|
89 | 89 | # SHA of the target branch head (what the user chose in the release UI) |
90 | 90 | BRANCH_SHA="$(git rev-parse "origin/$TARGET_BRANCH")" |
91 | 91 | echo "Branch HEAD (origin/$TARGET_BRANCH) is $BRANCH_SHA" |
| 92 | + echo "expected_branch_sha=${BRANCH_SHA}" >> "$GITHUB_OUTPUT" |
92 | 93 |
|
93 | 94 | # SHA of the tag if it exists |
94 | 95 | if git rev-parse "refs/tags/$TAG_NAME^{commit}" >/dev/null 2>&1; then |
@@ -134,6 +135,39 @@ jobs: |
134 | 135 | git config user.name "github-actions[bot]" |
135 | 136 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
136 | 137 |
|
| 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 | +
|
137 | 171 | - name: Run Maven release:prepare |
138 | 172 | run: | |
139 | 173 | VERSION="${{ steps.validate_tag.outputs.version }}" |
@@ -184,22 +218,47 @@ jobs: |
184 | 218 | # Merge origin/TARGET_BRANCH into our release HEAD. |
185 | 219 | # If this conflicts, we bail out rather than trying to auto-resolve. |
186 | 220 | 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." |
189 | 231 | exit 1 |
190 | 232 | fi |
191 | 233 |
|
192 | 234 | # Now push the merge commit |
193 | 235 | if git push origin "HEAD:${TARGET_BRANCH}"; then |
194 | 236 | echo "Pushed merge commit to ${TARGET_BRANCH}." |
195 | 237 | 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" |
197 | 245 | exit 1 |
198 | 246 | fi |
199 | 247 | fi |
200 | 248 |
|
201 | 249 | 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 |
203 | 262 | echo "Pushed release commits and tag to $TARGET_BRANCH" |
204 | 263 |
|
205 | 264 | - name: Publish GitHub release |
|
0 commit comments