name: Build Release on: workflow_call: inputs: ENVIRONMENT: description: "GitHub environment for secrets access" required: true type: string BUILD_TYPE: description: "Type of release build (stable or nightly)" required: true type: string DRY_RUN: description: "Run in test mode without publishing artifacts" required: false default: false type: boolean secrets: DOCKERHUB_USERNAME: required: true DOCKERHUB_TOKEN: required: true permissions: contents: read # Declare default permissions as read only. jobs: build: name: Build runs-on: ubuntu-latest environment: ${{ inputs.ENVIRONMENT }} env: DOCKER_CLI_EXPERIMENTAL: "enabled" CGO_ENABLED: 0 TAG: ${{ github.ref_name }} permissions: contents: write # For code checkout and publishing releases packages: write # For pushing images to registries attestations: write # For generating provenance and SBOMs id-token: write # For OIDC auth to Docker Hub and GHCR steps: - name: Harden the Runner (Step Security) uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 with: egress-policy: audit - name: Validate BUILD_TYPE input env: BUILD_TYPE: ${{ inputs.BUILD_TYPE }} run: | if [[ "${BUILD_TYPE}" != "stable" && "${BUILD_TYPE}" != "nightly" ]]; then echo "Error: BUILD_TYPE must be 'stable' or 'nightly', got '${BUILD_TYPE}'" exit 1 fi - name: Checkout Repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - name: Setup Go uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: cache: false # Disable to prevent cache poisoning go-version-file: go.mod - name: Setup QEMU uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4.3.0 with: image: tonistiigi/binfmt@sha256:d3b963f787999e6c0219a48dba02978769286ff61a5f4d26245cb6a6e5567ea3 # latest platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm64/v8,linux/riscv64 - name: Setup Docker Buildx uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 with: platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm64/v8,linux/riscv64 - name: Install Syft for SBOM generation uses: anchore/sbom-action/download-syft@3ad7283483fc7af8ff2b4ea19663c2d5ca935e26 # v0.24.2 if: ${{ inputs.BUILD_TYPE == 'stable' }} - name: Install Cosign uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 - name: Login to Docker Hub uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 if: ${{ !inputs.DRY_RUN }} with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 if: ${{ !inputs.DRY_RUN }} with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DRY_RUN: ${{ inputs.DRY_RUN }} with: distribution: goreleaser version: "~> v2" args: >- release --config build/goreleaser/${{ inputs.BUILD_TYPE }}.yaml ${{ inputs.BUILD_TYPE == 'nightly' && '--skip=validate,archive' || '' }} --clean ${{ inputs.DRY_RUN && '--skip=publish' || '' }} - name: Upload Binary SBOMs uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 if: ${{ !inputs.DRY_RUN && inputs.BUILD_TYPE == 'stable' }} with: name: ${{ inputs.BUILD_TYPE }}-binary-sboms path: dist/*.sbom if-no-files-found: ignore - name: Generate Artifact Attestation uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 if: ${{ !inputs.DRY_RUN && inputs.BUILD_TYPE == 'stable' }} with: subject-checksums: ./dist/checksums.txt - name: Cleanup dist Directory if: always() run: rm -rf dist