forked from NationalSecurityAgency/emissary
-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (221 loc) · 9.29 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
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
# This is a release workflow that leverages the maven release plugin specified in
# the pom.xml to perform a release and create a tag of that release version.
---
name: "Maven: Release"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
inputs:
release_type:
description: "Choose the release type"
required: true
default: "release"
type: choice
options:
- release
- milestone
- patch
release_suffix:
description: "Add a suffix to the release version (-M1)"
required: false
default: ""
env:
JAVA_VERSION: "11"
JAVA_DISTRIBUTION: "corretto"
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Djava.awt.headless=true"
jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Check release is using correct branch
if: ${{ github.event.inputs.release_type == 'release' && github.ref_name != 'main' }}
run: |
echo "Release is not using the correct branch, please target 'main'"
exit 1
- name: Check milestone release type is using correct branch
if: ${{ github.event.inputs.release_type == 'milestone' && github.ref_name != 'main' }}
run: |
echo "Milestone release is not using the correct branch, please target 'main'"
exit 1
- name: Check milestone has release suffix
if: ${{ github.event.inputs.release_type == 'milestone' && github.event.inputs.release_suffix == '' }}
run: |
echo "Milestone release is missing a release suffix, i.e. -M1"
exit 1
- name: Check suffix is not specified for a release or patch
if: ${{ github.event.inputs.release_type != 'milestone' && github.event.inputs.release_suffix != '' }}
run: |
echo "Suffix should only be specified for milestone releases"
exit 1
- name: Check patch release type is using correct branch
if: ${{ github.event.inputs.release_type == 'patch' && !startsWith(github.ref_name, 'patch/') }}
run: |
echo "Patch release is not using the correct branch, please target a branch that starts with 'patch/'"
exit 1
get_version:
needs: verify
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Get the version
run: echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '\[.*' | awk -F- '{print ""$1"${{ github.event.inputs.release_suffix }}"}')" >> "$GITHUB_ENV"
outputs:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
release:
needs: get_version
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Add RELEASE_VERSION to environment variable
run: echo "RELEASE_VERSION=${{ needs.get_version.outputs.RELEASE_VERSION }}" >> "$GITHUB_ENV"
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
cache: "maven"
distribution: ${{ env.JAVA_DISTRIBUTION }}
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
- name: Configure Git user
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Branch that release
run: git switch -c release/${{ env.RELEASE_VERSION }}
- name: Dry run a release with maven
run: |
mvn -B -V -e -ntp release:prepare -DdryRun -DreleaseVersion=${{ env.RELEASE_VERSION }}
mvn -B -V -e -ntp release:clean
- name: Release that version
run: |
mvn -V -B -e versions:set -DnewVersion=${{ env.RELEASE_VERSION }} -DprocessAllModules -DgenerateBackupPoms=false
mvn -V -B -e versions:set-scm-tag -DnewTag=${{ env.RELEASE_VERSION }} -DgenerateBackupPoms=false
mvn -V -B -e sortpom:sort
git commit -am "[github-actions](${{ github.actor }}) release ${{ env.RELEASE_VERSION }}"
git tag -a ${{ env.RELEASE_VERSION }} -m "${{ env.RELEASE_VERSION }}"
git push origin release/${{ env.RELEASE_VERSION }}
git push origin ${{ env.RELEASE_VERSION }}
- name: Build release artifacts
run: mvn -B -V -e -ntp "-Dstyle.color=always" package
- name: Create Release
id: create_release
uses: actions/create-release@v1
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: ${{ env.RELEASE_VERSION }}
draft: false
prerelease: false
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -Pgithub-publish -DskipTests
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish site to GitHub Pages
run: mvn site site:stage scm-publish:publish-scm -DskipTests
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete branch
continue-on-error: true
if: ${{ github.event.inputs.release_type == 'patch' && startsWith(github.ref_name, 'patch/') }}
run: git push origin :${{ github.ref_name }}
snapshot-bump:
if: ${{ github.event.inputs.release_type == 'release' && github.ref_name == 'main' }}
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: "maven"
- name: Configure Git user
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Get the version and set the name of the branch
run: |
NEXT_DEV_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '\[.*' | awk -F. '{print ""$1"."$2+1"."$3""}')
echo "NEXT_DEV_VERSION=${NEXT_DEV_VERSION}" >> "$GITHUB_ENV"
echo "PR_BRANCH=action/${NEXT_DEV_VERSION}" >> "$GITHUB_ENV"
- name: Create a branch
run: git switch -c ${{ env.PR_BRANCH }}
- name: Set the next snapshot version
run: |
mvn -B -V -e -ntp versions:set -DnewVersion=${{ env.NEXT_DEV_VERSION }} -DgenerateBackupPoms=false
mvn -B -V -e -ntp versions:commit
git add .
git commit -m "[github-actions](${{ github.actor }}) next development iteration ${{ env.NEXT_DEV_VERSION }}"
git push -u origin ${{ env.PR_BRANCH }}
- name: Create pull request
run: gh pr create -B main -H ${{ env.PR_BRANCH }} --title 'next development iteration ${{ env.NEXT_DEV_VERSION }}' --body 'Created by GitHub Action'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
slack-notify-start:
if: ${{ github.repository == 'NationalSecurityAgency/emissary' }}
needs: get_version
runs-on: ubuntu-latest
steps:
- name: Add RELEASE_VERSION to environment variable
run: echo "RELEASE_VERSION=${{ needs.get_version.outputs.RELEASE_VERSION }}" >> "$GITHUB_ENV"
- name: Publish to slack channel via bot token
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"unfurl_links": false,
"unfurl_media": false,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "emissary-release -- Release of version: ${{ env.RELEASE_VERSION }} Started by: ${{ github.actor }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
slack-notify-complete:
if: ${{ github.repository == 'NationalSecurityAgency/emissary' }}
needs: [get_version, release]
runs-on: ubuntu-latest
steps:
- name: Add RELEASE_VERSION to environment variable
run: echo "RELEASE_VERSION=${{ needs.get_version.outputs.RELEASE_VERSION }}" >> "$GITHUB_ENV"
- name: Publish to slack channel via bot token
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"unfurl_links": false,
"unfurl_media": false,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "emissary-release -- Release of version: ${{ env.RELEASE_VERSION }} complete.\nRelease Page: <https://github.com/NationalSecurityAgency/emissary/releases/tag/${{ env.RELEASE_VERSION }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}