|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main, master] |
| 8 | + # Allows you to run this workflow manually from the Actions tab |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v4 |
| 18 | + with: |
| 19 | + python-version: '3.12.2' |
| 20 | + - name: Install dependencies |
| 21 | + run: | |
| 22 | + python -m pip install --upgrade pip |
| 23 | + pip install -r scripts/requirements.txt |
| 24 | + - name: Run pytest |
| 25 | + run: pytest |
| 26 | + |
| 27 | + build: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + container: makeappdev/uselatex:latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Configure Git safe directory with GITHUB_WORKSPACE |
| 36 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 37 | + |
| 38 | + # Build documents via CMake |
| 39 | + - name: Build documents |
| 40 | + run: | |
| 41 | + cmake --version |
| 42 | + pdflatex --version |
| 43 | + mkdir -p build && cd build |
| 44 | + cmake .. |
| 45 | + make |
| 46 | +
|
| 47 | + # Fetch default branch |
| 48 | + - name: Fetch default branch |
| 49 | + run: | |
| 50 | + git fetch origin ${{ github.event.repository.default_branch }} |
| 51 | +
|
| 52 | + # Run latexdiff on each document by retrieving the original .tex file from the default branch. |
| 53 | + - name: Run latexdiff on documents |
| 54 | + run: | |
| 55 | + # Install latexdiff if not present |
| 56 | + apt-get install -y latexdiff |
| 57 | + |
| 58 | + # Create a directory to hold diff outputs. |
| 59 | + mkdir -p diff |
| 60 | + mkdir -p temp |
| 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" ]; then |
| 68 | + # Check if the file exists in the default branch using git cat-file. |
| 69 | + if git cat-file -e origin/${{ github.event.repository.default_branch }}:"$filename.tex" 2>/dev/null; then |
| 70 | + echo "Running latexdiff on $filename.tex" |
| 71 | + # Retrieve the file from the default branch directly into a temporary file. |
| 72 | + git show origin/${{ github.event.repository.default_branch }}:"$filename.tex" > temp/"$filename"_old.tex |
| 73 | + # Generate a diff TeX file using the original (default branch) and current file. |
| 74 | + latexdiff temp/"$filename"_old.tex "$filename.tex" > diff/"${filename}_diff.tex" |
| 75 | + # Compile the diff file to produce a diff PDF. |
| 76 | + pdflatex -output-directory=diff diff/"${filename}_diff.tex" |
| 77 | + else |
| 78 | + echo "Skipping $filename: $filename.tex not found in the default branch." |
| 79 | + fi |
| 80 | + else |
| 81 | + echo "Skipping $filename: $filename.tex not found in the current branch." |
| 82 | + fi |
| 83 | + done |
| 84 | +
|
| 85 | + # Upload the PDFs produced by build. |
| 86 | + - name: Upload build artifact |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: build |
| 90 | + path: build/*.pdf |
| 91 | + |
| 92 | + # Upload the diff PDFs produced by latexdiff. |
| 93 | + - name: Upload latexdiff artifact |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: latexdiff |
| 97 | + path: diff/*.pdf |
| 98 | + |
| 99 | + - name: Prepare Deployment |
| 100 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' |
| 101 | + run: | |
| 102 | + mkdir -p export |
| 103 | + echo "# This branch is for deployment only" >> export/README.md |
| 104 | + cp build/*.pdf export |
| 105 | + cp build/git.id export |
| 106 | + |
| 107 | + - name: Deploy |
| 108 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' |
| 109 | + |
| 110 | + with: |
| 111 | + branch: gh-pages |
| 112 | + folder: export |
| 113 | + single-commit: true |
| 114 | + silent: true |
0 commit comments