Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/scripts/test-merge-main-into-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unset GITHUB_STEP_SUMMARY

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
HELPER="$SCRIPT_DIR/merge-main-into-release.sh"
WORKFLOW="$SCRIPT_DIR/../workflows/update-release-branch.yml"
TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/release-sync-tests.XXXXXX")"
trap 'cd "$SCRIPT_DIR"; rm -rf -- "$TEST_ROOT"' EXIT

Expand All @@ -15,6 +16,11 @@ fail() {
exit 1
}

grep -Fq 'for attempt in {1..3}; do' "$WORKFLOW" || fail "Release workflow does not retry rejected pushes."
grep -Fq 'git checkout -B "$BRANCH" "origin/$BRANCH"' "$WORKFLOW" || fail "Release workflow does not refresh the release branch before retrying."
grep -Fq 'if git push origin "HEAD:refs/heads/$BRANCH"; then' "$WORKFLOW" || fail "Release workflow does not handle rejected pushes."
echo "PASS: workflow retries release branch push races"

write_file() {
mkdir -p -- "$(dirname -- "$1")"
printf '%s\n' "$2" > "$1"
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/update-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,21 @@ jobs:
run: |
set -euo pipefail

git fetch origin main
MAIN_SHA="$(git rev-parse origin/main)"
for attempt in {1..3}; do
git fetch origin main "$BRANCH"
git checkout -B "$BRANCH" "origin/$BRANCH"
MAIN_SHA="$(git rev-parse origin/main)"
Comment on lines +84 to +87

# Checkout is on release; always run the helper from the pinned main
# commit, including when release has not received the helper yet.
git show "$MAIN_SHA:.github/scripts/merge-main-into-release.sh" > "$RUNNER_TEMP/merge-main-into-release.sh"
bash "$RUNNER_TEMP/merge-main-into-release.sh" "$MAIN_SHA" "$BRANCH"
git push origin "HEAD:refs/heads/$BRANCH"
# Always run the helper from the pinned main commit, including when
# release has not received the helper yet.
git show "$MAIN_SHA:.github/scripts/merge-main-into-release.sh" > "$RUNNER_TEMP/merge-main-into-release.sh"
bash "$RUNNER_TEMP/merge-main-into-release.sh" "$MAIN_SHA" "$BRANCH"
if git push origin "HEAD:refs/heads/$BRANCH"; then
exit 0
fi

echo "::warning::Release branch changed while syncing; retrying ($attempt/3)."
Comment on lines +93 to +97
done

echo "::error::Unable to push release sync after 3 attempts."
exit 1
Loading