Skip to content

Commit 32df83b

Browse files
authored
Address feedback on release process improvements for error handling and race conditions (#431)
1 parent f6d0210 commit 32df83b

1 file changed

Lines changed: 63 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
# SHA of the target branch head (what the user chose in the release UI)
9090
BRANCH_SHA="$(git rev-parse "origin/$TARGET_BRANCH")"
9191
echo "Branch HEAD (origin/$TARGET_BRANCH) is $BRANCH_SHA"
92+
echo "expected_branch_sha=${BRANCH_SHA}" >> "$GITHUB_OUTPUT"
9293
9394
# SHA of the tag if it exists
9495
if git rev-parse "refs/tags/$TAG_NAME^{commit}" >/dev/null 2>&1; then
@@ -134,6 +135,39 @@ jobs:
134135
git config user.name "github-actions[bot]"
135136
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
136137
138+
- name: Validate no race conditions before build
139+
run: |
140+
TAG_NAME="${{ github.event.release.tag_name }}"
141+
TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}"
142+
EXPECTED_BRANCH_SHA="${{ steps.handle_tag.outputs.expected_branch_sha }}"
143+
144+
echo "Performing pre-build race condition checks..."
145+
echo "Expected branch SHA: $EXPECTED_BRANCH_SHA"
146+
147+
# Fetch latest state from remote (tags and branch separately for clarity)
148+
git fetch origin --tags
149+
git fetch origin "$TARGET_BRANCH"
150+
151+
# Check if a tag was created by another process after it was deleted in handle_tag step
152+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME$"; then
153+
echo "::error::Race condition detected: Tag $TAG_NAME was re-created on remote after being deleted."
154+
echo "Another process may have created this tag while this workflow was running."
155+
echo "Please verify no other release process is running and try again."
156+
exit 1
157+
fi
158+
159+
# Check if the branch has moved (new commits pushed)
160+
CURRENT_BRANCH_SHA="$(git rev-parse "origin/$TARGET_BRANCH")"
161+
if [[ "$CURRENT_BRANCH_SHA" != "$EXPECTED_BRANCH_SHA" ]]; then
162+
echo "::error::Race condition detected: Branch $TARGET_BRANCH has new commits since this workflow started."
163+
echo "Expected SHA: $EXPECTED_BRANCH_SHA"
164+
echo "Current SHA: $CURRENT_BRANCH_SHA"
165+
echo "Please create a new release via the GitHub Release UI to include the latest changes."
166+
exit 1
167+
fi
168+
169+
echo "Pre-build validation passed. No race conditions detected."
170+
137171
- name: Run Maven release:prepare
138172
run: |
139173
VERSION="${{ steps.validate_tag.outputs.version }}"
@@ -184,22 +218,47 @@ jobs:
184218
# Merge origin/TARGET_BRANCH into our release HEAD.
185219
# If this conflicts, we bail out rather than trying to auto-resolve.
186220
if ! git merge --no-edit "origin/${TARGET_BRANCH}"; then
187-
echo "::error::Automatic merge with origin/${TARGET_BRANCH} failed due to conflicts."
188-
echo "Please resolve manually by checking out the release branch locally and merging origin/${TARGET_BRANCH}."
221+
echo "::error::Merge conflict detected - likely due to a race condition."
222+
echo ""
223+
echo "This typically happens when changes to POM files were merged to ${TARGET_BRANCH}"
224+
echo "while this release workflow was running."
225+
echo ""
226+
echo "Recommended resolution:"
227+
echo " 1. Delete this draft release in GitHub"
228+
echo " 2. Create a new draft release via the GitHub Release UI"
229+
echo ""
230+
echo "Note: Artifacts have NOT been deployed to Maven Central."
189231
exit 1
190232
fi
191233
192234
# Now push the merge commit
193235
if git push origin "HEAD:${TARGET_BRANCH}"; then
194236
echo "Pushed merge commit to ${TARGET_BRANCH}."
195237
else
196-
echo "::error::Failed to push merge commit to ${TARGET_BRANCH}."
238+
echo "::error::Failed to push merge commit to ${TARGET_BRANCH} after merge."
239+
echo ""
240+
echo "This may be due to branch protection rules or another race condition."
241+
echo ""
242+
echo "Recommended resolution:"
243+
echo " 1. Delete this draft release in GitHub"
244+
echo " 2. Create a new draft release via the GitHub Release UI"
197245
exit 1
198246
fi
199247
fi
200248
201249
echo "Pushing tag $TAG_NAME"
202-
git push origin "$TAG_NAME"
250+
if ! git push origin "$TAG_NAME"; then
251+
echo "::error::Failed to push tag $TAG_NAME."
252+
echo ""
253+
echo "This may be due to a race condition where someone created a tag with"
254+
echo "the same name while this workflow was running."
255+
echo ""
256+
echo "Recommended resolution:"
257+
echo " 1. Check if the tag $TAG_NAME already exists on the remote"
258+
echo " 2. If the tag exists but points to wrong commit, delete it"
259+
echo " 3. Create a new draft release via the GitHub Release UI"
260+
exit 1
261+
fi
203262
echo "Pushed release commits and tag to $TARGET_BRANCH"
204263
205264
- name: Publish GitHub release

0 commit comments

Comments
 (0)