Skip to content

Commit dd95ed3

Browse files
committed
ci: generate artefact slsa provenance
1 parent 502443f commit dd95ed3

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

.github/workflows/goreleaser.yml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ permissions:
1111
contents: read
1212

1313
jobs:
14-
deploy:
14+
goreleaser:
1515
runs-on: ubuntu-latest
1616

1717
permissions:
1818
contents: write
1919

20+
outputs:
21+
hashes: ${{ steps.binary.outputs.hashes }}
22+
2023
steps:
2124
- uses: actions/checkout@v4
2225
with:
@@ -30,10 +33,65 @@ jobs:
3033
go-version: "stable"
3134

3235
- name: Build and publish
36+
id: goreleaser
3337
uses: goreleaser/goreleaser-action@v5
3438
with:
3539
distribution: goreleaser
3640
version: latest
3741
args: release --clean
3842
env:
3943
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Generate binary hashes
46+
id: binary
47+
env:
48+
ARTIFACTS: "${{ steps.goreleaser.outputs.artifacts }}"
49+
run: |
50+
set -euo pipefail
51+
52+
checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
53+
echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
54+
55+
binary-provenance:
56+
needs: [goreleaser]
57+
permissions:
58+
actions: read # To read the workflow path.
59+
id-token: write # To sign the provenance.
60+
contents: write # To add assets to a release.
61+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
62+
with:
63+
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
64+
upload-assets: true # upload to a new release
65+
66+
verification-with-slsa-verifier:
67+
needs: [goreleaser, binary-provenance]
68+
runs-on: ubuntu-latest
69+
permissions: read-all
70+
steps:
71+
- name: Install the verifier
72+
uses: slsa-framework/slsa-verifier/actions/[email protected]
73+
74+
- name: Download assets
75+
env:
76+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
PROVENANCE: "${{ needs.binary-provenance.outputs.provenance-name }}"
78+
run: |
79+
set -euo pipefail
80+
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.tar.gz"
81+
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.zip"
82+
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$PROVENANCE"
83+
- name: Verify assets
84+
env:
85+
CHECKSUMS: ${{ needs.goreleaser.outputs.hashes }}
86+
PROVENANCE: "${{ needs.binary-provenance.outputs.provenance-name }}"
87+
run: |
88+
set -euo pipefail
89+
checksums=$(echo "$CHECKSUMS" | base64 -d)
90+
while read -r line; do
91+
fn=$(echo $line | cut -d ' ' -f2)
92+
echo "Verifying $fn"
93+
slsa-verifier verify-artifact --provenance-path "$PROVENANCE" \
94+
--source-uri "github.com/$GITHUB_REPOSITORY" \
95+
--source-tag "$GITHUB_REF_NAME" \
96+
"$fn"
97+
done <<<"$checksums"

.github/workflows/scorecards.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
- cron: '20 7 * * 2'
1414
push:
1515
branches: ["main"]
16+
workflow_dispatch:
1617

1718
# Declare default permissions as read only.
1819
permissions: read-all

0 commit comments

Comments
 (0)