44 push :
55 branches :
66 - main
7- - ' release/**'
7+ - " release/**"
88 tags :
99 - " v*"
1010
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
1213 pull_request :
13- branches :
14- - main
15- - ' release/**'
14+ types : [labeled]
1615
1716concurrency :
1817 group : ${{ github.workflow }}-${{ github.ref }}
3130jobs :
3231 compute-version :
3332 name : Compute version using git describe
33+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
3434 runs-on : ubuntu-24.04
35+
36+ permissions :
37+ contents : read
38+
3539 outputs :
3640 describe : ${{ steps.git.outputs.describe }}
3741 timestamp : ${{ steps.git.outputs.timestamp }}
42+
3843 steps :
3944 - name : Checkout the code
40455055
5156 build-assets :
5257 name : Build assets
58+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
5359 runs-on : ubuntu-24.04
5460
5561 permissions :
8187
8288 build-binaries :
8389 name : Build binaries
90+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
8491 runs-on : ubuntu-24.04
8592
8693 needs :
@@ -139,6 +146,7 @@ jobs:
139146
140147 assemble-archives :
141148 name : Assemble release archives
149+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
142150 runs-on : ubuntu-24.04
143151
144152 needs :
@@ -193,6 +201,7 @@ jobs:
193201
194202 build-image :
195203 name : Build and push Docker image
204+ if : github.event_name == 'push' || github.event.label.name == 'Z-Build-Workflow'
196205 runs-on : ubuntu-24.04
197206
198207 outputs :
@@ -221,6 +230,7 @@ jobs:
221230 latest=auto
222231 tags : |
223232 type=ref,event=branch
233+ type=ref,event=pr
224234 type=semver,pattern={{version}}
225235 type=semver,pattern={{major}}.{{minor}}
226236 type=semver,pattern={{major}}
@@ -237,6 +247,7 @@ jobs:
237247 suffix=-debug,onlatest=true
238248 tags : |
239249 type=ref,event=branch
250+ type=ref,event=pr
240251 type=semver,pattern={{version}}
241252 type=semver,pattern={{major}}.{{minor}}
242253 type=semver,pattern={{major}}
@@ -252,6 +263,7 @@ jobs:
252263 latest=auto
253264 tags : |
254265 type=ref,event=branch
266+ type=ref,event=pr
255267 type=semver,pattern={{version}}
256268 type=semver,pattern={{major}}.{{minor}}
257269 type=semver,pattern={{major}}
@@ -268,31 +280,15 @@ jobs:
268280 mirrors = ["mirror.gcr.io"]
269281
270282 - name : Login to GitHub Container Registry
271- if : github.event_name != 'pull_request'
272283273284 with :
274285 registry : ghcr.io
275286 username : ${{ github.repository_owner }}
276287 password : ${{ secrets.GITHUB_TOKEN }}
277288
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-
292289 - name : Build and push
293290 id : bake
294291295- if : github.event_name != 'pull_request'
296292 with :
297293 files : |
298294 ./docker-bake.hcl
@@ -308,7 +304,6 @@ jobs:
308304 # This transforms the ouput to an object which looks like this:
309305 # { reguar: { digest: "…", tags: ["…", "…"] }, debug: { digest: "…", tags: ["…"] }, … }
310306 id : output
311- if : github.event_name != 'pull_request'
312307 run : |
313308 echo 'metadata<<EOF' >> $GITHUB_OUTPUT
314309 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:
334329 syn2mas :
335330 name : Release syn2mas on NPM
336331 runs-on : ubuntu-24.04
332+ if : github.event_name != 'pull_request'
337333
338334 permissions :
339335 contents : read
340336 id-token : write
341337
342- if : github.event_name != 'pull_request'
343-
344338 steps :
345339 - name : Checkout the code
346340@@ -428,14 +422,16 @@ jobs:
428422
429423 unstable :
430424 name : Update the unstable release
425+ if : github.ref == 'refs/heads/main'
431426 runs-on : ubuntu-24.04
427+
432428 needs :
433429 - assemble-archives
434430 - build-image
435- if : github.ref == 'refs/heads/main'
436431
437432 permissions :
438433 contents : write
434+
439435 steps :
440436 - name : Checkout the code
441437@@ -460,7 +456,7 @@ jobs:
460456 - name : Update unstable release
461457 uses : softprops/action-gh-release@v2
462458 with :
463- name : ' Unstable build'
459+ name : " Unstable build"
464460 tag_name : unstable
465461 body : |
466462 This is an automatically updated unstable release containing the latest builds from the main branch.
@@ -501,3 +497,31 @@ jobs:
501497 artifacts/mas-cli-x86_64-linux.tar.gz
502498 prerelease : true
503499 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