4
4
push :
5
5
branches :
6
6
- main
7
- - ' release/**'
7
+ - " release/**"
8
8
tags :
9
9
- " v*"
10
10
11
- # Only run for pull requests if relevant files were changed
11
+ # Run when there is a label change on the pull request
12
+ # This runs only if the 'Z-Build-Workflow' is added to the pull request
12
13
pull_request :
13
- branches :
14
- - main
15
- - ' release/**'
14
+ types : [labeled]
16
15
17
16
concurrency :
18
17
group : ${{ github.workflow }}-${{ github.ref }}
31
30
jobs :
32
31
compute-version :
33
32
name : Compute version using git describe
33
+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
34
34
runs-on : ubuntu-24.04
35
+
36
+ permissions :
37
+ contents : read
38
+
35
39
outputs :
36
40
describe : ${{ steps.git.outputs.describe }}
37
41
timestamp : ${{ steps.git.outputs.timestamp }}
42
+
38
43
steps :
39
44
- name : Checkout the code
40
45
50
55
51
56
build-assets :
52
57
name : Build assets
58
+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
53
59
runs-on : ubuntu-24.04
54
60
55
61
permissions :
81
87
82
88
build-binaries :
83
89
name : Build binaries
90
+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
84
91
runs-on : ubuntu-24.04
85
92
86
93
needs :
@@ -139,6 +146,7 @@ jobs:
139
146
140
147
assemble-archives :
141
148
name : Assemble release archives
149
+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
142
150
runs-on : ubuntu-24.04
143
151
144
152
needs :
@@ -193,6 +201,7 @@ jobs:
193
201
194
202
build-image :
195
203
name : Build and push Docker image
204
+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
196
205
runs-on : ubuntu-24.04
197
206
198
207
outputs :
@@ -221,6 +230,7 @@ jobs:
221
230
latest=auto
222
231
tags : |
223
232
type=ref,event=branch
233
+ type=ref,event=pr
224
234
type=semver,pattern={{version}}
225
235
type=semver,pattern={{major}}.{{minor}}
226
236
type=semver,pattern={{major}}
@@ -237,6 +247,7 @@ jobs:
237
247
suffix=-debug,onlatest=true
238
248
tags : |
239
249
type=ref,event=branch
250
+ type=ref,event=pr
240
251
type=semver,pattern={{version}}
241
252
type=semver,pattern={{major}}.{{minor}}
242
253
type=semver,pattern={{major}}
@@ -252,6 +263,7 @@ jobs:
252
263
latest=auto
253
264
tags : |
254
265
type=ref,event=branch
266
+ type=ref,event=pr
255
267
type=semver,pattern={{version}}
256
268
type=semver,pattern={{major}}.{{minor}}
257
269
type=semver,pattern={{major}}
@@ -268,31 +280,15 @@ jobs:
268
280
mirrors = ["mirror.gcr.io"]
269
281
270
282
- name : Login to GitHub Container Registry
271
- if : github.event_name != 'pull_request'
272
283
273
284
with :
274
285
registry : ghcr.io
275
286
username : ${{ github.repository_owner }}
276
287
password : ${{ secrets.GITHUB_TOKEN }}
277
288
278
- # For pull-requests, only read from the cache, do not try to push to the
279
- # cache or the image itself
280
- - name : Build
281
-
282
- if : github.event_name == 'pull_request'
283
- with :
284
- files : |
285
- ./docker-bake.hcl
286
- cwd://${{ steps.meta.outputs.bake-file }}
287
- cwd://${{ steps.meta-debug.outputs.bake-file }}
288
- cwd://${{ steps.meta-syn2mas.outputs.bake-file }}
289
- set : |
290
- base.cache-from=type=registry,ref=${{ env.BUILDCACHE }}:buildcache
291
-
292
289
- name : Build and push
293
290
id : bake
294
291
295
- if : github.event_name != 'pull_request'
296
292
with :
297
293
files : |
298
294
./docker-bake.hcl
@@ -308,7 +304,6 @@ jobs:
308
304
# This transforms the ouput to an object which looks like this:
309
305
# { reguar: { digest: "…", tags: ["…", "…"] }, debug: { digest: "…", tags: ["…"] }, … }
310
306
id : output
311
- if : github.event_name != 'pull_request'
312
307
run : |
313
308
echo 'metadata<<EOF' >> $GITHUB_OUTPUT
314
309
echo '${{ steps.bake.outputs.metadata }}' | jq -c 'with_entries(select(.value | (type == "object" and has("containerimage.digest")))) | map_values({ digest: .["containerimage.digest"], tags: (.["image.name"] | split(",")) })' >> $GITHUB_OUTPUT
@@ -334,13 +329,12 @@ jobs:
334
329
syn2mas :
335
330
name : Release syn2mas on NPM
336
331
runs-on : ubuntu-24.04
332
+ if : github.event_name != 'pull_request'
337
333
338
334
permissions :
339
335
contents : read
340
336
id-token : write
341
337
342
- if : github.event_name != 'pull_request'
343
-
344
338
steps :
345
339
- name : Checkout the code
346
340
@@ -428,14 +422,16 @@ jobs:
428
422
429
423
unstable :
430
424
name : Update the unstable release
425
+ if : github.ref == 'refs/heads/main'
431
426
runs-on : ubuntu-24.04
427
+
432
428
needs :
433
429
- assemble-archives
434
430
- build-image
435
- if : github.ref == 'refs/heads/main'
436
431
437
432
permissions :
438
433
contents : write
434
+
439
435
steps :
440
436
- name : Checkout the code
441
437
@@ -460,7 +456,7 @@ jobs:
460
456
- name : Update unstable release
461
457
uses : softprops/action-gh-release@v2
462
458
with :
463
- name : ' Unstable build'
459
+ name : " Unstable build"
464
460
tag_name : unstable
465
461
body : |
466
462
This is an automatically updated unstable release containing the latest builds from the main branch.
@@ -501,3 +497,31 @@ jobs:
501
497
artifacts/mas-cli-x86_64-linux.tar.gz
502
498
prerelease : true
503
499
make_latest : false
500
+
501
+ pr-cleanup :
502
+ name : " Remove workflow build PR label and comment on it"
503
+ runs-on : ubuntu-24.04
504
+ if : github.event_name == 'pull_request' && github.event.label.name == 'Z-Build-Workflow'
505
+
506
+ needs :
507
+ - build-image
508
+
509
+ permissions :
510
+ contents : read
511
+ pull-requests : write
512
+
513
+ steps :
514
+ - name : Checkout the code
515
+
516
+ with :
517
+ sparse-checkout : |
518
+ .github/scripts
519
+
520
+ - name : Remove label and comment
521
+
522
+ env :
523
+ BUILD_IMAGE_MANIFEST : ${{ needs.build-image.outputs.metadata }}
524
+ with :
525
+ script : |
526
+ const script = require('./.github/scripts/cleanup-pr.cjs');
527
+ await script({ core, github, context });
0 commit comments