-
Notifications
You must be signed in to change notification settings - Fork 1
296 lines (266 loc) · 11.3 KB
/
reusable-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
name: Reusable Automated Maven Release workflow
on:
workflow_call:
secrets:
AUTOMATED_MAVEN_RELEASE_PGP_SECRET:
required: true
AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD:
required: true
# Determine Release Version (project code)
# Create Release Commit (release-workflow-code as GitHub App) - includes GitHub Actor in commit message
# * https://github.com/orgs/community/discussions/50055
# ... wait on standard tests to run?!
# Create artifacts (project code)
# Sign artifacts (release-workflow-code as GitHub App)
# * Create Release Tag, with artifact hashes in tag message
# * Create post-Release Commit with post-release version
# Release artifacts to Maven (release-workflow-code as GitHub App)
# Create GitHub Release (release-workflow-code as GitHub App)
env:
LOCAL_ARTIFACTS_STAGING_PATH: /tmp/artifact_staging
jobs:
identifiers-for-signing-key:
name: 🔒 Read Signing Key Id
runs-on: ubuntu-latest
outputs:
key_fingerprint: ${{ steps.read-identifiers.outputs.key_fingerprint }}
key_email: ${{ steps.read-identifiers.outputs.key_email }}
steps:
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17
gpg-private-key: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
- name: Read Identifiers from Signing Key
id: read-identifiers
run: |
key_fingerprint_and_email=$(gpg2 --list-secret-keys --list-options show-only-fpr-mbox)
key_fingerprint=$(echo $key_fingerprint_and_email | awk '{print $1}')
key_email=$(echo $key_fingerprint_and_email | awk '{print $2}')
echo "key_fingerprint=$key_fingerprint"
cat << EndOfFile >> $GITHUB_OUTPUT
key_fingerprint=$key_fingerprint
key_email=$key_email
EndOfFile
generate-version-update-commits:
name: 🎊 Test & Version
needs: identifiers-for-signing-key
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4 # don't 'cache: sbt', at least until https://github.com/actions/setup-java/pull/564 is merged
with:
distribution: corretto
java-version: 17
- name: Use sbt-release to construct version.sbt updates
env:
KEY_EMAIL: ${{ needs.identifiers-for-signing-key.outputs.key_email }}
run: |
git config user.email "$KEY_EMAIL"
git config user.name "@$GITHUB_ACTOR using Guardian Automated Maven Release"
sbt "release with-defaults"
echo $GITHUB_WORKSPACE
cd `mktemp -d`
git clone --bare $GITHUB_WORKSPACE repo-with-unsigned-version-update-commits.git
rm -Rf $GITHUB_WORKSPACE/*
mv repo-with-unsigned-version-update-commits.git $GITHUB_WORKSPACE/
ls -lR $GITHUB_WORKSPACE
- name: Job summary
run: |
echo "# Release $(git describe --tags --abbrev=0)" >> $GITHUB_STEP_SUMMARY
- uses: actions/cache/save@v3
with:
path: repo-with-unsigned-version-update-commits.git
key: repo-with-unsigned-version-update-commits-${{ github.run_id }}-${{ github.run_attempt }}
push-release-commit:
name: 🔒 Push Release Commit
needs: [generate-version-update-commits, identifiers-for-signing-key]
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.create-commit.outputs.release_tag }}
release_commit_id: ${{ steps.create-commit.outputs.release_commit_id }}
steps:
- uses: actions/checkout@v4
with:
path: repo
- uses: actions/cache/restore@v3
with:
path: repo-with-unsigned-version-update-commits.git
key: repo-with-unsigned-version-update-commits-${{ github.run_id }}-${{ github.run_attempt }}
fail-on-cache-miss: true
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17
gpg-private-key: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
- name: Create commit
id: create-commit
env:
KEY_FINGERPRINT: ${{ needs.identifiers-for-signing-key.outputs.key_fingerprint }}
KEY_EMAIL: ${{ needs.identifiers-for-signing-key.outputs.key_email }}
run: |
echo "GITHUB_REF_NAME=$GITHUB_REF_NAME"
echo "GITHUB_REF=$GITHUB_REF"
cd repo-with-unsigned-version-update-commits.git
release_tag=$(git describe --tags --abbrev=0)
cd ../repo
git status
git config user.email "$KEY_EMAIL"
git config user.name "@$GITHUB_ACTOR using Guardian Automated Maven Release"
git config commit.gpgsign true
git config user.signingkey "$KEY_FINGERPRINT"
git remote add unsigned ../repo-with-unsigned-version-update-commits.git
git fetch unsigned
git cherry-pick -S$KEY_FINGERPRINT $GITHUB_REF_NAME..unsigned/$GITHUB_REF_NAME
git status
release_commit_id=$(git rev-parse HEAD^)
cat << EndOfFile >> $GITHUB_OUTPUT
release_tag=$release_tag
release_commit_id=$release_commit_id
EndOfFile
git log --format="%h %p %ce %s" --decorate=short -n3
git status
git push
create-artifacts:
name: 🎊 Create artifacts
needs: [identifiers-for-signing-key, push-release-commit]
runs-on: ubuntu-latest
outputs:
ARTIFACT_SHA256SUMS: ${{ steps.record-hashes.outputs.ARTIFACT_SHA256SUMS }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.push-release-commit.outputs.release_commit_id }}
- uses: actions/setup-java@v4 # don't 'cache: sbt', at least until https://github.com/actions/setup-java/pull/564 is resolved
with:
distribution: corretto
java-version: 17
- name: Generate artifacts
run: |
cat << EndOfFile > sbt-commands.txt
set every sonatypeProjectHosting := Some(xerial.sbt.Sonatype.GitHubHosting("$GITHUB_REPOSITORY_OWNER", "${GITHUB_REPOSITORY#*/}", "${{ needs.identifiers-for-signing-key.outputs.key_email }}"))
set ThisBuild / publishTo := Some(Resolver.file("foobar", file("$LOCAL_ARTIFACTS_STAGING_PATH")))
EndOfFile
cat sbt-commands.txt
sbt ";< sbt-commands.txt; +publish"
- name: Record SHA-256 hashes of artifacts
id: record-hashes
run: |
sudo apt-get install hashdeep -q > /dev/null
cd $LOCAL_ARTIFACTS_STAGING_PATH
{
echo 'ARTIFACT_SHA256SUMS<<EOF'
sha256deep -r -l .
echo EOF
} >> "$GITHUB_OUTPUT"
- uses: actions/cache/save@v3
id: cache
with:
path: ${{ env.LOCAL_ARTIFACTS_STAGING_PATH }}
key: unsigned-${{ github.run_id }}-${{ github.run_attempt }}
sign:
name: 🔒 Sign
needs: [identifiers-for-signing-key, push-release-commit, create-artifacts]
runs-on: ubuntu-latest
env:
KEY_FINGERPRINT: ${{ needs.identifiers-for-signing-key.outputs.key_fingerprint }}
steps:
- uses: actions/checkout@v4
with:
path: repo
ref: ${{ needs.push-release-commit.outputs.release_commit_id }}
- uses: actions/cache/restore@v3
with:
path: ${{ env.LOCAL_ARTIFACTS_STAGING_PATH }}
key: unsigned-${{ github.run_id }}-${{ github.run_attempt }}
fail-on-cache-miss: true
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17
gpg-private-key: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
- name: Sign artifacts
run: |
echo "KEY_FINGERPRINT=$KEY_FINGERPRINT"
find $LOCAL_ARTIFACTS_STAGING_PATH -type f -exec gpg -a --local-user "$KEY_FINGERPRINT" --detach-sign {} \;
- name: Push signed tag
env:
RELEASE_TAG: ${{ needs.push-release-commit.outputs.release_tag }}
RELEASE_COMMIT_ID: ${{ needs.push-release-commit.outputs.release_commit_id }}
ARTIFACT_SHA256SUMS: ${{ needs.create-artifacts.outputs.ARTIFACT_SHA256SUMS }}
KEY_EMAIL: ${{ needs.identifiers-for-signing-key.outputs.key_email }}
run: |
echo "RELEASE_TAG=$RELEASE_TAG"
echo "RELEASE_COMMIT_ID=$RELEASE_COMMIT_ID"
cd repo
git config user.email "$KEY_EMAIL"
git config user.name "@$GITHUB_ACTOR using Automated Maven Release"
git config tag.gpgSign true
git config user.signingkey "$KEY_FINGERPRINT"
cat << EndOfFile > tag-message.txt
Release $RELEASE_TAG initiated by @$GITHUB_ACTOR using Automated Maven Release
$ARTIFACT_SHA256SUMS
EndOfFile
echo "Message is..."
cat tag-message.txt
echo "Creating tag"
git tag -a -F tag-message.txt $RELEASE_TAG $RELEASE_COMMIT_ID
echo "RELEASE_TAG=$RELEASE_TAG"
git show $RELEASE_TAG
echo "Pushing tag $RELEASE_TAG"
git push origin $RELEASE_TAG
- uses: actions/cache/save@v3
with:
path: ${{ env.LOCAL_ARTIFACTS_STAGING_PATH }}
key: signed-${{ github.run_id }}-${{ github.run_attempt }}
sonatype-release:
name: 🔒 Sonatype Release
needs: sign
runs-on: ubuntu-latest
steps:
- uses: actions/cache/restore@v3
with:
path: ${{ env.LOCAL_ARTIFACTS_STAGING_PATH }}
key: signed-${{ github.run_id }}-${{ github.run_attempt }}
fail-on-cache-miss: true
- name: Create tiny sbt project to perform Sonatype upload
run: |
cat << EndOfFile > build.sbt
sonatypeBundleDirectory := new File("$LOCAL_ARTIFACTS_STAGING_PATH")
sonatypeProfileName := "com.gu"
EndOfFile
mkdir project
echo 'addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")' > project/plugins.sbt
echo 'sbt.version = 1.9.7' > project/build.properties
ls -lR .
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17
cache: sbt # the issue described in https://github.com/actions/setup-java/pull/564 doesn't affect this step (no version.sbt)
- name: Release
env:
SONATYPE_USERNAME: guardian.automated.maven.release
SONATYPE_PASSWORD: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD }}
run: |
sbt "sonatypeBundleRelease"
github-release:
name: 🔒 GitHub Release
needs: [push-release-commit, sign]
runs-on: ubuntu-latest
permissions:
contents: write
env:
RELEASE_TAG: ${{ needs.push-release-commit.outputs.release_tag }}
steps:
- name: Create Github Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
gh release create $RELEASE_TAG --verify-tag --generate-notes --notes "Release run: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
- name: Job summary
run: |
echo "GitHub Release notes: [$RELEASE_TAG](${{ github.server_url }}/${{ github.repository }}/releases/tag/$RELEASE_TAG)" >> $GITHUB_STEP_SUMMARY