Skip to content

Commit 1a8a524

Browse files
committed
fix(ci): handle new upstream workflow files; pre-create auto-sync label
Two real failures observed in production: 1. revert logic missed NEW workflow files. `git checkout BEFORE -- path` restores modifications but does not delete files added by the merge. Switch to `git rm -rf` then `git checkout BEFORE --`, which wipes the directory and restores only what existed pre-merge. Applied to both auto-sync.yml and update-fork.sh. 2. failure-report step could not open an issue because the auto-sync label did not exist. The original `gh label create … 2>/dev/null || true` swallowed an earlier permission failure. Replaced with an explicit existence check that surfaces real errors.
1 parent 30fd83d commit 1a8a524

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

.github/workflows/auto-sync.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,20 @@ jobs:
6666
else
6767
# GITHUB_TOKEN cannot push .github/workflows/** changes (GitHub
6868
# gates that behind the `workflow` OAuth scope, which only PATs
69-
# carry). Revert any workflow-file changes the merge introduced
70-
# so the push always succeeds; we accept slow drift on those
71-
# files (most upstream workflows are disabled in this fork anyway).
69+
# carry). Restore the entire workflows/ directory to its
70+
# pre-merge state so the push always succeeds. We must handle
71+
# both kinds of upstream change:
72+
# * modifications -> reset to pre-merge content
73+
# * NEW files -> `git checkout BEFORE -- path` does NOT
74+
# remove them; we have to delete them
75+
# `git rm -rf` then `git checkout BEFORE --` is the bulletproof
76+
# combination: it wipes the directory then restores only what
77+
# existed before the merge. Slow drift on workflow files is the
78+
# accepted trade-off (most are disabled in this fork anyway).
7279
if ! git diff --quiet "$BEFORE" HEAD -- .github/workflows/; then
73-
echo "Reverting upstream changes to .github/workflows/ (cannot push them)"
74-
git checkout "$BEFORE" -- .github/workflows/
80+
echo "Restoring .github/workflows/ to pre-merge state (cannot push workflow changes)"
81+
git rm -rf --quiet --ignore-unmatch .github/workflows/
82+
git checkout "$BEFORE" -- .github/workflows/ 2>/dev/null || true
7583
if ! git diff --quiet --cached; then
7684
git commit --amend --no-edit
7785
fi
@@ -143,11 +151,17 @@ jobs:
143151
then fast-forward \`$STABLE_BRANCH\` to it.
144152
EOF
145153
)
154+
# Ensure the label exists BEFORE any gh call that filters on it.
155+
# `gh label create` errors if the label already exists; swallow only
156+
# that specific case (don't blanket-suppress with 2>/dev/null, which
157+
# hid a permission failure on an earlier run).
158+
if ! gh label list --search auto-sync --json name --jq '.[].name' | grep -qx auto-sync; then
159+
gh label create auto-sync --color B60205 --description "Automated upstream sync"
160+
fi
146161
EXISTING=$(gh issue list --state open --label auto-sync --json number --jq '.[0].number')
147162
if [ -n "$EXISTING" ]; then
148163
gh issue comment "$EXISTING" --body "$BODY"
149164
else
150-
gh label create auto-sync --color B60205 --description "Automated upstream sync" 2>/dev/null || true
151165
gh issue create --title "$TITLE" --body "$BODY" --label auto-sync
152166
fi
153167
exit 1

scripts/update-fork.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ git checkout "${INTEGRATION_BRANCH}"
2525
BEFORE=$(git rev-parse HEAD)
2626
git merge --no-edit upstream/main # stops here if there are conflicts
2727

28-
# Revert any upstream changes to .github/workflows/** so disabled workflows
28+
# Restore .github/workflows/ to its pre-merge state so disabled workflows
2929
# stay disabled and the fork's CI surface stays stable. (The auto-sync
30-
# GitHub workflow does the same — for the same reason GITHUB_TOKEN cannot
31-
# push these files, mirroring its behaviour here keeps local and automated
32-
# syncs equivalent.) Skip when nothing was merged.
30+
# GitHub workflow does the same; mirroring it here keeps local and
31+
# automated syncs equivalent.) Must handle both kinds of upstream change:
32+
# * modifications -> reset to pre-merge content
33+
# * NEW files -> git checkout BEFORE -- path does NOT delete them
34+
# `git rm -rf` then `git checkout BEFORE --` is the bulletproof combination.
3335
if [ "$BEFORE" != "$(git rev-parse HEAD)" ] && \
3436
! git diff --quiet "$BEFORE" HEAD -- .github/workflows/; then
35-
echo ">> Reverting upstream changes under .github/workflows/ (keep fork CI stable)"
36-
git checkout "$BEFORE" -- .github/workflows/
37+
echo ">> Restoring .github/workflows/ to pre-merge state (keep fork CI stable)"
38+
git rm -rf --quiet --ignore-unmatch .github/workflows/
39+
git checkout "$BEFORE" -- .github/workflows/ 2>/dev/null || true
3740
if ! git diff --quiet --cached; then
3841
git commit --amend --no-edit
3942
fi

0 commit comments

Comments
 (0)