11name : Convert FODT to PDF
22
3- # Convert added/changed .fodt tutorials to PDF with LibreOffice and place each
4- # PDF beside its source (same directory / basename).
5- #
6- # - push: convert, commit PDF next to each .fodt, upload artifacts
7- # - pull_request: convert + upload artifacts (CI check for reviewers)
8- # - workflow_dispatch: manual rebuild + commit
3+ # Convert changed .fodt tutorials to PDF beside the source, then commit them
4+ # back to the branch on push / workflow_dispatch.
95on :
106 pull_request :
117 paths :
2218 type : boolean
2319 default : true
2420
21+ # Keep PR and push runs independent so a PR check cannot cancel the push
22+ # job that commits PDFs into the branch.
2523concurrency :
26- # One in-flight run per branch (covers same-repo PR + push races).
27- group : fodt-to-pdf-${{ github.head_ref || github.ref_name }}
24+ group : fodt-to-pdf-${{ github.event_name }}-${{ github.head_ref || github.ref_name }}
2825 cancel-in-progress : true
2926
3027permissions :
@@ -35,41 +32,15 @@ jobs:
3532 runs-on : ubuntu-latest
3633 timeout-minutes : 60
3734 steps :
38- - name : Decide target branch
39- id : meta
40- shell : bash
41- run : |
42- set -euo pipefail
43- EVENT="${{ github.event_name }}"
44- # Commit PDFs into the repo on push/manual runs.
45- # Same-repo PRs still get PDFs via the accompanying push event.
46- # Fork PRs only receive artifacts (no write access to the fork).
47- CAN_PUSH=false
48- BRANCH="${{ github.ref_name }}"
49-
50- if [[ "$EVENT" == "push" && "${{ github.ref_type }}" == "branch" ]]; then
51- CAN_PUSH=true
52- BRANCH="${{ github.ref_name }}"
53- elif [[ "$EVENT" == "workflow_dispatch" ]]; then
54- CAN_PUSH=true
55- BRANCH="${{ github.ref_name }}"
56- elif [[ "$EVENT" == "pull_request" ]]; then
57- BRANCH="${{ github.head_ref }}"
58- fi
59-
60- echo "event=$EVENT"
61- echo "branch=$BRANCH"
62- echo "can_push=$CAN_PUSH"
63- echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
64- echo "can_push=$CAN_PUSH" >> "$GITHUB_OUTPUT"
65-
6635 - name : Checkout
6736 uses : actions/checkout@v4
6837 with :
6938 fetch-depth : 0
70- # Check out the branch that should receive the PDFs whenever we can push.
71- ref : ${{ steps.meta.outputs.can_push == 'true' && steps.meta.outputs.branch || github.sha }}
39+ # Always check out a named branch for push/dispatch so git push works.
40+ # For pull_request, check out the PR head commit.
41+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref_name }}
7242 token : ${{ secrets.GITHUB_TOKEN }}
43+ persist-credentials : true
7344
7445 - name : Install LibreOffice
7546 run : |
@@ -112,19 +83,12 @@ jobs:
11283 done
11384
11485 echo "count=$COUNT" >> "$GITHUB_OUTPUT"
115- {
116- echo "files<<EOF"
117- cat /tmp/fodt_list.txt
118- echo "EOF"
119- } >> "$GITHUB_OUTPUT"
120-
12186 echo "FODT files to convert ($COUNT):"
12287 cat /tmp/fodt_list.txt || true
12388
12489 - name : Skip notice
12590 if : steps.fodt.outputs.count == '0'
126- run : |
127- echo "No matching .fodt files to convert for this event."
91+ run : echo "No matching .fodt files to convert for this event."
12892
12993 - name : Convert FODT to PDF beside sources
13094 if : steps.fodt.outputs.count != '0'
13397 set -euo pipefail
13498 chmod +x build_tools/convert_fodt_to_pdf.sh build_tools/build_pdfs.sh
13599 mapfile -t FILES < /tmp/fodt_list.txt
136- # Writes each PDF next to its .fodt (same directory, same basename).
137100 ./build_tools/build_pdfs.sh "${FILES[@]}"
138101
139102 echo "Generated PDFs (alongside sources):"
@@ -157,7 +120,6 @@ jobs:
157120 mkdir -p "/tmp/pdf-artifacts/$(dirname "$pdf")"
158121 cp "$pdf" "/tmp/pdf-artifacts/$pdf"
159122 done < /tmp/fodt_list.txt
160- find /tmp/pdf-artifacts -type f -name '*.pdf' -ls
161123
162124 - name : Upload PDF artifacts
163125 if : steps.fodt.outputs.count != '0'
@@ -169,36 +131,39 @@ jobs:
169131 retention-days : 14
170132
171133 - name : Commit PDFs into the repository
172- if : steps.fodt.outputs.count != '0' && steps.meta.outputs.can_push == 'true'
134+ # Only push/dispatch write back to the branch. PR jobs upload artifacts only
135+ # (same-repo PR branches still get commits from the parallel push event).
136+ if : >-
137+ steps.fodt.outputs.count != '0' &&
138+ (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
173139 shell : bash
174140 run : |
175141 set -euo pipefail
176142
177- BRANCH="${{ steps.meta.outputs.branch }}"
178-
179- # Avoid a convert↔push loop if this commit was created by the bot.
180- if git log -1 --pretty=%an | grep -qx 'github-actions\[bot\]'; then
181- if git log -1 --pretty=%s | grep -qx 'Auto-convert tutorial FODT to PDF'; then
182- echo "HEAD is already an auto-PDF commit; skipping another commit"
183- exit 0
184- fi
185- fi
143+ BRANCH="${{ github.ref_name }}"
144+ echo "Committing PDFs onto branch: ${BRANCH}"
145+ echo "git status before add:"
146+ git status --short
186147
187148 while IFS= read -r fodt; do
188149 pdf="${fodt%.fodt}.pdf"
189150 git add -- "$pdf"
190- echo "staged $pdf (same directory as $fodt)"
151+ echo "staged $pdf (beside $fodt)"
191152 done < /tmp/fodt_list.txt
192153
154+ echo "git status after add:"
155+ git status --short
156+
193157 if git diff --cached --quiet; then
194- echo "No PDF content changes to commit"
158+ echo "No PDF content changes to commit (already up to date). "
195159 exit 0
196160 fi
197161
198162 git config user.name "github-actions[bot]"
199163 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
200164 git commit -m "Auto-convert tutorial FODT to PDF"
201165
202- # Push to the branch that owns the .fodt sources.
166+ # Rebase onto remote tip in case another job pushed meanwhile, then push.
167+ git pull --rebase --autostash origin "${BRANCH}"
203168 git push origin "HEAD:${BRANCH}"
204- echo "Committed PDFs next to their .fodt sources on branch ${BRANCH}"
169+ echo "Pushed PDFs next to their .fodt sources on ${BRANCH}"
0 commit comments