-
Notifications
You must be signed in to change notification settings - Fork 71
407 lines (354 loc) · 13.3 KB
/
release.yml
File metadata and controls
407 lines (354 loc) · 13.3 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
name: Draft Release
on:
push:
tags:
- "v*"
permissions:
contents: write
packages: write
id-token: write
jobs:
# Builds the x64 and arm64 binary for Linux via the Docker builder
build-binaries-linux:
strategy:
matrix:
target:
- amd64
- arm64
name:
- commit-boost
include:
- target: amd64
package-suffix: x86-64
- target: arm64
package-suffix: arm64
- name: commit-boost
target-crate: commit-boost
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Log commit hash
run: |
echo "Releasing commit: $(git rev-parse HEAD)"
- name: Set lowercase owner
run: echo "OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build binary (Linux)
uses: docker/build-push-action@v6
with:
context: .
push: false
platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=ghcr.io/${{ env.OWNER }}/buildcache:${{ matrix.target-crate}}
cache-to: type=registry,ref=ghcr.io/${{ env.OWNER }}/buildcache:${{ matrix.target-crate }},mode=max
file: provisioning/build.Dockerfile
outputs: type=local,dest=build
build-args: |
TARGET_CRATE=${{ matrix.name }}
- name: Package binary (Linux)
run: |
cd build/linux_${{ matrix.target }}
tar -czvf ${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}.tar.gz ${{ matrix.name }}
mv ${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}.tar.gz ../../
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}
path: |
${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}.tar.gz
# Builds the arm64 binary for Darwin natively
build-binaries-darwin:
strategy:
matrix:
target:
# x64 requires macos-latest-large which is not available in the free tier
# - x86_64-apple-darwin
- aarch64-apple-darwin
name:
- commit-boost
include:
# - target: x86_64-apple-darwin
# os: macos-latest-large
# package-suffix: x86-64
- target: aarch64-apple-darwin
os: macos-latest
package-suffix: arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Log commit hash
run: |
echo "Releasing commit: $(git rev-parse HEAD)"
- name: Install Protoc
run:
# Brew's version is much more up to date than the Linux ones, and installing the latest via script runs into curl issues so for now, brew's easier to use
# provisioning/protoc.sh
brew install protobuf
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ matrix.target }}-${{ matrix.name }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-${{ matrix.target }}-${{ matrix.name }}-
${{ runner.os }}-cargo-build-${{ matrix.target }}-
${{ runner.os }}-cargo-build-
- name: Build binary (Darwin)
run: cargo build --release --target ${{ matrix.target }} --bin ${{ matrix.name }}
- name: Package binary (Darwin)
run: |
cd target/${{ matrix.target }}/release
tar -czvf ${{ matrix.name }}-${{ github.ref_name }}-darwin_${{ matrix.package-suffix }}.tar.gz ${{ matrix.name }}
mv ${{ matrix.name }}-${{ github.ref_name }}-darwin_${{ matrix.package-suffix }}.tar.gz ../../../
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}-${{ github.ref_name }}-darwin_${{ matrix.package-suffix }}
path: |
${{ matrix.name }}-${{ github.ref_name }}-darwin_${{ matrix.package-suffix }}.tar.gz
# Signs the binaries
sign-binaries:
needs:
- build-binaries-linux
- build-binaries-darwin
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
pattern: "commit-boost*"
- name: Sign binaries
uses: sigstore/gh-action-sigstore-python@a5caf349bc536fbef3668a10ed7f5cd309a4b53d #v3.2.0
with:
inputs: ./artifacts/**/*.tar.gz
- name: Upload signatures
uses: actions/upload-artifact@v4
with:
name: signatures-${{ github.ref_name }}
path: |
./artifacts/**/*.sigstore.json
# Builds the PBS Docker image
build-and-push-pbs-docker:
needs: [build-binaries-linux]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Download binary archives
uses: actions/download-artifact@v4
with:
path: ./artifacts
pattern: "commit-boost*"
- name: Extract binaries
run: |
mkdir -p ./artifacts/bin/linux_amd64
mkdir -p ./artifacts/bin/linux_arm64
tar -xzf ./artifacts/commit-boost-${{ github.ref_name }}-linux_x86-64/commit-boost-${{ github.ref_name }}-linux_x86-64.tar.gz -C ./artifacts/bin
mv ./artifacts/bin/commit-boost ./artifacts/bin/linux_amd64/commit-boost
tar -xzf ./artifacts/commit-boost-${{ github.ref_name }}-linux_arm64/commit-boost-${{ github.ref_name }}-linux_arm64.tar.gz -C ./artifacts/bin
mv ./artifacts/bin/commit-boost ./artifacts/bin/linux_arm64/commit-boost
- name: Set lowercase owner
run: echo "OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push PBS Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
BINARIES_PATH=./artifacts/bin
tags: |
ghcr.io/${{ env.OWNER }}/pbs:${{ github.ref_name }}
${{ !contains(github.ref_name, 'rc') && format('ghcr.io/{0}/pbs:latest', env.OWNER) || '' }}
file: provisioning/pbs.Dockerfile
# Builds the Signer Docker image
build-and-push-signer-docker:
needs: [build-binaries-linux]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Download binary archives
uses: actions/download-artifact@v4
with:
path: ./artifacts
pattern: "commit-boost*"
- name: Extract binaries
run: |
mkdir -p ./artifacts/bin/linux_amd64
mkdir -p ./artifacts/bin/linux_arm64
tar -xzf ./artifacts/commit-boost-${{ github.ref_name }}-linux_x86-64/commit-boost-${{ github.ref_name }}-linux_x86-64.tar.gz -C ./artifacts/bin
mv ./artifacts/bin/commit-boost ./artifacts/bin/linux_amd64/commit-boost
tar -xzf ./artifacts/commit-boost-${{ github.ref_name }}-linux_arm64/commit-boost-${{ github.ref_name }}-linux_arm64.tar.gz -C ./artifacts/bin
mv ./artifacts/bin/commit-boost ./artifacts/bin/linux_arm64/commit-boost
- name: Set lowercase owner
run: echo "OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Signer Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
BINARIES_PATH=./artifacts/bin
tags: |
ghcr.io/${{ env.OWNER }}/signer:${{ github.ref_name }}
${{ !contains(github.ref_name, 'rc') && format('ghcr.io/{0}/signer:latest', env.OWNER) || '' }}
file: provisioning/signer.Dockerfile
# Creates a release on GitHub with the binaries
finalize-release:
needs:
- build-binaries-linux
- build-binaries-darwin
- sign-binaries
- build-and-push-pbs-docker
- build-and-push-signer-docker
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Download binaries
uses: actions/download-artifact@v4
with:
path: ./artifacts
pattern: "commit-boost*"
- name: Download signatures
uses: actions/download-artifact@v4
with:
path: ./artifacts
pattern: "signatures-${{ github.ref_name }}*"
- name: Finalize Release
uses: softprops/action-gh-release@v2
with:
files: ./artifacts/**/*
draft: false
prerelease: ${{ contains(github.ref_name, '-rc') }}
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
# Fast-forwards stable (full release) or beta (RC) to the new tag.
# Runs after all artifacts are built and the draft release is created,
# so stable/beta are never touched if any part of the pipeline fails.
fast-forward-branch:
needs:
- finalize-release
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure git
run: |
git config user.name "commit-boost-release-bot[bot]"
git config user.email "commit-boost-release-bot[bot]@users.noreply.github.com"
- name: Fast-forward beta branch (RC releases)
if: contains(github.ref_name, '-rc')
run: |
git checkout beta
git merge --ff-only "${{ github.ref_name }}"
git push origin beta
- name: Fast-forward stable branch (full releases)
if: "!contains(github.ref_name, '-rc')"
run: |
git checkout stable
git merge --ff-only "${{ github.ref_name }}"
git push origin stable
# Deletes the tag if any job in the release pipeline fails.
# This keeps the tag and release artifacts in sync — a tag should only
# exist if the full pipeline completed successfully.
# stable/beta are never touched on failure since fast-forward-branch
# only runs after finalize-release succeeds.
#
# Note: if finalize-release specifically fails, a draft release may already
# exist on GitHub pointing at the now-deleted tag and will need manual cleanup.
cleanup-on-failure:
needs:
- build-binaries-linux
- build-binaries-darwin
- sign-binaries
- build-and-push-pbs-docker
- build-and-push-signer-docker
- finalize-release
- fast-forward-branch
runs-on: ubuntu-latest
if: failure()
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Delete tag
run: git push origin --delete ${{ github.ref_name }}