|
| 1 | +name: Build Typst Projects |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup Typst |
| 19 | + uses: typst-community/setup-typst@v3 |
| 20 | + with: |
| 21 | + typst-version: latest |
| 22 | + |
| 23 | + - name: Install fonts |
| 24 | + run: | |
| 25 | + sudo apt-get update |
| 26 | + sudo apt-get install -y fonts-liberation fonts-jetbrains-mono fonts-noto |
| 27 | + |
| 28 | + - name: Find all Typst projects |
| 29 | + id: find_projects |
| 30 | + run: | |
| 31 | + echo "TYPST_FILES=$(find . -name "*.typ" | grep -v "_" | grep -v "/auxiliaries/" | tr '\n' ' ')" >> $GITHUB_ENV |
| 32 | + mkdir -p build |
| 33 | + |
| 34 | + - name: Build PDFs from Typst files |
| 35 | + run: | |
| 36 | + for file in $TYPST_FILES; do |
| 37 | + filename=$(basename "$file" .typ) |
| 38 | + dirname=$(dirname "$file") |
| 39 | + echo "Building $file to build/${dirname#./}/$filename.pdf" |
| 40 | + mkdir -p "build/${dirname#./}" |
| 41 | + |
| 42 | + # Try to compile, continue if there's an error |
| 43 | + typst compile "$file" "build/${dirname#./}/$filename.pdf" || echo "Failed to build $file, continuing..." |
| 44 | + done |
| 45 | + |
| 46 | + - name: Generate README with links |
| 47 | + run: | |
| 48 | + echo "# Typst Project PDFs" > build/README.md |
| 49 | + echo "" >> build/README.md |
| 50 | + echo "This branch contains automatically built PDFs from Typst source files." >> build/README.md |
| 51 | + echo "" >> build/README.md |
| 52 | + echo "## Available PDFs" >> build/README.md |
| 53 | + echo "" >> build/README.md |
| 54 | + |
| 55 | + find build -name "*.pdf" | sort | while read pdf; do |
| 56 | + relative_path="${pdf#build/}" |
| 57 | + echo "- [$relative_path]($relative_path)" >> build/README.md |
| 58 | + done |
| 59 | + |
| 60 | + # Add timestamp to show when the build was last run |
| 61 | + echo "" >> build/README.md |
| 62 | + echo "Last built: $(date)" >> build/README.md |
| 63 | + |
| 64 | + - name: Deploy to GitHub Pages |
| 65 | + uses: JamesIves/github-pages-deploy-action@v4 |
| 66 | + with: |
| 67 | + folder: build |
| 68 | + branch: gh-pages |
| 69 | + clean: true |
0 commit comments