|
| 1 | +name: goreleaser |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + goreleaser: |
| 13 | + outputs: |
| 14 | + hashes: ${{ steps.hash.outputs.hashes }} |
| 15 | + permissions: |
| 16 | + contents: write # for goreleaser/goreleaser-action to create a GitHub release |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + - name: Set up Go |
| 24 | + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 |
| 25 | + with: |
| 26 | + go-version: "1.21" |
| 27 | + check-latest: true |
| 28 | + - name: Install Syft |
| 29 | + run: | |
| 30 | + curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin |
| 31 | + - name: Run GoReleaser |
| 32 | + id: run-goreleaser |
| 33 | + uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 |
| 34 | + with: |
| 35 | + version: latest |
| 36 | + args: release --clean |
| 37 | + env: |
| 38 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + VERSION_LDFLAGS: ${{ steps.ldflags.outputs.version }} |
| 40 | + - name: Generate subject |
| 41 | + id: hash |
| 42 | + env: |
| 43 | + ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}" |
| 44 | + run: | |
| 45 | + set -euo pipefail |
| 46 | +
|
| 47 | + checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') |
| 48 | + echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT" |
| 49 | +
|
| 50 | + provenance: |
| 51 | + needs: [goreleaser] |
| 52 | + permissions: |
| 53 | + actions: read # To read the workflow path. |
| 54 | + id-token: write # To sign the provenance. |
| 55 | + contents: write # To add assets to a release. |
| 56 | + uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] |
| 57 | + with: |
| 58 | + base64-subjects: "${{ needs.goreleaser.outputs.hashes }}" |
| 59 | + upload-assets: true # upload to a new release |
| 60 | + verification: |
| 61 | + needs: [goreleaser, provenance] |
| 62 | + runs-on: ubuntu-latest |
| 63 | + permissions: read-all |
| 64 | + steps: |
| 65 | + - name: Install the verifier |
| 66 | + uses: slsa-framework/slsa-verifier/actions/[email protected] |
| 67 | + |
| 68 | + - name: Download assets |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}" |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.tar.gz" |
| 75 | + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.sbom" |
| 76 | + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$PROVENANCE" |
| 77 | + - name: Verify assets |
| 78 | + env: |
| 79 | + CHECKSUMS: ${{ needs.goreleaser.outputs.hashes }} |
| 80 | + PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}" |
| 81 | + run: | |
| 82 | + set -euo pipefail |
| 83 | + checksums=$(echo "$CHECKSUMS" | base64 -d) |
| 84 | + while read -r line; do |
| 85 | + fn=$(echo $line | cut -d ' ' -f2) |
| 86 | + echo "Verifying $fn" |
| 87 | + slsa-verifier verify-artifact --provenance-path "$PROVENANCE" \ |
| 88 | + --source-uri "github.com/$GITHUB_REPOSITORY" \ |
| 89 | + --source-tag "$GITHUB_REF_NAME" \ |
| 90 | + "$fn" |
| 91 | + done <<<"$checksums" |
0 commit comments