Skip to content

Commit 71cf7de

Browse files
committed
Sync release automation to main
1 parent 2db8823 commit 71cf7de

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

‎.github/workflows/release-please.yml‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,44 @@ jobs:
5151
# version bump and changelog must also land back on scalar-next, or the next
5252
# release PR would propose this release again. A real merge (never a plain
5353
# commit push) so a squash- or rebase-merged release PR syncs just as well; the
54-
# non-conventional message keeps the sync commit out of future changelogs. Plain
55-
# (non-force) push on purpose: losing a race against a concurrent regeneration
56-
# push fails loudly here, and the platform's next sync re-converges.
54+
# non-conventional message keeps the sync commit out of future changelogs.
55+
#
56+
# The Scalar platform merges main into scalar-next itself when the release
57+
# PR merges, so this step routinely races it. The sync is done once the release commit
58+
# is an ancestor of scalar-next, whoever merged it, so that is checked before every
59+
# attempt. A rejected push retries from a fresh fetch rather than failing the release
60+
# run. Plain (non-force) push on purpose: a concurrent regeneration push is never
61+
# discarded, and a sync that still cannot land after the retries fails loudly.
5762
- name: Sync release back to scalar-next
5863
if: ${{ steps.release.outputs.release_created == 'true' }}
64+
env:
65+
RELEASE_SHA: ${{ steps.release.outputs.sha }}
66+
RELEASE_TAG: ${{ steps.release.outputs.tag_name }}
5967
run: |
6068
git config user.name "github-actions[bot]"
6169
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
62-
git fetch origin scalar-next
63-
git checkout -B scalar-next origin/scalar-next
64-
git merge --no-edit -m "Sync release ${{ steps.release.outputs.tag_name }} back to scalar-next" "${{ steps.release.outputs.sha }}"
65-
git push origin scalar-next
70+
# Explicit `|| return 1`s because `set -e` does not apply inside a function called
71+
# as a condition, and a failed merge must never fall through to a no-op push.
72+
sync_release() {
73+
git fetch origin scalar-next || return 1
74+
if git merge-base --is-ancestor "$RELEASE_SHA" origin/scalar-next; then
75+
echo "$RELEASE_TAG is already on scalar-next."
76+
return 0
77+
fi
78+
git checkout -B scalar-next origin/scalar-next || return 1
79+
if ! git merge --no-edit -m "Sync release $RELEASE_TAG back to scalar-next" "$RELEASE_SHA"; then
80+
git merge --abort
81+
return 1
82+
fi
83+
git push origin scalar-next
84+
}
85+
for attempt in 1 2 3; do
86+
if sync_release; then exit 0; fi
87+
echo "Attempt $attempt of 3 to sync $RELEASE_TAG back to scalar-next failed."
88+
if [ "$attempt" -lt 3 ]; then sleep $((attempt * 5)); fi
89+
done
90+
echo "::error::Could not sync $RELEASE_TAG back to scalar-next after 3 attempts."
91+
exit 1
6692
publish:
6793
needs: release-please
6894
# `!cancelled()` keeps publishing even when the back-sync to the integration branch

0 commit comments

Comments
 (0)