|
| 1 | +name: Generate PDFs and Deploy Docs |
| 2 | + |
| 3 | +# Triggered by: |
| 4 | +# - push to master that changes lecture markdown files |
| 5 | +# - manual dispatch (regenerates PDFs for ALL lecture files) |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + paths: |
| 11 | + - '[0-9][0-9]_*.md' |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: pdf-generation |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + # ------------------------------------------------------------------------- |
| 23 | + # Job 1 – build PDFs and publish GitHub Releases |
| 24 | + # ------------------------------------------------------------------------- |
| 25 | + generate_pdfs: |
| 26 | + name: Generate PDFs and create releases |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 2 |
| 33 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + |
| 35 | + - name: Detect changed lecture files (push) or select all (dispatch) |
| 36 | + id: changes |
| 37 | + run: | |
| 38 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 39 | + # Regenerate PDFs for every numbered lecture file |
| 40 | + files=$(ls [0-9][0-9]_*.md 2>/dev/null | tr '\n' ' ') |
| 41 | + else |
| 42 | + files=$(git diff --name-only HEAD^ HEAD \ |
| 43 | + | grep -E '^[0-9]{2}_.*\.md$' || true) |
| 44 | + files="${files//$'\n'/ }" |
| 45 | + fi |
| 46 | + echo "changed_files=${files}" >> "$GITHUB_OUTPUT" |
| 47 | + echo "Files to process: ${files}" |
| 48 | +
|
| 49 | + - name: Set up Node.js |
| 50 | + if: steps.changes.outputs.changed_files != '' |
| 51 | + uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + node-version: '22' |
| 54 | + |
| 55 | + - name: Install LiaScript exporter |
| 56 | + if: steps.changes.outputs.changed_files != '' |
| 57 | + run: npm install -g @liascript/exporter |
| 58 | + |
| 59 | + - name: Generate PDFs and publish GitHub Releases |
| 60 | + if: steps.changes.outputs.changed_files != '' |
| 61 | + run: | |
| 62 | + set -euo pipefail |
| 63 | + mkdir -p /tmp/pdf_build |
| 64 | +
|
| 65 | + for file in ${{ steps.changes.outputs.changed_files }}; do |
| 66 | + [ -f "$file" ] || continue |
| 67 | +
|
| 68 | + filename=$(basename "$file" .md) |
| 69 | +
|
| 70 | + # Safe tag: lowercase, transliterate umlauts, remove non-ASCII |
| 71 | + safe_tag=$(echo "$filename" \ |
| 72 | + | tr '[:upper:]' '[:lower:]' \ |
| 73 | + | sed -e 's/ä/ae/g' -e 's/ö/oe/g' -e 's/ü/ue/g' -e 's/ß/ss/g' \ |
| 74 | + -e 's/Ä/ae/g' -e 's/Ö/oe/g' -e 's/Ü/ue/g' \ |
| 75 | + -e 's/[^a-z0-9_-]//g') |
| 76 | +
|
| 77 | + # Extract version from frontmatter (e.g. "version: 1.0.10") |
| 78 | + version=$(grep -oP 'version:\s*\K[\d.]+' "$file" | head -1 || echo "unknown") |
| 79 | +
|
| 80 | + asset_name="${filename}_v${version}_Documentation" |
| 81 | + release_tag="${safe_tag}_v${version}" |
| 82 | +
|
| 83 | + echo "==> $file (tag: $release_tag)" |
| 84 | +
|
| 85 | + # Generate PDF |
| 86 | + liaex \ |
| 87 | + --input "$file" \ |
| 88 | + --format pdf \ |
| 89 | + --output "/tmp/pdf_build/${asset_name}" \ |
| 90 | + --pdf-timeout 60000 |
| 91 | +
|
| 92 | + pdf_path="/tmp/pdf_build/${asset_name}.pdf" |
| 93 | +
|
| 94 | + if [ ! -f "$pdf_path" ]; then |
| 95 | + echo "WARNING: PDF not created for $file – skipping release." |
| 96 | + continue |
| 97 | + fi |
| 98 | +
|
| 99 | + # Create or update the GitHub Release |
| 100 | + if gh release view "$release_tag" > /dev/null 2>&1; then |
| 101 | + echo "Release $release_tag already exists – uploading updated asset." |
| 102 | + gh release upload "$release_tag" "$pdf_path" --clobber |
| 103 | + else |
| 104 | + gh release create "$release_tag" \ |
| 105 | + --title "PDF – ${filename} (v${version})" \ |
| 106 | + --notes "Automated PDF export for \`${file}\` – version ${version}" \ |
| 107 | + "$pdf_path" |
| 108 | + fi |
| 109 | + done |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + |
| 114 | + # ------------------------------------------------------------------------- |
| 115 | + # Job 2 – regenerate docs/index.html and inject PDF links |
| 116 | + # ------------------------------------------------------------------------- |
| 117 | + deploy_docs: |
| 118 | + name: Build and deploy docs |
| 119 | + runs-on: ubuntu-latest |
| 120 | + needs: generate_pdfs |
| 121 | + steps: |
| 122 | + - name: Checkout repository |
| 123 | + uses: actions/checkout@v4 |
| 124 | + with: |
| 125 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 126 | + |
| 127 | + - name: Set up Node.js |
| 128 | + uses: actions/setup-node@v4 |
| 129 | + with: |
| 130 | + node-version: '22' |
| 131 | + |
| 132 | + - name: Install LiaScript exporter |
| 133 | + run: npm install -g @liascript/exporter |
| 134 | + |
| 135 | + - name: Set up Python |
| 136 | + uses: actions/setup-python@v5 |
| 137 | + with: |
| 138 | + python-version: '3.x' |
| 139 | + |
| 140 | + - name: Install Python dependencies |
| 141 | + run: pip install beautifulsoup4 requests |
| 142 | + |
| 143 | + - name: Generate docs/index.html from course.yml |
| 144 | + run: | |
| 145 | + mkdir -p docs |
| 146 | + liaex \ |
| 147 | + --input course.yml \ |
| 148 | + --format project \ |
| 149 | + --output docs/index \ |
| 150 | + --project-category-blur |
| 151 | +
|
| 152 | + - name: Copy CSS into docs/ |
| 153 | + run: cp linklayout.css docs/linklayout.css |
| 154 | + |
| 155 | + - name: Inject PDF download links |
| 156 | + run: python inject_pdf_links.py docs/index.html docs/index.html |
| 157 | + |
| 158 | + - name: Commit docs/ to repository |
| 159 | + run: | |
| 160 | + git config user.name "github-actions[bot]" |
| 161 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 162 | + git add docs/ |
| 163 | + if git diff --staged --quiet; then |
| 164 | + echo "No changes in docs/ – nothing to commit." |
| 165 | + else |
| 166 | + if ! git pull --rebase origin master; then |
| 167 | + echo "WARNING: git pull --rebase failed; attempting to push without rebase." |
| 168 | + fi |
| 169 | + git commit -m "ci: update docs/index.html with PDF links [skip ci]" |
| 170 | + git push |
| 171 | + fi |
0 commit comments