1- name : Build PR with goreleaser
1+ # Copyright © 2025 OpenCHAMI a Series of LF Projects, LLC
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ name : Build each PR for testing and validation
26
37on :
48 pull_request :
59 branches :
610 - main
711 types : [opened, synchronize, reopened, edited]
812 workflow_dispatch :
9-
13+ inputs :
14+ pr_number :
15+ description : ' PR Number to build (optional, for manual PR builds)'
16+ required : false
17+ type : string
18+
19+ permissions : write-all # Necessary for the generate-build-provenance action with containers
1020
1121jobs :
12- prbuild :
22+
23+ build :
24+
25+
1326 runs-on : ubuntu-latest
14- steps :
15- - name : Install cross-compilation tools
16- run : |
17- sudo apt-get update
18- sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
1927
28+ steps :
2029 - name : Set up latest stable Go
21- uses : actions/setup-go@v5
30+ uses : actions/setup-go@v6.4.0
2231 with :
2332 go-version : stable
2433 - name : Set up QEMU
25- uses : docker/setup-qemu-action@v3
26-
34+ uses : docker/setup-qemu-action@v4
35+ - name : Set up Docker Buildx
36+ uses : docker/setup-buildx-action@v4
37+ with :
38+ driver-opts : |
39+ image=moby/buildkit:master
40+ network=host
41+ - name : Docker Login
42+ uses : docker/login-action@v4.1.0
43+ with :
44+ registry : ghcr.io
45+ username : ${{ github.actor }}
46+ password : ${{ secrets.GITHUB_TOKEN }}
2747 - name : Checkout
28- uses : actions/checkout@v4
48+ uses : actions/checkout@v6.0.2
2949 with :
3050 fetch-tags : 1
31- fetch-depth : 1
32-
51+ fetch-depth : 0
3352 # Set environment variables required by GoReleaser
3453 - name : Set build environment variables
3554 run : |
3655 echo "GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" >> $GITHUB_ENV
3756 echo "BUILD_HOST=$(hostname)" >> $GITHUB_ENV
3857 echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV
3958 echo "BUILD_USER=$(whoami)" >> $GITHUB_ENV
40- echo "CGO_ENABLED=1" >> $GITHUB_ENV
59+ echo "CGO_ENABLED=0" >> $GITHUB_ENV
60+ echo "IS_PR_BUILD=true" >> $GITHUB_ENV
61+
62+ - name : Docker Login
63+ uses : docker/login-action@v4.1.0
64+ with :
65+ registry : ghcr.io
66+ username : ${{ github.actor }}
67+ password : ${{ secrets.GITHUB_TOKEN }}
68+
69+ - name : Create Tag for PR
70+ if : github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.pr_number != '')
71+ run : |
72+ git config --global user.name "github-actions[bot]"
73+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
74+ PR_NUM="${{ github.event.number }}"
75+ if [[ "${{ inputs.pr_number }}" != "" ]]; then
76+ PR_NUM="${{ inputs.pr_number }}"
77+ fi
78+ git tag -f -a pr-${PR_NUM} -m "PR Release"
4179
42- - name : Build with goreleaser
43- uses : goreleaser/goreleaser-action@v6
80+ - name : Build/Push container with goreleaser
81+ uses : goreleaser/goreleaser-action@v7
4482 env :
4583 GITHUB_TOKEN : ${{ github.token }}
4684 with :
47- version : ' ~> v2'
48- args : build --clean --snapshot
49- id : goreleaser
85+ version : ' ~> 2'
86+ args : release --clean --skip=announce,validate,archive
87+ id : goreleaser
88+ - name : Process goreleaser output
89+ id : process_goreleaser_output
90+ run : |
91+ echo "const fs = require('fs');" > process.js
92+ echo 'const artifacts = ${{ steps.goreleaser.outputs.artifacts }}' >> process.js
93+ echo "const firstNonNullDigest = artifacts.find(artifact => artifact.extra && artifact.extra.Digest != null)?.extra.Digest;" >> process.js
94+ echo "console.log(firstNonNullDigest);" >> process.js
95+ echo "fs.writeFileSync('digest.txt', firstNonNullDigest);" >> process.js
96+ node process.js
97+ echo "digest=$(cat digest.txt)" >> $GITHUB_OUTPUT
0 commit comments