@@ -2,27 +2,27 @@ name: CI
22
33on :
44 push :
5- branches : [ master, main ]
5+ branches : [main, master ]
66 pull_request :
7- branches : [ master, main ]
7+ branches : [main, master ]
88 # Allows you to run this workflow manually from the Actions tab
99 workflow_dispatch :
1010
1111jobs :
1212 test :
1313 runs-on : ubuntu-latest
1414 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
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
2626
2727 build :
2828 runs-on : ubuntu-latest
@@ -31,25 +31,80 @@ jobs:
3131 - uses : actions/checkout@v4
3232 with :
3333 fetch-depth : 0
34-
34+
3535 - name : Configure Git safe directory with GITHUB_WORKSPACE
36- run : git config --global --add safe.directory $GITHUB_WORKSPACE
37-
38- - name : Build
36+ run : git config --global --add safe.directory "$GITHUB_WORKSPACE"
37+
38+ # Build documents via CMake
39+ - name : Build documents
3940 run : |
40- cmake --version; pdflatex --version
41+ cmake --version
42+ pdflatex --version
4143 mkdir -p build && cd build
4244 cmake ..
4345 make
4446
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+ continue-on-error : true
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+ mkdir -p temp
62+
63+ # Loop over each PDF in the build folder.
64+ for pdf in build/*.pdf; do
65+ # Extract the basename (e.g. "document" from "document.pdf")
66+ filename=$(basename "$pdf" .pdf)
67+
68+ if [ -f "$filename.tex" ]; then
69+ # Check if the file exists in the default branch using git cat-file.
70+ if git cat-file -e origin/${{ github.event.repository.default_branch }}:"$filename.tex" 2>/dev/null; then
71+ echo "Running latexdiff on $filename.tex"
72+ # Retrieve the file from the default branch directly into a temporary file.
73+ git show origin/${{ github.event.repository.default_branch }}:"$filename.tex" > temp/"$filename"_old.tex
74+ # Generate a diff TeX file using the original (default branch) and current file.
75+ latexdiff temp/"$filename"_old.tex "$filename.tex" > diff/"${filename}_diff.tex"
76+ # Compile the diff file to produce a diff PDF.
77+ pdflatex -output-directory=diff diff/"${filename}_diff.tex"
78+ else
79+ echo "Skipping $filename: $filename.tex not found in the default branch."
80+ fi
81+ else
82+ echo "Skipping $filename: $filename.tex not found in the current branch."
83+ fi
84+ done
85+
86+ # Upload the PDFs produced by build.
87+ - name : Upload build artifact
88+ uses : actions/upload-artifact@v4
89+ with :
90+ name : build
91+ path : build/*.pdf
92+
93+ # Upload the diff PDFs produced by latexdiff.
94+ - name : Upload latexdiff artifact
95+ uses : actions/upload-artifact@v4
96+ with :
97+ name : latexdiff
98+ path : diff/*.pdf
99+
45100 - name : Prepare Deployment
46101 if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
47102 run : |
48103 mkdir -p export
49104 echo "# This branch is for deployment only" >> export/README.md
50105 cp build/*.pdf export
51106 cp build/git.id export
52-
107+
53108 - name : Deploy
54109 if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
55110
0 commit comments