Skip to content

Make the PDF commit step survive a push race - #14

Merged
egonw merged 1 commit into
mainfrom
fix-pdf-commit-push-race
Sep 18, 2026
Merged

egonw merged 1 commit into
mainfrom
fix-pdf-commit-push-race

Conversation

@inutano

@inutano inutano commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Commit PDF to repository pushes without rebasing, so two commits landing close together make one build fail after it has already generated the PDF.

This is not a rare race. Creating a repository from this template triggers it immediately: the template's initial commit starts a build, and the author's first real commit starts another. One of the two loses the push and goes red on a brand-new repo, which is an alarming first impression. It also fires whenever an author pushes twice in quick succession.

Observed on a fresh repo created from this template:

[main 6b75d80] Update paper.pdf [skip ci]
 1 file changed, 0 insertions(+), 0 deletions(-)
To https://github.com/biohackathon-japan/BH26-logica
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/biohackathon-japan/BH26-logica'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally.
##[error]Process completed with exit code 1.

Changes

Rebase and retry rather than pushing once and failing.

A concurrency group with cancel-in-progress, so a newer push supersedes an in-flight build. Without it, retrying alone would fix the red X but leave a worse problem: two builds racing to commit means whichever finishes last wins, which can leave paper.pdf built from an older paper.md.

Do not push when there was nothing to commit. The previous line was:

git diff --cached --quiet && echo "No changes to PDF" || git commit -m "..." && git push

Since A && B || C && D groups as ((A && B) || C) && D, a successful git diff --cached --quiet short-circuits past the commit but still reaches git push. Harmless in practice, but it meant the step pushed after reporting "No changes to PDF".

Verification

Tested on a repo using this workflow by pushing two commits 11 seconds apart, which is the exact scenario that used to fail:

  • before: the earlier run failed at the push, as above
  • after: the earlier run was cancelled by the concurrency group and the later run pushed cleanly on its first attempt (4d687c7..774d478 main -> main)

Also confirmed the no-op path still reports "No changes to PDF" and exits 0 when the PDF is unchanged.

🤖 Generated with Claude Code

The step pushes without rebasing, so when two commits land close together
one run builds the PDF and then loses the push, failing the whole build.
Creating a repo from this template hits it immediately: the initial commit
and the author's first real commit both trigger a build, and one of them
goes red on a brand new repo.

Rebase and retry, and add a concurrency group so a newer push supersedes
an in-flight build, which keeps the committed PDF in step with the newest
paper.md rather than letting whichever build finishes last win.

Also stop running `git push` when there was nothing to commit: in
`A && B || C && D`, a successful A short-circuits past C but still runs D,
so the previous chain pushed even after reporting "No changes to PDF".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

PDF Preview Ready

The PDF has been generated successfully. Download it from the Actions artifacts.

@egonw

egonw commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@egonw
egonw merged commit 2d917d9 into main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants