chore(.github/workflows/release.yml): add custom SLSA provenance and … #433
Workflow file for this run
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: | |
| tags: | |
| - v* | |
| permissions: | |
| contents: read | |
| jobs: | |
| goreleaser: | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| outputs: | |
| hashes: ${{ steps.hash.outputs.hashes }} | |
| tag_name: ${{ steps.tag.outputs.tag_name }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
| with: | |
| fetch-depth: 0 | |
| submodules: recursive | |
| - name: Setup Go | |
| uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b | |
| with: | |
| go-version-file: go.mod | |
| - name: Check GoReleaser config | |
| uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 | |
| with: | |
| version: latest | |
| args: check | |
| - name: Run GoReleaser | |
| uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 | |
| id: run-goreleaser | |
| with: | |
| version: latest | |
| args: release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate subject | |
| id: hash | |
| env: | |
| ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}" | |
| run: | | |
| set -euo pipefail | |
| hashes=$(echo $ARTIFACTS | jq --raw-output '.[] | {name, "digest": (.extra.Digest // .extra.Checksum)} | select(.digest) | {digest} + {name} | join(" ") | sub("^sha256:";"")' | base64 -w0) | |
| if test "$hashes" = ""; then # goreleaser < v1.13.0 | |
| checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') | |
| hashes=$(cat $checksum_file | base64 -w0) | |
| fi | |
| echo "hashes=$hashes" >> $GITHUB_OUTPUT | |
| - name: Set tag output | |
| id: tag | |
| run: echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT" | |
| provenance: | |
| needs: [goreleaser] | |
| permissions: | |
| actions: read | |
| id-token: write | |
| contents: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Generate SLSA Provenance | |
| id: slsa | |
| uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0 | |
| with: | |
| base64-subjects: "${{ needs.goreleaser.outputs.hashes }}" | |
| upload-assets: false | |
| - name: Upload SLSA Provenance Attestation to Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG_NAME: ${{ needs.goreleaser.outputs.tag_name }} | |
| run: | | |
| set -euxo pipefail | |
| PROVENANCE_FILE="multiple.intoto.jsonl" | |
| SPDX_FILES="*.spdx.json" | |
| files_to_upload=() | |
| if [ -f "$PROVENANCE_FILE" ]; then | |
| files_to_upload+=("$PROVENANCE_FILE") | |
| echo "Found provenance file: $PROVENANCE_FILE" | |
| else | |
| echo "Provenance '$PROVENANCE_FILE' cannot be found." | |
| exit 0 | |
| fi | |
| found_spdx=$(find . -maxdepth 1 -name '*.spdx.json' -print) | |
| if [ -n "$found_spdx" ]; then | |
| while IFS= read -r file; do | |
| files_to_upload+=("$file") | |
| echo "Found SPDX file: $file" | |
| done <<< "$found_spdx" | |
| else | |
| echo "$SPDX_FILES cannot be found." | |
| exit 0 | |
| fi | |
| gh release upload "$TAG_NAME" "${files_to_upload[@]}" --clobber |