-
Notifications
You must be signed in to change notification settings - Fork 15
285 lines (251 loc) · 9.64 KB
/
release-finish.yml
File metadata and controls
285 lines (251 loc) · 9.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Release Finish
on:
workflow_dispatch:
inputs:
release_branch:
description: 'Release branch to finish (e.g., release/2.0.16)'
required: true
type: string
next_version_increment:
description: 'Next version increment type for master'
required: false
type: choice
default: 'patch'
options:
- major
- minor
- patch
next_version:
description: 'Or specify exact next version for base branch (e.g., 2.1.0-SNAPSHOT)'
required: false
type: string
base_branch:
description: 'Base branch to merge release back into'
required: false
type: string
default: 'master'
skip_publish:
description: 'Skip Maven Central publish (use if artifact was already published but merge/bump steps failed)'
required: false
type: boolean
default: false
jobs:
get-release-version:
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_branch }}
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: liberica
- name: Get release version
id: get_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
# Remove -SNAPSHOT if present
VERSION="${VERSION%-SNAPSHOT}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Release version: $VERSION"
create-tag:
name: Create release tag
needs: get-release-version
if: ${{ !inputs.skip_publish }}
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_branch }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
run: |
VERSION="${{ needs.get-release-version.outputs.version }}"
TAG="v${VERSION}"
echo "Creating tag: $TAG from branch ${{ inputs.release_branch }}"
git tag -a "$TAG" -m "Release $VERSION"
git push origin "$TAG"
publish-release:
name: Publish to Maven Central
needs: [get-release-version, create-tag]
if: ${{ !inputs.skip_publish }}
runs-on: ubuntu-24.04
env:
JRELEASER_MAVENCENTRAL_URL: "https://central.sonatype.com/api/v1/publisher"
JRELEASER_DEPLOY_MAVEN_MAVENCENTRAL_ACTIVE: "RELEASE"
JRELEASER_DEPLOY_MAVEN_NEXUS2_ACTIVE: "SNAPSHOT"
JRELEASER_NEXUS2_URL: "https://ossrh-staging-api.central.sonatype.com/service/local"
JRELEASER_NEXUS2_SNAPSHOT_URL: "https://central.sonatype.com/repository/maven-snapshots"
JRELEASER_OVERWRITE: true
JRELEASER_UPDATE: true
JRELEASER_GIT_ROOT_SEARCH: true
steps:
- uses: actions/checkout@v6
with:
ref: v${{ needs.get-release-version.outputs.version }}
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: liberica
cache: maven
- name: Install xmlstarlet
run: |
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
sudo apt-get -y install xmlstarlet
- name: JReleaser Release to Maven Central
uses: entur/ror-gha-workflows/.github/actions/jreleaser-release@v1
with:
version: ${{ needs.get-release-version.outputs.version }}
version_tag_prefix: v
github_token: ${{ secrets.GITHUB_TOKEN }}
sonatype_username: ${{ secrets.SONATYPE_AUTH_USER }}
sonatype_password: ${{ secrets.SONATYPE_AUTH_TOKEN }}
gpg_public_key: ${{ secrets.SONATYPE_GPG_KEY_PUBLIC }}
gpg_secret_key: ${{ secrets.SONATYPE_GPG_KEY }}
gpg_passphrase: ${{ secrets.SONATYPE_GPG_KEY_PASSWORD }}
artifactory_user: ${{ secrets.ARTIFACTORY_AUTH_USER }}
artifactory_token: ${{ secrets.ARTIFACTORY_AUTH_TOKEN }}
- name: Upload Build Reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: jreleaser-reports
path: |
**/target/site
**/target/reports/
**/target/surefire-reports
merge-release-to-base:
name: Merge release branch to base branch
needs: [get-release-version, create-tag, publish-release]
if: |
always() &&
needs.get-release-version.result == 'success' &&
(needs.create-tag.result == 'success' || needs.create-tag.result == 'skipped') &&
(needs.publish-release.result == 'success' || needs.publish-release.result == 'skipped')
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.base_branch || 'master' }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Merge release branch
run: |
RELEASE_BRANCH="${{ inputs.release_branch }}"
BASE_BRANCH="${{ inputs.base_branch || 'master' }}"
VERSION="${{ needs.get-release-version.outputs.version }}"
echo "Merging $RELEASE_BRANCH into $BASE_BRANCH"
git fetch origin "$RELEASE_BRANCH"
git merge "origin/$RELEASE_BRANCH" -m "chore: merge release $VERSION into $BASE_BRANCH"
git push origin "$BASE_BRANCH"
update-base-branch:
name: Update base branch to next SNAPSHOT version
needs: [get-release-version, merge-release-to-base]
if: |
always() &&
needs.get-release-version.result == 'success' &&
needs.merge-release-to-base.result == 'success'
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.base_branch || 'master' }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: liberica
- name: Calculate next development version
id: next_version
run: |
CURRENT_VERSION="${{ needs.get-release-version.outputs.version }}"
# Use custom version if provided, otherwise increment
if [ -n "${{ inputs.next_version }}" ]; then
NEXT_VERSION="${{ inputs.next_version }}"
# Ensure it has -SNAPSHOT
if [[ ! "$NEXT_VERSION" =~ -SNAPSHOT$ ]]; then
NEXT_VERSION="${NEXT_VERSION}-SNAPSHOT"
fi
else
INCREMENT_TYPE="${{ inputs.next_version_increment }}"
# Parse version components
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]:-0}"
MINOR="${VERSION_PARTS[1]:-0}"
PATCH="${VERSION_PARTS[2]:-0}"
# Calculate next version based on increment type
case "$INCREMENT_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
*)
echo "Error: Invalid increment type: $INCREMENT_TYPE"
exit 1
;;
esac
NEXT_VERSION="$MAJOR.$MINOR.$PATCH-SNAPSHOT"
fi
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "Next development version: $NEXT_VERSION"
- name: Update base branch version
run: |
NEXT_VERSION="${{ steps.next_version.outputs.next_version }}"
BASE_BRANCH="${{ inputs.base_branch || 'master' }}"
echo "Updating $BASE_BRANCH to: $NEXT_VERSION"
mvn -B versions:set -DnewVersion="$NEXT_VERSION" -DgenerateBackupPoms=false -DprocessAllModules=true
git add '*/pom.xml' pom.xml
git commit -m "chore: prepare for next development iteration $NEXT_VERSION [skip ci]"
git push origin "$BASE_BRANCH"
- name: Delete release branch
continue-on-error: true
run: |
RELEASE_BRANCH="${{ inputs.release_branch }}"
echo "Deleting release branch: $RELEASE_BRANCH"
git push origin --delete "$RELEASE_BRANCH" || echo "Branch already deleted"
- name: Create summary
run: |
VERSION="${{ needs.get-release-version.outputs.version }}"
BASE_BRANCH="${{ inputs.base_branch || 'master' }}"
cat >> $GITHUB_STEP_SUMMARY <<EOF
## Release Finished
- **Released Version:** $VERSION
- **Git Tag:** \`v${VERSION}\`
- **Maven Central (netex-java-model):** https://central.sonatype.com/artifact/org.entur/netex-java-model/${VERSION}
- **Next Development Version ($BASE_BRANCH):** ${{ steps.next_version.outputs.next_version }}
- **Release Branch:** Merged to $BASE_BRANCH and deleted
The release has been published to Maven Central, merged to $BASE_BRANCH, and $BASE_BRANCH has been updated to the next development version.
EOF