|
| 1 | +# |
| 2 | +# Copyright 2023 Stacklok, Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +# This workflow compiles frizbee using a SLSA3 compliant |
| 17 | +# build and then verifies the provenance of the built artifacts. |
| 18 | +# It releases the following architectures: amd64, arm64, and armv7 on Linux, |
| 19 | +# Windows, and macOS. |
| 20 | +# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier. |
| 21 | +# For more information about SLSA and how it improves the supply-chain, visit slsa.dev. |
| 22 | + |
| 23 | +name: Release |
| 24 | +on: |
| 25 | + push: |
| 26 | + tags: |
| 27 | + - '*' |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + |
| 32 | +jobs: |
| 33 | + release: |
| 34 | + name: Build and release |
| 35 | + outputs: |
| 36 | + hashes: ${{ steps.hash.outputs.hashes }} |
| 37 | + permissions: |
| 38 | + contents: write # To add assets to a release. |
| 39 | + id-token: write # To do keyless signing with cosign |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + |
| 47 | + - name: Setup Go |
| 48 | + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 |
| 49 | + with: |
| 50 | + go-version-file: 'go.mod' |
| 51 | + cache: true |
| 52 | + |
| 53 | + - name: Install Syft |
| 54 | + uses: anchore/sbom-action/download-syft@78fc58e266e87a38d4194b2137a3d4e9bcaf7ca1 # v0.14.3 |
| 55 | + |
| 56 | + - name: Install Cosign |
| 57 | + uses: sigstore/cosign-installer@1fc5bd396d372bee37d608f955b336615edf79c8 # v3.2.0 |
| 58 | + |
| 59 | + - name: Run GoReleaser |
| 60 | + id: run-goreleaser |
| 61 | + uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5 |
| 62 | + with: |
| 63 | + distribution: goreleaser |
| 64 | + version: latest |
| 65 | + args: release --clean |
| 66 | + env: |
| 67 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} |
| 69 | + WINGET_GITHUB_TOKEN: ${{ secrets.WINGET_GITHUB_TOKEN }} |
| 70 | + |
| 71 | + - name: Generate subject |
| 72 | + id: hash |
| 73 | + env: |
| 74 | + ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}" |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | + hashes=$(echo $ARTIFACTS | jq --raw-output '.[] | {name, "digest": (.extra.Digest // .extra.Checksum)} | select(.digest) | {digest} + {name} | join(" ") | sub("^sha256:";"")' | base64 -w0) |
| 78 | + if test "$hashes" = ""; then # goreleaser < v1.13.0 |
| 79 | + checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') |
| 80 | + hashes=$(cat $checksum_file | base64 -w0) |
| 81 | + fi |
| 82 | + echo "hashes=$hashes" >> $GITHUB_OUTPUT |
| 83 | +
|
| 84 | + provenance: |
| 85 | + name: Generate provenance (SLSA3) |
| 86 | + needs: |
| 87 | + - release |
| 88 | + permissions: |
| 89 | + actions: read # To read the workflow path. |
| 90 | + id-token: write # To sign the provenance. |
| 91 | + contents: write # To add assets to a release. |
| 92 | + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@07e64b653f10a80b6510f4568f685f8b7b9ea830 # v1.9.0 |
| 93 | + with: |
| 94 | + base64-subjects: "${{ needs.release.outputs.hashes }}" |
| 95 | + upload-assets: true # upload to a new release |
| 96 | + |
| 97 | + verification: |
| 98 | + name: Verify provenance of assets (SLSA3) |
| 99 | + needs: |
| 100 | + - release |
| 101 | + - provenance |
| 102 | + runs-on: ubuntu-latest |
| 103 | + permissions: read-all |
| 104 | + steps: |
| 105 | + - name: Install the SLSA verifier |
| 106 | + uses: slsa-framework/slsa-verifier/actions/installer@7e1e47d7d793930ab0082c15c2b971fdb53a3c95 # v2.4.1 |
| 107 | + - name: Download assets |
| 108 | + env: |
| 109 | + GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 110 | + CHECKSUMS: "${{ needs.release.outputs.hashes }}" |
| 111 | + ATT_FILE_NAME: "${{ needs.provenance.outputs.provenance-name }}" |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | + checksums=$(echo "$CHECKSUMS" | base64 -d) |
| 115 | + while read -r line; do |
| 116 | + fn=$(echo $line | cut -d ' ' -f2) |
| 117 | + echo "Downloading $fn" |
| 118 | + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$fn" |
| 119 | + done <<<"$checksums" |
| 120 | + gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$ATT_FILE_NAME" |
| 121 | + - name: Verify assets |
| 122 | + env: |
| 123 | + CHECKSUMS: "${{ needs.release.outputs.hashes }}" |
| 124 | + PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}" |
| 125 | + run: | |
| 126 | + set -euo pipefail |
| 127 | + checksums=$(echo "$CHECKSUMS" | base64 -d) |
| 128 | + while read -r line; do |
| 129 | + fn=$(echo $line | cut -d ' ' -f2) |
| 130 | + echo "Verifying SLSA provenance for $fn" |
| 131 | + slsa-verifier verify-artifact --provenance-path "$PROVENANCE" \ |
| 132 | + --source-uri "github.com/$GITHUB_REPOSITORY" \ |
| 133 | + --source-tag "$GITHUB_REF_NAME" \ |
| 134 | + "$fn" |
| 135 | + done <<<"$checksums" |
0 commit comments