Merge pull request #240 from smlx/dependabot/github_actions/github/co… #138
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: {} | |
| jobs: | |
| release-tag: | |
| permissions: | |
| # create tag | |
| contents: write | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new-tag: ${{ steps.ccv.outputs.new-tag }} | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Bump tag if necessary | |
| id: ccv | |
| uses: smlx/ccv@7318e2f25a52dcd550e75384b84983973251a1f8 # v0.10.0 | |
| release-build: | |
| permissions: | |
| # create release | |
| contents: write | |
| # push docker images to registry | |
| packages: write | |
| # required by attest-build-provenance | |
| id-token: write | |
| attestations: write | |
| needs: release-tag | |
| if: needs.release-tag.outputs.new-tag == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | |
| with: | |
| go-version: stable | |
| - name: Login to GHCR | |
| uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Export SBOM in SPDX JSON format | |
| # https://docs.github.com/en/rest/dependency-graph/sboms?apiVersion=2022-11-28 | |
| run: | | |
| gh api \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| /repos/${{ github.repository }}/dependency-graph/sbom > sbom.spdx.json | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 | |
| id: goreleaser | |
| with: | |
| version: latest | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # attest artefacts | |
| - uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0 | |
| with: | |
| subject-path: | | |
| dist/*.tar.gz | |
| sbom.spdx.json | |
| # parse artifacts to the format required for image attestation | |
| - run: | | |
| echo "digest=$(echo "$ARTIFACTS" | jq -r '.[]|select(.type=="Docker Manifest")|select(.name|test("go-cli-github:v"))|.extra.Digest')" >> "$GITHUB_OUTPUT" | |
| echo "name=$(echo "$ARTIFACTS" | jq -r '.[]|select(.type=="Docker Manifest")|select(.name|test("go-cli-github:v"))|.name|split(":")[0]')" >> "$GITHUB_OUTPUT" | |
| id: image_metadata_go_cli_github | |
| env: | |
| ARTIFACTS: ${{steps.goreleaser.outputs.artifacts}} | |
| - run: | | |
| echo "digest=$(echo "$ARTIFACTS" | jq -r '.[]|select(.type=="Docker Manifest")|select(.name|test("another-binary:v"))|.extra.Digest')" >> "$GITHUB_OUTPUT" | |
| echo "name=$(echo "$ARTIFACTS" | jq -r '.[]|select(.type=="Docker Manifest")|select(.name|test("another-binary:v"))|.name|split(":")[0]')" >> "$GITHUB_OUTPUT" | |
| id: image_metadata_another_binary | |
| env: | |
| ARTIFACTS: ${{steps.goreleaser.outputs.artifacts}} | |
| # attest images | |
| - uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0 | |
| with: | |
| subject-digest: ${{steps.image_metadata_go_cli_github.outputs.digest}} | |
| subject-name: ${{steps.image_metadata_go_cli_github.outputs.name}} | |
| push-to-registry: true | |
| - uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0 | |
| with: | |
| subject-digest: ${{steps.image_metadata_another_binary.outputs.digest}} | |
| subject-name: ${{steps.image_metadata_another_binary.outputs.name}} | |
| push-to-registry: true |