1
+ name : release
2
+
3
+ # on:
4
+ # push:
5
+ # tags:
6
+ # - '*'
7
+ # FIXME(vdemeester) Add commit + tag
8
+
9
+ jobs :
10
+ goreleaser :
11
+ outputs :
12
+ hashes : ${{ steps.hash.outputs.hashes }}
13
+ tag_name : ${{ steps.tag.outputs.tag_name }}
14
+
15
+ defaults :
16
+ run :
17
+ working-directory : image/git-init
18
+
19
+ permissions :
20
+ packages : write
21
+ id-token : write
22
+ contents : write
23
+
24
+ runs-on : ubuntu-latest
25
+ steps :
26
+ - uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
27
+
28
+ - run : git fetch --prune --unshallow
29
+
30
+ - uses : actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
31
+ with :
32
+ go-version : ' 1.20'
33
+ check-latest : true
34
+
35
+ # This installs the current latest release.
36
+ - uses : ko-build/setup-ko@ace48d793556083a76f1e3e6068850c1f4a369aa # v0.6
37
+ with :
38
+ version : v0.13.0
39
+
40
+ - uses : imjasonh/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # v0.3
41
+
42
+ - uses : sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1
43
+
44
+ - name : Set tag output
45
+ id : tag
46
+ run : echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT"
47
+
48
+ - uses : goreleaser/goreleaser-action@3fa32b8bb5620a2c1afe798654bbad59f9da4906 # v4.4.0
49
+ id : run-goreleaser
50
+ with :
51
+ version : latest
52
+ args : release --clean
53
+ env :
54
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
55
+
56
+ - name : sign ko-image
57
+ run : |
58
+ digest=$(crane digest "${REGISTRY}":"${GIT_TAG}")
59
+ cosign sign --yes \
60
+ -a GIT_HASH="${GIT_HASH}" \
61
+ -a GIT_TAG="${GIT_TAG}" \
62
+ -a RUN_ID="${RUN_ID}" \
63
+ -a RUN_ATTEMPT="${RUN_ATTEMPT}" \
64
+ "${REGISTRY}@${digest}"
65
+ env :
66
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67
+ GIT_HASH : ${{ github.sha }}
68
+ GIT_TAG : ${{ steps.tag.outputs.tag_name }}
69
+ RUN_ATTEMPT : ${{ github.run_attempt }}
70
+ RUN_ID : ${{ github.run_id }}
71
+ REGISTRY : " ghcr.io/${{ github.repository }}"
72
+
73
+ - name : Generate subject
74
+ id : hash
75
+ env :
76
+ ARTIFACTS : " ${{ steps.run-goreleaser.outputs.artifacts }}"
77
+ run : |
78
+ set -euo pipefail
79
+
80
+ checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
81
+ echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
82
+
83
+ provenance :
84
+ needs :
85
+ - goreleaser
86
+
87
+ permissions :
88
+ actions : read # To read the workflow path.
89
+ id-token : write # To sign the provenance.
90
+ contents : write # To add assets to a release.
91
+
92
+ uses :
slsa-framework/slsa-github-generator/.github/workflows/[email protected]
93
+ with :
94
+ base64-subjects : " ${{ needs.goreleaser.outputs.hashes }}"
95
+ upload-assets : true
96
+ upload-tag-name : " ${{ needs.release.outputs.tag_name }}"
97
+
98
+ verification :
99
+ needs :
100
+ - goreleaser
101
+ - provenance
102
+
103
+ runs-on : ubuntu-latest
104
+ permissions : read-all
105
+
106
+ steps :
107
+ # Note: this will be replaced with the GHA in the future.
108
+ - name : Install the verifier
109
+ env :
110
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
111
+ run : |
112
+ set -euo pipefail
113
+
114
+ gh -R slsa-framework/slsa-verifier release download v1.3.2 -p "slsa-verifier-linux-amd64"
115
+ chmod ug+x slsa-verifier-linux-amd64
116
+ # Note: see https://github.com/slsa-framework/slsa-verifier/blob/main/SHA256SUM.md
117
+ COMPUTED_HASH=$(sha256sum slsa-verifier-linux-amd64 | cut -d ' ' -f1)
118
+ EXPECTED_HASH="b1d6c9bbce6274e253f0be33158cacd7fb894c5ebd643f14a911bfe55574f4c0"
119
+ if [[ "$EXPECTED_HASH" != "$COMPUTED_HASH" ]];then
120
+ echo "error: expected $EXPECTED_HASH, computed $COMPUTED_HASH"
121
+ exit 1
122
+ fi
123
+
124
+ - name : Download assets
125
+ env :
126
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
127
+ PROVENANCE : " ${{ needs.provenance.outputs.provenance-name }}"
128
+ run : |
129
+ set -euo pipefail
130
+
131
+ gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.tar.gz"
132
+ gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "$PROVENANCE"
133
+
134
+ - name : Verify assets
135
+ env :
136
+ CHECKSUMS : ${{ needs.goreleaser.outputs.hashes }}
137
+ PROVENANCE : " ${{ needs.provenance.outputs.provenance-name }}"
138
+ run : |
139
+ set -euo pipefail
140
+
141
+ checksums=$(echo "$CHECKSUMS" | base64 -d)
142
+ while read -r line; do
143
+ fn=$(echo $line | cut -d ' ' -f2)
144
+
145
+ echo "Verifying $fn"
146
+ ./slsa-verifier-linux-amd64 -artifact-path "$fn" \
147
+ -provenance "$PROVENANCE" \
148
+ -source "github.com/$GITHUB_REPOSITORY" \
149
+ -tag "$GITHUB_REF_NAME"
150
+
151
+ done <<<"$checksums"
0 commit comments