From 1da5da4125735945ab39669afc6998813963bda6 Mon Sep 17 00:00:00 2001 From: Darius Peters <38152878+dariusptrs@users.noreply.github.com> Date: Sat, 1 Feb 2025 14:13:00 +0100 Subject: [PATCH 1/4] add latexdiff and test workflow --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++------ CheatsheetTemplate.tex | 2 +- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e765e64..f561da3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,7 @@ name: CI on: push: - branches: [ master, main ] pull_request: - branches: [ master, main ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -33,20 +31,63 @@ jobs: fetch-depth: 0 - name: Configure Git safe directory with GITHUB_WORKSPACE - run: git config --global --add safe.directory $GITHUB_WORKSPACE - - - name: Build + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + + # Build documents via CMake + - name: Build documents run: | - cmake --version; pdflatex --version + cmake --version + pdflatex --version + + # Create and enter the build directory. mkdir -p build && cd build cmake .. make + + # Prepare the "original" version from the default branch. + - name: Checkout default branch for diff + run: | + git fetch origin ${{ github.event.repository.default_branch }} + git worktree add original origin/${{ github.event.repository.default_branch }} + + # Run latexdiff on each document. + - name: Run latexdiff on documents + run: | + # Install latexdiff if not present + apt-get install -y latexdiff - - name: Upload artifact + # Create a directory to hold diff outputs. + mkdir -p diff + + # Loop over each PDF in the build folder. + for pdf in build/*.pdf; do + # Extract the basename (e.g. "document" from "document.pdf") + filename=$(basename "$pdf" .pdf) + + if [ -f "$filename.tex" ] && [ -f original/"$filename.tex" ]; then + echo "Running latexdiff on $filename.tex" + # Generate a diff TeX file. + latexdiff original/"$filename.tex" "$filename.tex" > diff/"${filename}_diff.tex" + # Compile the diff file to produce a diff PDF. + pdflatex -output-directory=diff diff/"${filename}_diff.tex" + else + echo "Skipping $filename: Corresponding .tex file not found in one of the branches." + fi + done + + # Upload the PDFs produced by build. + - name: Upload build artifact uses: actions/upload-artifact@v4 with: name: build-artifact - path: ./build/*.pdf + path: build/*.pdf + + # Upload the diff PDFs produced by latexdiff. + - name: Upload latexdiff artifact + uses: actions/upload-artifact@v4 + with: + name: latexdiff-artifact + path: diff/*.pdf - name: Comment on PR with artifact link if: ${{ github.event_name == 'pull_request' }} uses: actions/github-script@v6 diff --git a/CheatsheetTemplate.tex b/CheatsheetTemplate.tex index 4c1b337..52d4efc 100644 --- a/CheatsheetTemplate.tex +++ b/CheatsheetTemplate.tex @@ -49,7 +49,7 @@ \section{Math} \begin{sectionbox} \subsection{Cosinus} - Text goes here ... + More text goes here ... \end{sectionbox} From 6a92f237e43faaf92d7d2c7600ff2e17a2f9e592 Mon Sep 17 00:00:00 2001 From: Darius Peters <38152878+dariusptrs@users.noreply.github.com> Date: Wed, 5 Feb 2025 20:46:49 +0100 Subject: [PATCH 2/4] add continue-on-error to handle workflow runs from forks --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f561da3..2479cee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,8 +88,10 @@ jobs: with: name: latexdiff-artifact path: diff/*.pdf + - name: Comment on PR with artifact link if: ${{ github.event_name == 'pull_request' }} + continue-on-error: true uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 39599716b7582b245fb4b2aa4e37c3db3d31b1d0 Mon Sep 17 00:00:00 2001 From: Darius Peters <38152878+dariusptrs@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:47:29 +0100 Subject: [PATCH 3/4] remove comment step and second checkout --- .github/workflows/ci.yml | 78 ++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2479cee..d2ce6b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,17 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.12.2' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r scripts/requirements.txt - - name: Run pytest - run: pytest + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12.2' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r scripts/requirements.txt + - name: Run pytest + run: pytest build: runs-on: ubuntu-latest @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - + - name: Configure Git safe directory with GITHUB_WORKSPACE run: git config --global --add safe.directory "$GITHUB_WORKSPACE" @@ -38,19 +38,16 @@ jobs: run: | cmake --version pdflatex --version - - # Create and enter the build directory. mkdir -p build && cd build cmake .. make - # Prepare the "original" version from the default branch. - - name: Checkout default branch for diff + # Fetch default branch + - name: Fetch default branch run: | git fetch origin ${{ github.event.repository.default_branch }} - git worktree add original origin/${{ github.event.repository.default_branch }} - # Run latexdiff on each document. + # Run latexdiff on each document by retrieving the original .tex file from the default branch. - name: Run latexdiff on documents run: | # Install latexdiff if not present @@ -58,20 +55,28 @@ jobs: # Create a directory to hold diff outputs. mkdir -p diff - + mkdir -p temp + # Loop over each PDF in the build folder. for pdf in build/*.pdf; do # Extract the basename (e.g. "document" from "document.pdf") filename=$(basename "$pdf" .pdf) - if [ -f "$filename.tex" ] && [ -f original/"$filename.tex" ]; then - echo "Running latexdiff on $filename.tex" - # Generate a diff TeX file. - latexdiff original/"$filename.tex" "$filename.tex" > diff/"${filename}_diff.tex" - # Compile the diff file to produce a diff PDF. - pdflatex -output-directory=diff diff/"${filename}_diff.tex" + if [ -f "$filename.tex" ]; then + # Check if the file exists in the default branch using git cat-file. + if git cat-file -e origin/${{ github.event.repository.default_branch }}:"$filename.tex" 2>/dev/null; then + echo "Running latexdiff on $filename.tex" + # Retrieve the file from the default branch directly into a temporary file. + git show origin/${{ github.event.repository.default_branch }}:"$filename.tex" > temp/"$filename"_old.tex + # Generate a diff TeX file using the original (default branch) and current file. + latexdiff temp/"$filename"_old.tex "$filename.tex" > diff/"${filename}_diff.tex" + # Compile the diff file to produce a diff PDF. + pdflatex -output-directory=diff diff/"${filename}_diff.tex" + else + echo "Skipping $filename: $filename.tex not found in the default branch." + fi else - echo "Skipping $filename: Corresponding .tex file not found in one of the branches." + echo "Skipping $filename: $filename.tex not found in the current branch." fi done @@ -79,32 +84,16 @@ jobs: - name: Upload build artifact uses: actions/upload-artifact@v4 with: - name: build-artifact + name: build path: build/*.pdf # Upload the diff PDFs produced by latexdiff. - name: Upload latexdiff artifact uses: actions/upload-artifact@v4 with: - name: latexdiff-artifact + name: latexdiff path: diff/*.pdf - - name: Comment on PR with artifact link - if: ${{ github.event_name == 'pull_request' }} - continue-on-error: true - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const pr_number = context.payload.pull_request.number - const run_id = process.env.GITHUB_RUN_ID - const run_url = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${run_id}` - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr_number, - body: `:robot: The artifacts from this build are available [here](${run_url}).` - }) - name: Prepare Deployment if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' run: | @@ -112,6 +101,7 @@ jobs: echo "# This branch is for deployment only" >> export/README.md cp build/*.pdf export cp build/git.id export + - name: Deploy if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' uses: JamesIves/github-pages-deploy-action@v4.5.0 From 9ed12273b3f57b239aac317939dbf6095582445c Mon Sep 17 00:00:00 2001 From: Darius Peters <38152878+dariusptrs@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:26:45 +0100 Subject: [PATCH 4/4] re-add branch checks --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2ce6b6..d3ac834 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,9 @@ name: CI on: push: + branches: [main, master] pull_request: + branches: [main, master] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: