11# This workflow automates the release process when a release is created on GitHub
2- # It creates a release branch, updates versions, and deploys to Maven Central
2+ # It uses Maven release plugin to manage versions and deploys to Maven Central
33#
44# Usage:
55# 1. Create a new release in GitHub UI with tag format: vX.Y.Z (e.g., v1.2.0)
6+ # - Select the target branch (typically main)
67# 2. This workflow will automatically:
7- # - Create a release-X.Y.Z branch
8- # - Update pom.xml versions to release version
9- # - Build and deploy artifacts to Maven Central
10- # - Update pom.xml to next development version
11- # - Push version commits back to the release branch
8+ # - Use Maven release:prepare to update versions and create release commits
9+ # - Use Maven release:perform to build and deploy artifacts to Maven Central
10+ # - Move the tag to point to the actual release commit
11+ # - Push commits back to the originating branch
1212
1313name : Automated Release
1414
1515on :
1616 release :
17- types : [created] # Trigger when release is created (before it's published)
17+ types : [created] # Trigger when release is created
1818
1919permissions :
20- contents : write # Required to create branches and push commits
20+ contents : write # Required to push commits and update tags
2121
2222jobs :
2323 release :
4141 echo "version=${VERSION}" >> $GITHUB_OUTPUT
4242 echo "Extracted version: $VERSION"
4343
44- # Create release branch name
45- RELEASE_BRANCH="release-${VERSION}"
46- echo "release_branch=${RELEASE_BRANCH}" >> $GITHUB_OUTPUT
47- echo "Release branch: $RELEASE_BRANCH"
48-
4944 # Calculate next development version (increment patch version)
5045 IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
5146 MAJOR="${VERSION_PARTS[0]}"
@@ -56,20 +51,36 @@ jobs:
5651 echo "next_version=${NEXT_VERSION}" >> $GITHUB_OUTPUT
5752 echo "Next development version: $NEXT_VERSION"
5853
59- - name : Checkout repository at release tag
54+ - name : Determine target branch
55+ id : target_branch
56+ run : |
57+ # Use target_commitish to determine the originating branch
58+ TARGET="${{ github.event.release.target_commitish }}"
59+
60+ # If target_commitish is empty or a SHA, default to main
61+ if [[ -z "$TARGET" ]] || [[ "$TARGET" =~ ^[0-9a-f]{40}$ ]]; then
62+ TARGET="main"
63+ fi
64+
65+ echo "target_branch=${TARGET}" >> $GITHUB_OUTPUT
66+ echo "Target branch: $TARGET"
67+
68+ - name : Checkout repository
6069 uses : actions/checkout@v3
6170 with :
62- ref : ${{ github.event.release.tag_name }}
71+ ref : ${{ steps.target_branch.outputs.target_branch }}
6372 fetch-depth : 0
6473 token : ${{ secrets.GITHUB_TOKEN }}
6574
66- - name : Create release branch
75+ - name : Delete user-created tag
6776 run : |
68- RELEASE_BRANCH="${{ steps.validate_tag.outputs.release_branch }}"
77+ TAG_NAME="${{ github.event.release.tag_name }}"
78+
79+ # Delete the tag created by the user (will be recreated by release:prepare)
80+ git tag -d "$TAG_NAME" || true
81+ git push origin ":refs/tags/$TAG_NAME" || true
6982
70- # Create new branch from the release tag
71- git checkout -b "$RELEASE_BRANCH"
72- echo "Created branch $RELEASE_BRANCH from tag ${{ github.event.release.tag_name }}"
83+ echo "Deleted user-created tag $TAG_NAME"
7384
7485 - name : Set up JDK 17
7586 uses : actions/setup-java@v5
@@ -88,103 +99,60 @@ jobs:
8899 git config user.name "github-actions[bot]"
89100 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
90101
91- - name : Set release version in POM
92- run : |
93- VERSION="${{ steps.validate_tag.outputs.version }}"
94- echo "Setting version to: $VERSION"
95-
96- # Use Maven versions plugin to set the version
97- ./mvnw -B versions:set -DnewVersion="${VERSION}" -DgenerateBackupPoms=false
98-
99- # Commit the version change
100- git add .
101- git commit -m "[maven-release-plugin] prepare release v${VERSION}"
102-
103- - name : Verify release build
104- run : |
105- echo "Running tests and verification for release version"
106-
107- # Build and test the release version
108- ./mvnw -B clean verify
109-
110- - name : Build and deploy release
102+ - name : Run Maven release:prepare
111103 run : |
112104 VERSION="${{ steps.validate_tag.outputs.version }}"
113- echo "Building and deploying version: $VERSION"
105+ NEXT_VERSION="${{ steps.validate_tag.outputs.next_version }}"
106+ TAG_NAME="${{ github.event.release.tag_name }}"
114107
115- # Build and deploy with release profile (includes signing, sources, javadocs)
116- ./mvnw -B clean deploy -Prelease \
117- -pl xapi-model,xapi-client,xapi-model-spring-boot-starter -am \
118- -DskipTests
108+ echo "Preparing release version: $VERSION"
109+ echo "Next development version: $NEXT_VERSION"
110+ echo "Tag name: $TAG_NAME"
111+
112+ # Run release:prepare with explicit versions
113+ ./mvnw -B release:prepare \
114+ -DreleaseVersion="${VERSION}" \
115+ -DdevelopmentVersion="${NEXT_VERSION}" \
116+ -Dtag="${TAG_NAME}" \
117+ -DpushChanges=false \
118+ -DremoteTagging=false
119119 env :
120120 MAVEN_USERNAME : ${{ secrets.OSSRH_USERNAME }}
121121 MAVEN_PASSWORD : ${{ secrets.OSSRH_TOKEN }}
122122 MAVEN_GPG_PASSPHRASE : ${{ secrets.MAVEN_GPG_PASSPHRASE }}
123123
124- - name : Update to next development version
124+ - name : Run Maven release:perform
125125 run : |
126- NEXT_VERSION="${{ steps.validate_tag.outputs.next_version }}"
127- echo "Setting next development version to: $NEXT_VERSION"
126+ echo "Performing release and deploying to Maven Central"
128127
129- # Update to next SNAPSHOT version
130- ./mvnw -B versions:set -DnewVersion="${NEXT_VERSION}" -DgenerateBackupPoms=false
131-
132- # Commit the version change
133- git add .
134- git commit -m "[maven-release-plugin] prepare for next development iteration"
128+ # Run release:perform to build and deploy
129+ ./mvnw -B release:perform \
130+ -DlocalCheckout=true \
131+ -DeployAtEnd=true
132+ env :
133+ MAVEN_USERNAME : ${{ secrets.OSSRH_USERNAME }}
134+ MAVEN_PASSWORD : ${{ secrets.OSSRH_TOKEN }}
135+ MAVEN_GPG_PASSPHRASE : ${{ secrets.MAVEN_GPG_PASSPHRASE }}
135136
136- - name : Update release tag to point to release commit
137+ - name : Push changes to originating branch
137138 run : |
139+ TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}"
138140 TAG_NAME="${{ github.event.release.tag_name }}"
139141
140- # Delete the existing tag locally
141- git tag -d "$TAG_NAME"
142-
143- # Get the commit hash of the release preparation commit (one before current)
144- RELEASE_COMMIT=$(git rev-parse HEAD~1)
145-
146- # Create new tag pointing to the release commit
147- git tag -a "$TAG_NAME" "$RELEASE_COMMIT" -m "Release $TAG_NAME"
148-
149- # Force push the updated tag
150- git push -f origin "$TAG_NAME"
151-
152- echo "Updated tag $TAG_NAME to point to release commit: $RELEASE_COMMIT"
153-
154- - name : Push release branch
155- run : |
156- RELEASE_BRANCH="${{ steps.validate_tag.outputs.release_branch }}"
157-
158- # Push the release branch with all commits
159- git push -u origin "$RELEASE_BRANCH"
160-
161- echo "Pushed release branch: $RELEASE_BRANCH"
162-
163- - name : Update main branch with next development version
164- run : |
165- NEXT_VERSION="${{ steps.validate_tag.outputs.next_version }}"
166-
167- echo "Updating main branch to next development version: $NEXT_VERSION"
168-
169- # Fetch and checkout main branch
170- git fetch origin main
171- git checkout main
172-
173- # Update to next SNAPSHOT version
174- ./mvnw -B versions:set -DnewVersion="${NEXT_VERSION}" -DgenerateBackupPoms=false
142+ echo "Pushing changes to branch: $TARGET_BRANCH"
175143
176- # Commit the version change
177- git add .
178- git commit -m "[maven-release-plugin] prepare for next development iteration"
144+ # Push the commits created by release:prepare
145+ git push origin "HEAD:${TARGET_BRANCH}"
179146
180- # Push to main
181- git push origin main
147+ # Push the tag created by release:prepare
148+ git push origin "$TAG_NAME"
182149
183- echo "Updated main branch to version: $NEXT_VERSION "
150+ echo "Pushed release commits and tag to $TARGET_BRANCH "
184151
185152 - name : Clean up
186153 if : always()
187154 run : |
188- # Clean up any Maven artifacts
189- rm -f release.properties
190- find . -name "pom.xml.versionsBackup" -delete || true
155+ # Clean up Maven release artifacts
156+ rm -f release.properties pom.xml.releaseBackup
157+ find . -name "pom.xml.releaseBackup" -delete || true
158+ find . -name "pom.xml.tag" -delete || true
0 commit comments