|
| 1 | +# Copyright © 2026 OpenCHAMI a Series of LF Projects, LLC |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +name: Build each PR for testing and validation |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + types: [opened, synchronize, reopened, edited] |
| 12 | + workflow_dispatch: |
| 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 |
| 20 | + |
| 21 | +jobs: |
| 22 | + |
| 23 | + build: |
| 24 | + |
| 25 | + |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Set up latest stable Go |
| 30 | + uses: actions/setup-go@v6.4.0 |
| 31 | + with: |
| 32 | + go-version: stable |
| 33 | + - name: Set up QEMU |
| 34 | + uses: docker/setup-qemu-action@v3 |
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v3 |
| 37 | + with: |
| 38 | + driver-opts: | |
| 39 | + image=moby/buildkit:master |
| 40 | + network=host |
| 41 | + - name: Docker Login |
| 42 | + uses: docker/login-action@v3 |
| 43 | + with: |
| 44 | + registry: ghcr.io |
| 45 | + username: ${{ github.actor }} |
| 46 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v6.0.2 |
| 49 | + with: |
| 50 | + fetch-tags: 1 |
| 51 | + fetch-depth: 0 |
| 52 | + # Set environment variables required by GoReleaser |
| 53 | + - name: Set build environment variables |
| 54 | + run: | |
| 55 | + echo "GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" >> $GITHUB_ENV |
| 56 | + echo "BUILD_HOST=$(hostname)" >> $GITHUB_ENV |
| 57 | + echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV |
| 58 | + echo "BUILD_USER=$(whoami)" >> $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@v3 |
| 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" |
| 79 | +
|
| 80 | + - name: Build/Push container with goreleaser |
| 81 | + uses: goreleaser/goreleaser-action@v6 |
| 82 | + env: |
| 83 | + GITHUB_TOKEN: ${{ github.token }} |
| 84 | + with: |
| 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 |
| 98 | + - name: Attest Binaries |
| 99 | + uses: actions/attest-build-provenance@v4.1.0 |
| 100 | + with: |
| 101 | + subject-path: dist/**/fru-tracker* |
| 102 | + - name: generate build provenance |
| 103 | + uses: actions/attest-build-provenance@v4.1.0 |
| 104 | + with: |
| 105 | + subject-name: ghcr.io/openchami/fru-tracker |
| 106 | + subject-digest: ${{ steps.process_goreleaser_output.outputs.digest }} |
| 107 | + push-to-registry: true |
0 commit comments