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@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 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@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: fetch-depth: 0 persist-credentials: false - name: Setup Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: cache: false # Disable to prevent cache poisoning go-version-file: go.mod - name: Setup QEMU uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.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@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.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@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0 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@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 if: ${{ !inputs.DRY_RUN }} with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GHCR uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 if: ${{ !inputs.DRY_RUN }} with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@5daf1e915a5f0af01ddbcd89a43b8061ff4f1a89 # v7.2.2 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@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 if: ${{ !inputs.DRY_RUN && inputs.BUILD_TYPE == 'stable' }} with: subject-checksums: ./dist/checksums.txt - name: Cleanup dist Directory if: always() run: rm -rf dist