| 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@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 |
| 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@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 60 |
with: |
| 61 |
fetch-depth: 0 |
| 62 |
persist-credentials: false |
| 63 |
|
| 64 |
- name: Setup Go |
| 65 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.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@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.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@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.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@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0 |
| 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@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.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@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.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@5daf1e915a5f0af01ddbcd89a43b8061ff4f1a89 # v7.2.2 |
| 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@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 |
| 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 |