|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + # Allows you to run this workflow manually from the Actions tab |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + - name: Set up Python |
| 15 | + uses: actions/setup-python@v4 |
| 16 | + with: |
| 17 | + python-version: '3.12.2' |
| 18 | + - name: Install dependencies |
| 19 | + run: | |
| 20 | + python -m pip install --upgrade pip |
| 21 | + pip install -r scripts/requirements.txt |
| 22 | + - name: Run pytest |
| 23 | + run: pytest |
| 24 | + |
| 25 | + build: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + container: makeappdev/uselatex:latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Configure Git safe directory with GITHUB_WORKSPACE |
| 34 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 35 | + |
| 36 | + # Build documents via CMake |
| 37 | + - name: Build documents |
| 38 | + run: | |
| 39 | + cmake --version |
| 40 | + pdflatex --version |
| 41 | + |
| 42 | + # Create and enter the build directory. |
| 43 | + mkdir -p build && cd build |
| 44 | + cmake .. |
| 45 | + make |
| 46 | +
|
| 47 | + # Prepare the "original" version from the default branch. |
| 48 | + - name: Checkout default branch for diff |
| 49 | + run: | |
| 50 | + git fetch origin ${{ github.event.repository.default_branch }} |
| 51 | + git worktree add original origin/${{ github.event.repository.default_branch }} |
| 52 | +
|
| 53 | + # Run latexdiff on each document. |
| 54 | + - name: Run latexdiff on documents |
| 55 | + run: | |
| 56 | + # Install latexdiff if not present |
| 57 | + apt-get install -y latexdiff |
| 58 | + |
| 59 | + # Create a directory to hold diff outputs. |
| 60 | + mkdir -p diff |
| 61 | + |
| 62 | + # Loop over each PDF in the build folder. |
| 63 | + for pdf in build/*.pdf; do |
| 64 | + # Extract the basename (e.g. "document" from "document.pdf") |
| 65 | + filename=$(basename "$pdf" .pdf) |
| 66 | + |
| 67 | + if [ -f "$filename.tex" ] && [ -f original/"$filename.tex" ]; then |
| 68 | + echo "Running latexdiff on $filename.tex" |
| 69 | + # Generate a diff TeX file. |
| 70 | + latexdiff original/"$filename.tex" "$filename.tex" > diff/"${filename}_diff.tex" |
| 71 | + # Compile the diff file to produce a diff PDF. |
| 72 | + pdflatex -output-directory=diff diff/"${filename}_diff.tex" |
| 73 | + else |
| 74 | + echo "Skipping $filename: Corresponding .tex file not found in one of the branches." |
| 75 | + fi |
| 76 | + done |
| 77 | +
|
| 78 | + # Upload the PDFs produced by build. |
| 79 | + - name: Upload build artifact |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: build-artifact |
| 83 | + path: build/*.pdf |
| 84 | + |
| 85 | + # Upload the diff PDFs produced by latexdiff. |
| 86 | + - name: Upload latexdiff artifact |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: latexdiff-artifact |
| 90 | + path: diff/*.pdf |
| 91 | + - name: Comment on PR with artifact link |
| 92 | + if: ${{ github.event_name == 'pull_request' }} |
| 93 | + uses: actions/github-script@v6 |
| 94 | + with: |
| 95 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + script: | |
| 97 | + const pr_number = context.payload.pull_request.number |
| 98 | + const run_id = process.env.GITHUB_RUN_ID |
| 99 | + const run_url = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${run_id}` |
| 100 | + await github.rest.issues.createComment({ |
| 101 | + owner: context.repo.owner, |
| 102 | + repo: context.repo.repo, |
| 103 | + issue_number: pr_number, |
| 104 | + body: `:robot: The artifacts from this build are available [here](${run_url}).` |
| 105 | + }) |
| 106 | + - name: Prepare Deployment |
| 107 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' |
| 108 | + run: | |
| 109 | + mkdir -p export |
| 110 | + echo "# This branch is for deployment only" >> export/README.md |
| 111 | + cp build/*.pdf export |
| 112 | + cp build/git.id export |
| 113 | + - name: Deploy |
| 114 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' |
| 115 | + |
| 116 | + with: |
| 117 | + branch: gh-pages |
| 118 | + folder: export |
| 119 | + single-commit: true |
| 120 | + silent: true |
0 commit comments