Skip to content

Commit 9e567c4

Browse files
committed
tip
1 parent 32df83b commit 9e567c4

1 file changed

Lines changed: 31 additions & 67 deletions

File tree

.github/workflows/release.yml

Lines changed: 31 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -75,44 +75,23 @@ jobs:
7575
fetch-depth: 0
7676
token: ${{ steps.generate_token.outputs.token }}
7777

78-
- name: Handle existing tag safely
79-
id: handle_tag
78+
- name: Pre-build condition checks
8079
run: |
8180
TAG_NAME="${{ github.event.release.tag_name }}"
82-
TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}"
83-
84-
echo "Checking tag $TAG_NAME on branch $TARGET_BRANCH"
85-
86-
# Make sure we have up-to-date branch and tags
87-
git fetch origin --tags "$TARGET_BRANCH"
8881
89-
# SHA of the target branch head (what the user chose in the release UI)
90-
BRANCH_SHA="$(git rev-parse "origin/$TARGET_BRANCH")"
91-
echo "Branch HEAD (origin/$TARGET_BRANCH) is $BRANCH_SHA"
92-
echo "expected_branch_sha=${BRANCH_SHA}" >> "$GITHUB_OUTPUT"
82+
echo "Performing pre-build condition checks..."
9383
94-
# SHA of the tag if it exists
95-
if git rev-parse "refs/tags/$TAG_NAME^{commit}" >/dev/null 2>&1; then
96-
TAG_SHA="$(git rev-parse "refs/tags/$TAG_NAME^{commit}")"
97-
echo "Existing tag $TAG_NAME points at $TAG_SHA"
84+
# Fetch latest state from remote
85+
git fetch origin --tags
9886
99-
if [[ "$TAG_SHA" == "$BRANCH_SHA" ]]; then
100-
echo "Tag points at the target branch head – treating as freshly created UI tag."
101-
echo "Will delete it so Maven can recreate the tag on the release commit."
102-
git tag -d "$TAG_NAME" || true
103-
git push origin ":refs/tags/$TAG_NAME" || true
104-
echo "deleted=true" >> "$GITHUB_OUTPUT"
105-
else
106-
echo "::error::Tag $TAG_NAME already exists and does NOT point at origin/$TARGET_BRANCH."
107-
echo "This may indicate a previous release attempt or conflicting tag."
108-
echo "deleted=false" >> "$GITHUB_OUTPUT"
109-
exit 1
110-
fi
111-
else
112-
echo "Tag $TAG_NAME does not exist yet – nothing to delete."
113-
echo "deleted=false" >> "$GITHUB_OUTPUT"
87+
# Check if a tag exists
88+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME$"; then
89+
echo "::error::Tag $TAG_NAME already exists on remote."
90+
exit 1
11491
fi
11592
93+
echo "Pre-build checks passed. No issues detected."
94+
11695
- name: Set up JDK 25
11796
uses: actions/setup-java@v5
11897
with:
@@ -135,39 +114,6 @@ jobs:
135114
git config user.name "github-actions[bot]"
136115
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
137116
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-
171117
- name: Run Maven release:prepare
172118
run: |
173119
VERSION="${{ steps.validate_tag.outputs.version }}"
@@ -225,9 +171,9 @@ jobs:
225171
echo ""
226172
echo "Recommended resolution:"
227173
echo " 1. Delete this draft release in GitHub"
228-
echo " 2. Create a new draft release via the GitHub Release UI"
174+
echo " 2. Create a new release via the GitHub Release UI"
229175
echo ""
230-
echo "Note: Artifacts have NOT been deployed to Maven Central."
176+
echo "Note: Artifacts have been deployed to Maven Central."
231177
exit 1
232178
fi
233179
@@ -241,7 +187,7 @@ jobs:
241187
echo ""
242188
echo "Recommended resolution:"
243189
echo " 1. Delete this draft release in GitHub"
244-
echo " 2. Create a new draft release via the GitHub Release UI"
190+
echo " 2. Create a new release via the GitHub Release UI"
245191
exit 1
246192
fi
247193
fi
@@ -261,10 +207,28 @@ jobs:
261207
fi
262208
echo "Pushed release commits and tag to $TARGET_BRANCH"
263209
210+
- name: Collect release assets
211+
run: |
212+
mkdir -p artifacts
213+
cp xapi-client/target/xapi-client-${{version}}.jar artifacts/
214+
cp xapi-model/target/xapi-model-${{version}}.jar artifacts/
215+
cp xapi-model-spring-boot-starter/target/xapi-model-spring-boot-starter-${{version}}.jar artifacts/
216+
217+
- name: Upload release assets
218+
env:
219+
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
220+
run: |
221+
TAG_NAME="${{ github.event.release.tag_name }}"
222+
for FILE in artifacts/*; do
223+
echo "Uploading $(basename "$FILE")"
224+
gh release upload "$TAG_NAME" "$FILE" --clobber
225+
done
226+
264227
- name: Publish GitHub release
265228
env:
266229
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
267230
run: |
268231
TAG_NAME="${{ github.event.release.tag_name }}"
269232
echo "Publishing draft release for $TAG_NAME"
270233
gh release edit "$TAG_NAME" --draft=false
234+

0 commit comments

Comments
 (0)