@@ -2,59 +2,113 @@ 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
2929 container : makeappdev/uselatex:latest
3030 steps :
3131 - uses : actions/checkout@v4
32- with :
32+ 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+ 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+
4599 - name : Prepare Deployment
46100 if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
47101 run : |
48102 mkdir -p export
49103 echo "# This branch is for deployment only" >> export/README.md
50104 cp build/*.pdf export
51105 cp build/git.id export
52-
106+
53107 - name : Deploy
54108 if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
5510956110 with :
57111 branch : gh-pages
58112 folder : export
59113 single-commit : true
60- silent : true
114+ silent : true
0 commit comments