Skip to content

Commit 99c5d73

Browse files
Update release.yml
1 parent 72eb24a commit 99c5d73

1 file changed

Lines changed: 1 addition & 193 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -46,199 +46,7 @@ jobs:
4646
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
4747
echo "Extracted version: $VERSION"
4848
49-
- name: Determine target branch
50-
id: target_branch
51-
run: |
52-
# Use target_commitish to determine the originating branch
53-
TARGET="${{ github.event.release.target_commitish }}"
54-
55-
# If target_commitish is empty or a SHA, default to main
56-
if [[ -z "$TARGET" ]] || [[ "$TARGET" =~ ^[0-9a-f]{40}$ ]]; then
57-
TARGET="main"
58-
fi
59-
60-
echo "target_branch=${TARGET}" >> "$GITHUB_OUTPUT"
61-
echo "Target branch: $TARGET"
62-
63-
- name: Generate GitHub App Token
64-
id: generate_token
65-
uses: actions/create-github-app-token@v2
66-
with:
67-
app-id: ${{ secrets.APP_ID }}
68-
private-key: ${{ secrets.APP_PRIVATE_KEY }}
69-
70-
- name: Checkout repository
71-
uses: actions/checkout@v6
72-
with:
73-
ref: ${{ steps.target_branch.outputs.target_branch }}
74-
fetch-depth: 0
75-
token: ${{ steps.generate_token.outputs.token }}
76-
77-
- name: Pre-build condition checks
78-
run: |
79-
TAG_NAME="${{ github.event.release.tag_name }}"
80-
81-
echo "Performing pre-build condition checks..."
82-
83-
# Fetch latest state from remote
84-
git fetch origin --tags
8549
86-
# Check if a tag exists
87-
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME$"; then
88-
echo "::error::Tag $TAG_NAME already exists on remote."
89-
exit 1
90-
fi
91-
92-
echo "Pre-build checks passed. No issues detected."
93-
94-
- name: Set up JDK 25
95-
uses: actions/setup-java@v5
96-
with:
97-
java-version: "25"
98-
distribution: "temurin"
99-
cache: maven
100-
cache-dependency-path: |
101-
pom.xml
102-
xapi-model/pom.xml
103-
xapi-client/pom.xml
104-
xapi-model-spring-boot-starter/pom.xml
105-
server-id: central
106-
server-username: MAVEN_USERNAME
107-
server-password: MAVEN_PASSWORD
108-
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
109-
gpg-passphrase: MAVEN_GPG_PASSPHRASE
11050
111-
- name: Configure Git
112-
run: |
113-
git config user.name "github-actions[bot]"
114-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
115-
116-
- name: Run Maven release:prepare
117-
run: |
118-
VERSION="${{ steps.validate_tag.outputs.version }}"
119-
TAG_NAME="${{ github.event.release.tag_name }}"
120-
121-
echo "Preparing release version: $VERSION"
122-
echo "Tag name: $TAG_NAME"
123-
124-
./mvnw -B release:prepare \
125-
-DreleaseVersion="${VERSION}" \
126-
-Dtag="${TAG_NAME}" \
127-
-DpushChanges=false \
128-
-Darguments="-pl xapi-model,xapi-client,xapi-model-spring-boot-starter -am"
129-
env:
130-
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
131-
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
132-
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
133-
134-
- name: Run Maven release:perform
135-
run: |
136-
echo "Performing release and deploying to Maven Central"
137-
138-
./mvnw -B release:perform \
139-
-DlocalCheckout=true \
140-
-DdeployAtEnd=true \
141-
-Darguments="-pl xapi-model,xapi-client,xapi-model-spring-boot-starter -am"
142-
env:
143-
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
144-
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
145-
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
146-
147-
- name: Push changes to originating branch and tag (with merge fallback)
148-
run: |
149-
TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}"
150-
TAG_NAME="${{ github.event.release.tag_name }}"
151-
152-
echo "Pushing changes to branch: $TARGET_BRANCH"
153-
154-
# First, try a normal fast-forward push
155-
if git push origin "HEAD:${TARGET_BRANCH}"; then
156-
echo "Fast-forward push to ${TARGET_BRANCH} succeeded."
157-
else
158-
echo "::warning::Fast-forward push to ${TARGET_BRANCH} failed. Trying merge fallback."
159-
160-
# Fetch latest state of the branch
161-
git fetch origin "${TARGET_BRANCH}"
162-
163-
# Merge origin/TARGET_BRANCH into our release HEAD.
164-
# If this conflicts, we bail out rather than trying to auto-resolve.
165-
if ! git merge --no-edit "origin/${TARGET_BRANCH}"; then
166-
echo "::error::Merge conflict detected - likely due to a race condition."
167-
echo ""
168-
echo "This typically happens when changes to POM files were merged to ${TARGET_BRANCH}"
169-
echo "while this release workflow was running."
170-
echo ""
171-
echo "Recommended resolution:"
172-
echo " 1. Delete this draft release in GitHub"
173-
echo " 2. Create a new release via the GitHub Release UI"
174-
echo ""
175-
echo "Note: Artifacts have been deployed to Maven Central."
176-
exit 1
177-
fi
178-
179-
# Now push the merge commit
180-
if git push origin "HEAD:${TARGET_BRANCH}"; then
181-
echo "Pushed merge commit to ${TARGET_BRANCH}."
182-
else
183-
echo "::error::Failed to push merge commit to ${TARGET_BRANCH} after merge."
184-
echo ""
185-
echo "This may be due to branch protection rules or another race condition."
186-
echo ""
187-
echo "Recommended resolution:"
188-
echo " 1. Delete this draft release in GitHub"
189-
echo " 2. Create a new release via the GitHub Release UI"
190-
exit 1
191-
fi
192-
fi
193-
194-
echo "Pushing tag $TAG_NAME"
195-
if ! git push origin "$TAG_NAME"; then
196-
echo "::error::Failed to push tag $TAG_NAME."
197-
echo ""
198-
echo "This may be due to concurrent tag creation (tag collision), where someone created a tag with"
199-
echo "the same name while this workflow was running."
200-
echo ""
201-
echo "Recommended resolution:"
202-
echo " 1. Check if the tag $TAG_NAME already exists on the remote"
203-
echo " 2. If the tag exists but points to wrong commit, delete it"
204-
echo " 3. Create a new draft release via the GitHub Release UI"
205-
exit 1
206-
fi
207-
echo "Pushed release commits and tag to $TARGET_BRANCH"
208-
209-
- name: Collect release assets
210-
run: |
211-
set -e
212-
VERSION="${{ steps.validate_tag.outputs.version }}"
213-
mkdir -p artifacts
214-
# Define artifact paths
215-
CLIENT_JAR="xapi-client/target/xapi-client-${VERSION}.jar"
216-
MODEL_JAR="xapi-model/target/xapi-model-${VERSION}.jar"
217-
STARTER_JAR="xapi-model-spring-boot-starter/target/xapi-model-spring-boot-starter-${VERSION}.jar"
218-
# Check existence and copy
219-
for JAR in "$CLIENT_JAR" "$MODEL_JAR" "$STARTER_JAR"; do
220-
if [ ! -f "$JAR" ]; then
221-
echo "::error::Artifact not found: $JAR"
222-
exit 1
223-
fi
224-
cp "$JAR" artifacts/
225-
done
226-
227-
- name: Upload release assets
228-
env:
229-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
230-
run: |
231-
TAG_NAME="${{ github.event.release.tag_name }}"
232-
for FILE in artifacts/*; do
233-
echo "Uploading $(basename "$FILE")"
234-
gh release upload "$TAG_NAME" "$FILE" --clobber
235-
done
236-
237-
- name: Publish GitHub release
238-
env:
239-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
240-
run: |
241-
TAG_NAME="${{ github.event.release.tag_name }}"
242-
echo "Publishing draft release for $TAG_NAME"
243-
gh release edit "$TAG_NAME" --draft=false
24451
52+

0 commit comments

Comments
 (0)