-
Notifications
You must be signed in to change notification settings - Fork 1
221 lines (185 loc) · 6.34 KB
/
maven-release.yml
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
# Fully automated release to GitHub Packages
# This workflow performs the following operations:
#
# - Create a release branch
# - Prepare the release with Maven
# - Perform the release to GitHub Packages
# - Upload Maven Site to GitHub Pages
# - Publish the packages as a GitHub Release
# - Create a Pull Request to prepare next development version
#
# Requires the GITHUB_TOKEN secret to be defined (workspace or organization)
name: Release to GitHub Packages
run-name: Release v${{ inputs.releaseVersion }} to GitHub Packages
on:
workflow_dispatch:
inputs:
releaseVersion:
type: string
description: "Release version"
required: true
default: ""
developmentVersion:
type: string
description: "New SNAPSHOT version"
required: true
default: ""
permissions:
contents: write
pull-requests: write
pages: write
id-token: write
packages: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these releases and deployments to complete.
concurrency:
group: release
cancel-in-progress: false
# Default to bash
defaults:
run:
shell: bash
jobs:
prepare:
name: Prepare Release v${{ inputs.releaseVersion }}
runs-on: ubuntu-latest
outputs:
branchName: ${{ env.branchName }}
tagName: ${{ env.tagName }}
steps:
- name: Setup tmate SSH session
uses: mxschmitt/action-tmate@v3
with:
detached: true
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: temurin
java-package: jdk
cache: maven
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Set release branch and tag name
run: |
echo "branchName=release/v$INPUT_RELEASEVERSION" >> $GITHUB_ENV
echo "tagName=v$INPUT_RELEASEVERSION" >> $GITHUB_ENV
env:
INPUT_RELEASEVERSION: ${{ inputs.releaseVersion }}
- name: Create ${{ env.branchName }} branch
run: |
git checkout ${{ env.branchName }} 2>/dev/null || git checkout -b ${{ env.branchName }}
git push --force origin ${{ env.branchName }}
- name: Clean up existing ${{ env.tagName }} tags
run: |
git tag -d ${{ env.tagName }} || true
git push origin :refs/tags/${{ env.tagName }} || true
- name: Prepare release
id: prepare
run: |
mvn -B -U \
-Prelease \
release:clean \
release:prepare \
-DpreparationGoals="clean verify" \
-DreleaseVersion=${{ inputs.releaseVersion }} \
-DdevelopmentVersion=${{ inputs.developmentVersion }} \
-Dresume=false
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Release rollback on failure
run: |
mvn -B -U \
release:rollback \
if: always() && (steps.prepare.outcome == 'failure')
- uses: actions/upload-artifact@v4
with:
name: release.properties
path: release.properties
release:
name: Release v${{ inputs.releaseVersion }} on ${{ matrix.config.os }}
needs: prepare
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- { os: ubuntu-latest, mavenProfile: linux }
- { os: windows-latest, mavenProfile: windows }
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: temurin
java-package: jdk
cache: maven
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- uses: actions/download-artifact@v4
with:
name: release.properties
- name: Perform release to GitHub Packages
id: perform
run: |
mvn -B -U \
-P${{ matrix.config.mavenProfile }} \
release:perform \
-Dgoals=deploy \
-DworkingDirectory=$GITHUB_WORKSPACE/target/release \
-DreleaseVersion=${{ inputs.releaseVersion }} \
-DdevelopmentVersion=${{ inputs.developmentVersion }} \
-s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Release rollback on failure
run: |
mvn -B -U \
release:rollback \
if: always() && (steps.perform.outcome == 'failure')
- uses: actions/upload-artifact@v4
with:
name: jre-${{ matrix.config.os }}
path: |
./target/release/target/*.buildinfo
./target/release/metricshub-jre-*/target/*.zip
./target/release/metricshub-jre-*/target/*.buildinfo
# Finalize job
finalize:
name: Finalize release
runs-on: ubuntu-latest
needs: [ prepare, release ]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create a GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.prepare.outputs.tagName }}
fail_on_unmatched_files: false
generate_release_notes: true
files: |
./target/*.buildinfo
./metricshub-jre-*/target/*.zip
./metricshub-jre-*/target/*.buildinfo
- name: Create Pull Request from ${{ needs.prepare.outputs.branchName }} to ${{ github.event.repository.default_branch }}
uses: devops-infra/[email protected]
with:
github_token: ${{ github.token }}
source_branch: ${{ needs.prepare.outputs.branchName }}
target_branch: ${{ github.event.repository.default_branch }}
title: Release v${{ inputs.releaseVersion }} and prepare v${{ inputs.developmentVersion }}
body: |
## Automated release
* Release **v${{ inputs.releaseVersion }}**
* Prepare **v${{ inputs.developmentVersion }}**
label: automatic
get_diff: true
allow_no_diff: true