| .github/workflows | ||
| assets/img | ||
| .gitignore | ||
| bibliography.yml | ||
| layout.typ | ||
| LICENSE | ||
| main.typ | ||
| README.md | ||
| requirements.typ | ||
Typst Project Template with Automated Releases
This repository serves as a template for creating documents with Typst, a modern, markup-based typesetting system. It includes a pre-configured GitHub Actions workflow that automatically compiles your document and creates a GitHub Release whenever you push a new version tag.
Features
- Automated PDF Compilation: Automatically compiles
main.typintomain.pdfon every run. - Dependency Caching: Uses
typst-community/setup-typstto cache dependencies listed inrequirements.typ, speeding up subsequent builds. - Automatic Releases: Creates a new GitHub Release with the compiled PDF attached whenever a tag matching the
v*.*.*pattern is pushed. - Manual Workflow Trigger: Allows for manual builds directly from the GitHub Actions tab, perfect for testing changes without creating a release.
File Structure
.
├── .github/
│ └── workflows/
│ └── release.yml # The GitHub Actions workflow definition.
├── main.typ # Your main Typst document entry point.
├── requirements.typ # List your Typst package dependencies here.
├── bibliography.yml # A sample bibliography file (if needed).
└── README.md # This file.
main.typ: This is the heart of your document. All your content should start here.requirements.typ: If your project uses external Typst packages, you should specify them here. The workflow will automatically fetch and cache them. For example:
#import "@preview/fletcher:0.5.8"
#import "@preview/physica:0.9.5"
.github/workflows/release.yml: This file defines the Continuous Integration/Continuous Deployment (CI/CD) pipeline. See the "Workflow Breakdown" section below for a detailed explanation.
How to Use This Template
There are two primary ways to use the automation provided in this template.
Method 1: Creating a Release/Tag (Recommended)
This is the standard way to publish a new version of your document. The workflow will automatically create a GitHub Release and attach your compiled PDF.
- Commit Your Changes: Make sure all your latest changes to the
.typfiles are committed to your main branch.
git add .
git commit -m "Finalize version 1.0.0"
- Tag the Version: Create a new Git tag that follows the semantic versioning format (e.g.,
v1.0.0,v1.2.3).
git tag v1.0.0
- Push the Tag: Push your commits and the new tag to GitHub.
git push origin v1.0.0
Once the tag is pushed, the "Release" workflow will automatically start. It will compile main.typ and create a new release on your repository's "Releases" page, named v1.0.0 — <current_date>, with main.pdf attached as an asset.
Method 2: Manual Build for Testing
If you want to compile the PDF to see the result without creating a public release, you can trigger the workflow manually.
- Navigate to the Actions tab in your GitHub repository.
- In the left sidebar, click on the Release workflow.
- You will see a message: "This workflow has a
workflow_dispatchevent trigger." Click the Run workflow dropdown button. - You will be prompted to enter a
versionstring. This is for informational purposes in the run log; you can enter any value (e.g.,test-build). - Click the green Run workflow button.
The workflow will run, but the final "Release" step will be skipped. You can download the compiled main.pdf from the "Artifacts" section on the summary page for that workflow run.
Workflow Breakdown (release.yml)
The automation is powered by the .github/workflows/release.yml file. Here is a step-by-step explanation of what it does.
Triggers
The workflow is triggered by two events:
push: tags:: Runs automatically when a tag matching the patternv[0-9]+.[0-9]+.[0-9]+*is pushed.workflow_dispatch:: Allows the manual execution described above.
Permissions
contents: write: This is essential. It grants the workflow permission to create GitHub Releases and upload files (artifacts) to them.
Job: build
The workflow consists of a single job named build that runs on an ubuntu-latest virtual machine.
-
actions/checkout@v4: This step checks out your repository's code so the workflow can access your.typfiles. -
typst-community/setup-typst@v4: This community action installs the specified version of Typst (0.13). Thecache-dependency-pathkey is configured to look atrequirements.typ, enabling caching of Typst packages to make future runs faster. -
Compile Typst files: A simple shell command that runs the Typst compiler, takingmain.typas input and producingmain.pdf.
typst compile main.typ main.pdf
-
Upload PDF file: This step usesactions/upload-artifact@v4to save the generatedmain.pdfas a workflow artifact. This is useful for every run, as it allows you to download the PDF even if a release isn't created. -
Get current date: Creates a timestamp that is used in the release name for uniqueness. -
softprops/action-gh-release@v1: This is the final step that creates the release.if: github.ref_type == 'tag': This crucial condition ensures this step only runs if the workflow was triggered by a tag. It is skipped during manualworkflow_dispatchruns.name: "${{ github.ref_name }} — ${{ env.DATE }}": Sets the release title to the tag name (e.g.,v1.0.0) plus the date.files: main.pdf: Attaches the compiledmain.pdfto the release.
Customization
- Typst Version: To use a different version of Typst, simply change the
typst-versionin therelease.ymlfile. - Main File: If your main Typst file is not named
main.typ, you will need to update theCompile Typst filesandReleasesteps inrelease.yml. - Release Assets: You can add more files to the release (e.g., a ZIP of the source code) by modifying the
files:list in theReleasestep.