| 1 |
name: Build Release |
| 2 |
|
| 3 |
on: |
| 4 |
workflow_call: |
| 5 |
inputs: |
| 6 |
ENVIRONMENT: |
| 7 |
description: "GitHub environment for secrets access" |
| 8 |
required: true |
| 9 |
type: string |
| 10 |
BUILD_TYPE: |
| 11 |
description: "Type of release build (stable or nightly)" |
| 12 |
required: true |
| 13 |
type: string |
| 14 |
DRY_RUN: |
| 15 |
description: "Run in test mode without publishing artifacts" |
| 16 |
required: false |
| 17 |
default: false |
| 18 |
type: boolean |
| 19 |
secrets: |
| 20 |
DOCKERHUB_USERNAME: |
| 21 |
required: true |
| 22 |
DOCKERHUB_TOKEN: |
| 23 |
required: true |
| 24 |
|
| 25 |
permissions: |
| 26 |
contents: read # Declare default permissions as read only. |
| 27 |
|
| 28 |
jobs: |
| 29 |
build: |
| 30 |
name: Build |
| 31 |
runs-on: ubuntu-latest |
| 32 |
environment: ${{ inputs.ENVIRONMENT }} |
| 33 |
env: |
| 34 |
DOCKER_CLI_EXPERIMENTAL: "enabled" |
| 35 |
CGO_ENABLED: 0 |
| 36 |
TAG: ${{ github.ref_name }} |
| 37 |
permissions: |
| 38 |
contents: write # For code checkout and publishing releases |
| 39 |
packages: write # For pushing images to registries |
| 40 |
attestations: write # For generating provenance and SBOMs |
| 41 |
id-token: write # For OIDC auth to Docker Hub and GHCR |
| 42 |
|
| 43 |
steps: |
| 44 |
- name: Harden the Runner (Step Security) |
| 45 |
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 |
| 46 |
with: |
| 47 |
egress-policy: audit |
| 48 |
|
| 49 |
- name: Validate BUILD_TYPE input |
| 50 |
env: |
| 51 |
BUILD_TYPE: ${{ inputs.BUILD_TYPE }} |
| 52 |
run: | |
| 53 |
if [[ "${BUILD_TYPE}" != "stable" && "${BUILD_TYPE}" != "nightly" ]]; then |
| 54 |
echo "Error: BUILD_TYPE must be 'stable' or 'nightly', got '${BUILD_TYPE}'" |
| 55 |
exit 1 |
| 56 |
fi |
| 57 |
|
| 58 |
- name: Checkout Repo |
| 59 |
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 60 |
with: |
| 61 |
fetch-depth: 0 |
| 62 |
persist-credentials: false |
| 63 |
|
| 64 |
- name: Setup Go |
| 65 |
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 66 |
with: |
| 67 |
cache: false # Disable to prevent cache poisoning |
| 68 |
go-version-file: go.mod |
| 69 |
|
| 70 |
- name: Setup QEMU |
| 71 |
uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4.3.0 |
| 72 |
with: |
| 73 |
image: tonistiigi/binfmt@sha256:d3b963f787999e6c0219a48dba02978769286ff61a5f4d26245cb6a6e5567ea3 # latest |
| 74 |
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm64/v8,linux/riscv64 |
| 75 |
|
| 76 |
- name: Setup Docker Buildx |
| 77 |
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 |
| 78 |
with: |
| 79 |
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm64/v8,linux/riscv64 |
| 80 |
|
| 81 |
- name: Install Syft for SBOM generation |
| 82 |
uses: anchore/sbom-action/download-syft@3ad7283483fc7af8ff2b4ea19663c2d5ca935e26 # v0.24.2 |
| 83 |
if: ${{ inputs.BUILD_TYPE == 'stable' }} |
| 84 |
|
| 85 |
- name: Install Cosign |
| 86 |
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 |
| 87 |
|
| 88 |
- name: Login to Docker Hub |
| 89 |
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 |
| 90 |
if: ${{ !inputs.DRY_RUN }} |
| 91 |
with: |
| 92 |
username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 93 |
password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 94 |
|
| 95 |
- name: Login to GHCR |
| 96 |
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 |
| 97 |
if: ${{ !inputs.DRY_RUN }} |
| 98 |
with: |
| 99 |
registry: ghcr.io |
| 100 |
username: ${{ github.actor }} |
| 101 |
password: ${{ secrets.GITHUB_TOKEN }} |
| 102 |
|
| 103 |
- name: Run GoReleaser |
| 104 |
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3 |
| 105 |
env: |
| 106 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 |
DRY_RUN: ${{ inputs.DRY_RUN }} |
| 108 |
with: |
| 109 |
distribution: goreleaser |
| 110 |
version: "~> v2" |
| 111 |
args: >- |
| 112 |
release |
| 113 |
--config build/goreleaser/${{ inputs.BUILD_TYPE }}.yaml |
| 114 |
${{ inputs.BUILD_TYPE == 'nightly' && '--skip=validate,archive' || '' }} |
| 115 |
--clean |
| 116 |
${{ inputs.DRY_RUN && '--skip=publish' || '' }} |
| 117 |
|
| 118 |
- name: Upload Binary SBOMs |
| 119 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 120 |
if: ${{ !inputs.DRY_RUN && inputs.BUILD_TYPE == 'stable' }} |
| 121 |
with: |
| 122 |
name: ${{ inputs.BUILD_TYPE }}-binary-sboms |
| 123 |
path: dist/*.sbom |
| 124 |
if-no-files-found: ignore |
| 125 |
|
| 126 |
- name: Generate Artifact Attestation |
| 127 |
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 |
| 128 |
if: ${{ !inputs.DRY_RUN && inputs.BUILD_TYPE == 'stable' }} |
| 129 |
with: |
| 130 |
subject-checksums: ./dist/checksums.txt |
| 131 |
|
| 132 |
- name: Cleanup dist Directory |
| 133 |
if: always() |
| 134 |
run: rm -rf dist |