Skip to content

Commit 5deacad

Browse files
pnachtlaurentsimon
andauthored
ci: Ensure all version references are up-to-date prior to release (#447)
* Create references.sh Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * WIP: check docs in pre-submits Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Clean up Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Fix based on comments Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Add instructions to RELEASE.md Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> * Check references match version in PR body Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> --------- Signed-off-by: Pedro Kaj Kjellerup Nacht <[email protected]> Co-authored-by: laurentsimon <[email protected]>
1 parent 2444233 commit 5deacad

File tree

3 files changed

+110
-3
lines changed

3 files changed

+110
-3
lines changed

.github/workflows/pre-submit.actions.yml

+21
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,24 @@ jobs:
3939
with:
4040
name: dist
4141
path: dist/
42+
43+
check-docs:
44+
runs-on: ubuntu-latest
45+
if: ${{ contains(github.event.pull_request.body, '#label:release') }}
46+
env:
47+
BODY: ${{ github.event.pull_request.body }}
48+
steps:
49+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
50+
51+
- name: Check documentation is up-to-date
52+
run: |
53+
RELEASE_TAG=$(
54+
echo "$BODY" | \
55+
grep -oE '^[[:blank:]]*#label:release[[:blank:]]+v?[0-9]+\.[0-9]+\.[0-9]+' | \
56+
sed -E 's/.*([0-9]+\.[0-9]+\.[0-9])/\1/'
57+
)
58+
if [[ -z "$RELEASE_TAG" ]]; then
59+
echo "Invalid release PR body. Must include `#label:release vX.Y.Z"
60+
exit 1
61+
fi
62+
RELEASE_TAG="${RELEASE_TAG}" ./.github/workflows/scripts/pre-release/references.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
# Verify that all references point to the same version
4+
5+
set -euo pipefail
6+
7+
function get_first_nonblank_line() {
8+
while read line; do
9+
[[ "$line" =~ [^[:blank:]] ]] && break
10+
done < "$1"
11+
echo "$line"
12+
}
13+
14+
###
15+
### SHA256SUM.md
16+
###
17+
18+
line=$(get_first_nonblank_line SHA256SUM.md)
19+
20+
# Ensure both visible text and link point to the same release
21+
version_txt="$(sed -E "s~.*\[v(.*)\].*~\1~" <<< "$line")"
22+
version_lnk="$(sed -E "s~.*/v(.*)\)$~\1~" <<< "$line")"
23+
24+
if [[ "$version_txt" != "$version_lnk" ]]; then
25+
mark_txt="$(head -c ${#version_txt} < /dev/zero | tr '\0' '^')"
26+
mark_lnk="$(head -c ${#version_lnk} < /dev/zero | tr '\0' '^')"
27+
28+
marks="${line/"$version_txt"/"$mark_txt"}"
29+
marks="${marks/"$version_lnk"/"$mark_lnk"}"
30+
marks="$(sed 's/[^^]/ /g' <<< "$marks")"
31+
32+
echo "SHA256SUM.md: Visible text and linked URL do not match:"
33+
echo "$line"
34+
echo "$marks"
35+
36+
exit 1
37+
fi
38+
39+
# Ensure version matches what's declared in the PR body
40+
if [[ "$version_txt" != "$RELEASE_TAG" ]]; then
41+
echo "SHA256SUM.md version doesn't match version declared in PR body"
42+
echo "PR body: #label:release v$RELEASE_TAG"
43+
echo "SHA256SUM.md: v$version_txt"
44+
45+
exit 1
46+
fi
47+
48+
###
49+
### go.mod
50+
###
51+
52+
# Get major version from go.mod
53+
major_version_go_mod="$(get_first_nonblank_line go.mod | sed -E 's~.*/v(.*)~\1~')"
54+
55+
# Get major version declared in PR body
56+
major_version="$(sed -E 's/(.+)\..+\..+/\1/' <<< "$RELEASE_TAG")"
57+
58+
# Ensure major version from SHA256SUM.md matches go.mod's
59+
if [[ "$major_version_go_mod" != "$major_version" ]]; then
60+
echo "go.mod version doesn't match version declared in PR body:"
61+
echo "PR body: v$major_version (v$RELEASE_TAG)"
62+
echo "go.mod: v$major_version_go_mod"
63+
64+
exit 1
65+
fi
66+
67+
###
68+
### README.md
69+
###
70+
71+
# Select all version numbers following a reference to slsa-verifier that are different
72+
# from the version defined in SHA256SUM.md
73+
results=$(
74+
grep -Pon ".*?slsa-verifier.*?\d+\.\d+\.\d+" README.md |
75+
grep -v "$RELEASE_TAG$" |
76+
sed -E 's/(.*)/ \1/' || true
77+
)
78+
79+
if [[ "$results" != "" ]]; then
80+
echo "README.md version doesn't match version declared in PR body:"
81+
echo "PR body: #label:release v$RELEASE_TAG"
82+
echo "README.md:"
83+
echo "$results"
84+
exit 1
85+
fi

RELEASE.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ $ sha256sum slsa-verifier-linux-amd64
116116
$ sed -i "s/v1.0.0/v1.1.1/g" ./README.md
117117
```
118118

119-
4. Send a pull request with the changes. In the description, explain the steps to verify the hash update, i.e., reviewers shoud LGTM only if the provenance verification succeeds
120-
and the hash in the pull request matches the one computed on the binary. You can use [#slsa-framework/slsa-github-generator#113](https://github.com/slsa-framework/slsa-github-generator/pull/113) as example.
119+
4. Send a pull request with the changes. In the description:
120+
- add the string `#label:release vX.Y.Z` on its own line;
121+
- explain the steps to verify the hash update, i.e., reviewers shoud LGTM only if the provenance verification succeeds and the hash in the pull request matches the one computed on the binary. You can use [#slsa-framework/slsa-github-generator#113](https://github.com/slsa-framework/slsa-github-generator/pull/113) as an example.
121122

122-
5. Replace all version / commit references to the slsa-verifier repo with references to the newly released version [e2e.installer-action.yml](https://github.com/slsa-framework/example-package/blob/main/.github/workflows/e2e.installer-action.yml). Each reference has the comment `# UPDATE ON RELEASE`.
123+
5. Update all version / commit references to the `slsa-verifier` repo in [`example-package`'s e2e.installer-action.yml](https://github.com/slsa-framework/example-package/blob/main/.github/workflows/e2e.installer-action.yml). Each reference has the comment `# UPDATE ON RELEASE`.
123124

124125
## Update builders
125126

0 commit comments

Comments
 (0)