-
Notifications
You must be signed in to change notification settings - Fork 2
300 lines (247 loc) · 11.3 KB
/
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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Release new version
on:
workflow_dispatch:
inputs:
releaseversion:
description: 'Release version'
# required: true
# default: '2.4.0'
# snapshotversion:
# description: 'Next snapshot version'
# required: true
# default: '2.4.1'
env:
JAVA_VERSION: 11.0.3
SERVER_ID: ossrh
jobs:
version_change:
name: Create version and tag
runs-on: ubuntu-latest
outputs:
build_tag: ${{ steps.tagging.outputs.build_tag }} # map step output to job output
build_tag_created: ${{ steps.tagging.outputs.build_tag_created }}
build_version: ${{ steps.tagging.outputs.build_version }} # map step output to job output
build_branch: ${{ steps.tagging.outputs.build_branch }}
previous_release_tag: ${{ steps.tagging.outputs.previous_release_tag }}
steps:
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: setup git config
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Maven download
run: mvn validate dependency:resolve-plugins -B --quiet
- name: Set release version
id: tagging
run: |
# make sure we are at the head of development
NEW_RELEASE_VERSION=${{ github.event.inputs.releaseversion }}
echo "Input version is $NEW_RELEASE_VERSION"
# remove all but the release version
mvn -B --quiet versions:set-property -Dproperty=changelist "-DnewVersion="
mvn -B --quiet versions:set-property -Dproperty=sha1 "-DnewVersion="
# detect if a override version is given
if [ "$NEW_RELEASE_VERSION" == "" ]; then
echo "Input version not set. Use current version"
NEW_RELEASE_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
fi
# set the version to be released
NEW_RELEASE_TAG="Release/${NEW_RELEASE_VERSION}"
NEW_RELEASE_BRANCH="prepare-release/${NEW_RELEASE_VERSION}"
echo "::set-output name=build_tag::${NEW_RELEASE_TAG}"
echo "::set-output name=build_version::${NEW_RELEASE_VERSION}"
echo "::set-output name=build_branch::${NEW_RELEASE_BRANCH}"
PREVIOUS_RELEASE_TAG=$(git tag | sort -V | tail -1)
echo "::set-output name=previous_release_tag::${PREVIOUS_RELEASE_TAG}"
echo "release version is $NEW_RELEASE_VERSION"
echo "Tag release version is now $NEW_RELEASE_TAG"
mvn -B --quiet versions:set-property -Dproperty=revision "-DnewVersion=${NEW_RELEASE_VERSION}"
git checkout -b $NEW_RELEASE_BRANCH
git push -f --set-upstream origin $NEW_RELEASE_BRANCH
git add pom.xml
git commit -m "New release version ${NEW_RELEASE_VERSION}"
git tag -a "${NEW_RELEASE_TAG}" -m "Release version ${NEW_RELEASE_VERSION}"
git push origin "${NEW_RELEASE_TAG}"
echo "::set-output name=build_tag_created::YES"
# prepare next snapshot for development
mvn -B --quiet ci-friendly-flatten:version -Dprefix.regex="Release/*"
SNAPSHOTVERSION=$(cat revision.txt)
mvn -B --quiet versions:set-property -Dproperty=revision "-DnewVersion=$SNAPSHOTVERSION"
mvn -B --quiet versions:set-property -Dproperty=changelist "-DnewVersion=-SNAPSHOT"
mvn -B --quiet versions:set-property -Dproperty=sha1 "-DnewVersion="
git add pom.xml
git commit -m "Next snapshot version $SNAPSHOTVERSION"
git push
build:
name: Java and Native Compilation
runs-on: ${{ matrix.os }}
needs: version_change
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ] # ubuntu-latest, , macos-latest
platform: [ x64 ] #x32, x64 ]
exclude:
- os: macos-latest
platform: x32
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
ref: ${{ needs.version_change.outputs.build_tag }}
- name: Set up Java x64
if: matrix.platform == 'x64'
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
architecture: x64
- name: Set up Java x32
if: matrix.platform == 'x86'
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
architecture: x32
- name: Maven download
run: mvn validate dependency:resolve-plugins -Psonatype -B --quiet
- name: Maven Build
run: mvn -B package -Psonatype -Prelease -Dchangelist= -Dsha1= --file pom.xml "-Dmaven.test.skip=true"
final:
name: Build and Deploy Combined Release
runs-on: ubuntu-latest
needs: [ version_change , build ]
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
ref: ${{ needs.version_change.outputs.build_tag }}
- id: install-secret-key
name: Install gpg secret key
run: |
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
gpg --list-secret-keys --keyid-format LONG
- name: Environment variables
run: echo ${{ env.SERVER_ID }}
- name: Set up Java x64
if: matrix.platform == 'x64'
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
architecture: x64
- name: Set up Java x32
if: matrix.platform == 'x86'
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
architecture: x32
- name: Deploy server
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}
server-id: ${{ env.SERVER_ID }}
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Maven download
run: mvn validate dependency:resolve-plugins -Psonatype -B --quiet
- name: Maven Build Final
run: mvn -B package -Psonatype -Prelease -Dchangelist= -Dsha1= --file pom.xml -Dmaven.test.skip=true
- name: Maven Deploy RELEASE
# If autorelease is false then it must be released from here: https://oss.sonatype.org/#stagingRepositories -DautoReleaseAfterClose=true
run: mvn -B deploy -Dchangelist= -Dsha1= -Dmaven.test.skip=true -DskipITs -fae -Psonatype -Prelease -P\!combinedtest
env:
MAVEN_USERNAME: ${{ secrets.OSS_SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSS_SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
- name: Create changelog config
run: echo '{"max_back_track_time_days":1095}' > configuration.json
- name: Generate changelog
id: changelog
uses: mikepenz/[email protected]
with:
configuration: "configuration.json"
toTag: ${{ needs.version_change.outputs.build_tag }}
fromTag: ${{ needs.version_change.outputs.previous_release_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.version_change.outputs.build_tag }}
release_name: ${{ needs.version_change.outputs.build_tag }}
body: |
Grab the new version from Maven central https://search.maven.org/artifact/org.into-cps.fmi/jnifmuapi/${{ needs.version_change.outputs.build_version }}/jar:
```
<dependency>
<groupId>org.into-cps.vdmcheck.fmi2</groupId>
<artifactId>vdmcheck2</artifactId>
<version>${{ needs.version_change.outputs.build_version }}</version>
</dependency>
```
### Things that changed in this release
${{ steps.changelog.outputs.changelog }}
draft: true
prerelease: false
- name: Upload Release Asset - VDMCheck2
id: upload-release-asset2
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: fmi2/vdmcheck/target/FMI2-vdmcheck-${{ needs.version_change.outputs.build_version }}-distribution.zip
asset_name: FMI2-vdmcheck-${{ needs.version_change.outputs.build_version }}-distribution.zip
asset_content_type: application/zip
- name: Upload Release Asset - VDMCheck3
id: upload-release-asset3
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: fmi3/vdmcheck/target/FMI3-vdmcheck-${{ needs.version_change.outputs.build_version }}-distribution.zip
asset_name: FMI3-vdmcheck-${{ needs.version_change.outputs.build_version }}-distribution.zip
asset_content_type: application/zip
rollback:
name: Rollback on error
runs-on: ubuntu-latest
needs: [ version_change , build, final ]
if: always() && (needs.version_change.result == 'failure' || needs.build.result == 'failure' || needs.final.result == 'failure')
steps:
- uses: actions/checkout@v2
- name: Rolling back tag
continue-on-error: true
if: needs.version_change.outputs.build_tag_created == 'YES'
# we don't want to accidentally delete an existing tag from an existing release
run: git push --delete origin ${{ needs.version_change.outputs.build_tag }}
- name: Rolling back branch
continue-on-error: true
run: git push origin --delete ${{ needs.version_change.outputs.build_branch }}
cleanup:
name: Update development and master with new release
runs-on: ubuntu-latest
needs: [ final,version_change ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Merging release
run: |
git fetch origin ${{ needs.version_change.outputs.build_branch }}
git checkout development
git merge origin/${{ needs.version_change.outputs.build_branch }}
git push
git checkout master
git reset --hard ${{ needs.version_change.outputs.build_tag }}
git push -f origin master