-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: generate artefact slsa provenance
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,15 @@ permissions: | |
contents: read | ||
|
||
jobs: | ||
deploy: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: write | ||
|
||
outputs: | ||
hashes: ${{ steps.binary.outputs.hashes }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
|
@@ -30,10 +33,65 @@ jobs: | |
go-version: "stable" | ||
|
||
- name: Build and publish | ||
id: goreleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Generate binary hashes | ||
id: binary | ||
env: | ||
ARTIFACTS: "${{ steps.goreleaser.outputs.artifacts }}" | ||
run: | | ||
set -euo pipefail | ||
checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') | ||
echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT" | ||
binary-provenance: | ||
needs: [goreleaser] | ||
permissions: | ||
actions: read # To read the workflow path. | ||
id-token: write # To sign the provenance. | ||
contents: write # To add assets to a release. | ||
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] | ||
with: | ||
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}" | ||
upload-assets: true # upload to a new release | ||
|
||
verification-with-slsa-verifier: | ||
needs: [goreleaser, binary-provenance] | ||
runs-on: ubuntu-latest | ||
permissions: read-all | ||
steps: | ||
- name: Install the verifier | ||
uses: slsa-framework/slsa-verifier/actions/[email protected] | ||
|
||
- name: Download assets | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PROVENANCE: "${{ needs.binary-provenance.outputs.provenance-name }}" | ||
run: | | ||
set -euo pipefail | ||
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.tar.gz" | ||
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.zip" | ||
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$PROVENANCE" | ||
- name: Verify assets | ||
env: | ||
CHECKSUMS: ${{ needs.goreleaser.outputs.hashes }} | ||
PROVENANCE: "${{ needs.binary-provenance.outputs.provenance-name }}" | ||
run: | | ||
set -euo pipefail | ||
checksums=$(echo "$CHECKSUMS" | base64 -d) | ||
while read -r line; do | ||
fn=$(echo $line | cut -d ' ' -f2) | ||
echo "Verifying $fn" | ||
slsa-verifier verify-artifact --provenance-path "$PROVENANCE" \ | ||
--source-uri "github.com/$GITHUB_REPOSITORY" \ | ||
--source-tag "$GITHUB_REF_NAME" \ | ||
"$fn" | ||
done <<<"$checksums" |
This file contains 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