Skip to content

Commit 97e8b74

Browse files
rdimitrovclaude
andauthored
Rebase local commits before pushing to handle PR-branch drift (#763)
The skill step takes 20-45 min. During that window, someone often pushes merges from main to the PR branch (refreshing against latest review feedback). When the workflow's final "Commit and push" step then tries to push its local state, git rejects with: ! [rejected] HEAD -> renovate/... (fetch first) error: failed to push some refs Seen on run 24745672604 (skill completed successfully in 14 min, push rejected at the finish). Fix: - After committing any skill content, fetch the PR branch's current tip. - If origin is at or ahead of local (no new local commits), skip the push entirely. This is the common case when the skill produces no content changes. - Otherwise rebase local commits onto origin/HEAD_REF so we integrate any drift (merges, manual edits) before pushing. - Conflicts during rebase fail the step loudly with an actionable message. Same protection applied to the earlier "Commit + push refreshed reference assets" step; the race window is smaller there but still non-zero. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fabfc95 commit 97e8b74

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

.github/workflows/upstream-release-docs.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ jobs:
367367
echo "No reference changes for $PROJECT_ID $NEW_TAG."
368368
else
369369
git commit -m "Refresh reference assets for $PROJECT_ID $NEW_TAG"
370+
# Someone may have pushed to HEAD_REF between our checkout
371+
# and now (merges from main, etc). Rebase onto the latest
372+
# tip before pushing so we don't fail with "fetch first".
373+
git fetch origin "$HEAD_REF" --quiet
374+
git rebase "origin/$HEAD_REF" || {
375+
echo "::error::Rebase of the refresh commit onto origin/$HEAD_REF hit conflicts. Resolve manually on the PR branch."
376+
exit 1
377+
}
370378
git push origin "HEAD:$HEAD_REF"
371379
fi
372380
@@ -588,16 +596,30 @@ jobs:
588596
HEAD_REF: ${{ steps.eff.outputs.head_ref }}
589597
run: |
590598
# Stage any skill content and add a content commit if non-empty.
591-
# A refresh commit from the earlier step may also be waiting.
592599
git add -A
593600
if ! git diff --cached --quiet; then
594601
git commit -m "Add upstream-release-docs content for $PROJECT_ID $NEW_TAG"
595602
else
596603
echo "No skill content changes to commit."
597604
fi
598-
# Push whatever local commits are ahead of the remote — refresh
599-
# only, content only, or both. Empty push is a no-op.
600-
git push origin "HEAD:$HEAD_REF"
605+
606+
# Skill can take 20-45 min; during that window someone may
607+
# push merges-from-main or other commits to the PR branch.
608+
# Handle that safely:
609+
# - If our local HEAD is already on origin (no new work
610+
# to push), exit cleanly.
611+
# - Otherwise rebase any local-only commits onto the
612+
# latest origin tip, then push. Conflicts fail loudly.
613+
git fetch origin "$HEAD_REF" --quiet
614+
if git merge-base --is-ancestor HEAD "origin/$HEAD_REF" 2>/dev/null; then
615+
echo "Origin is at or ahead of local; nothing to push."
616+
else
617+
git rebase "origin/$HEAD_REF" || {
618+
echo "::error::Rebase of local commits onto origin/$HEAD_REF hit conflicts. Resolve manually on the PR branch."
619+
exit 1
620+
}
621+
git push origin "HEAD:$HEAD_REF"
622+
fi
601623
602624
- name: Augment PR body (marker-delimited section)
603625
# Runs even if earlier steps soft-failed so the augmentation

0 commit comments

Comments
 (0)