Skip to content

Commit 3959971

Browse files
committed
remove comment step and second checkout
1 parent 6a92f23 commit 3959971

File tree

1 file changed

+34
-44
lines changed

1 file changed

+34
-44
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
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
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
2424

2525
build:
2626
runs-on: ubuntu-latest
@@ -29,7 +29,7 @@ jobs:
2929
- uses: actions/checkout@v4
3030
with:
3131
fetch-depth: 0
32-
32+
3333
- name: Configure Git safe directory with GITHUB_WORKSPACE
3434
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
3535

@@ -38,80 +38,70 @@ jobs:
3838
run: |
3939
cmake --version
4040
pdflatex --version
41-
42-
# Create and enter the build directory.
4341
mkdir -p build && cd build
4442
cmake ..
4543
make
4644
47-
# Prepare the "original" version from the default branch.
48-
- name: Checkout default branch for diff
45+
# Fetch default branch
46+
- name: Fetch default branch
4947
run: |
5048
git fetch origin ${{ github.event.repository.default_branch }}
51-
git worktree add original origin/${{ github.event.repository.default_branch }}
5249
53-
# Run latexdiff on each document.
50+
# Run latexdiff on each document by retrieving the original .tex file from the default branch.
5451
- name: Run latexdiff on documents
5552
run: |
5653
# Install latexdiff if not present
5754
apt-get install -y latexdiff
5855
5956
# Create a directory to hold diff outputs.
6057
mkdir -p diff
61-
58+
mkdir -p temp
59+
6260
# Loop over each PDF in the build folder.
6361
for pdf in build/*.pdf; do
6462
# Extract the basename (e.g. "document" from "document.pdf")
6563
filename=$(basename "$pdf" .pdf)
6664
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"
65+
if [ -f "$filename.tex" ]; then
66+
# Check if the file exists in the default branch using git cat-file.
67+
if git cat-file -e origin/${{ github.event.repository.default_branch }}:"$filename.tex" 2>/dev/null; then
68+
echo "Running latexdiff on $filename.tex"
69+
# Retrieve the file from the default branch directly into a temporary file.
70+
git show origin/${{ github.event.repository.default_branch }}:"$filename.tex" > temp/"$filename"_old.tex
71+
# Generate a diff TeX file using the original (default branch) and current file.
72+
latexdiff temp/"$filename"_old.tex "$filename.tex" > diff/"${filename}_diff.tex"
73+
# Compile the diff file to produce a diff PDF.
74+
pdflatex -output-directory=diff diff/"${filename}_diff.tex"
75+
else
76+
echo "Skipping $filename: $filename.tex not found in the default branch."
77+
fi
7378
else
74-
echo "Skipping $filename: Corresponding .tex file not found in one of the branches."
79+
echo "Skipping $filename: $filename.tex not found in the current branch."
7580
fi
7681
done
7782
7883
# Upload the PDFs produced by build.
7984
- name: Upload build artifact
8085
uses: actions/upload-artifact@v4
8186
with:
82-
name: build-artifact
87+
name: build
8388
path: build/*.pdf
8489

8590
# Upload the diff PDFs produced by latexdiff.
8691
- name: Upload latexdiff artifact
8792
uses: actions/upload-artifact@v4
8893
with:
89-
name: latexdiff-artifact
94+
name: latexdiff
9095
path: diff/*.pdf
9196

92-
- name: Comment on PR with artifact link
93-
if: ${{ github.event_name == 'pull_request' }}
94-
continue-on-error: true
95-
uses: actions/github-script@v6
96-
with:
97-
github-token: ${{ secrets.GITHUB_TOKEN }}
98-
script: |
99-
const pr_number = context.payload.pull_request.number
100-
const run_id = process.env.GITHUB_RUN_ID
101-
const run_url = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${run_id}`
102-
await github.rest.issues.createComment({
103-
owner: context.repo.owner,
104-
repo: context.repo.repo,
105-
issue_number: pr_number,
106-
body: `:robot: The artifacts from this build are available [here](${run_url}).`
107-
})
10897
- name: Prepare Deployment
10998
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
11099
run: |
111100
mkdir -p export
112101
echo "# This branch is for deployment only" >> export/README.md
113102
cp build/*.pdf export
114103
cp build/git.id export
104+
115105
- name: Deploy
116106
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
117107
uses: JamesIves/[email protected]

0 commit comments

Comments
 (0)