Skip to content

Commit 4f678be

Browse files
committed
ci: split out release check into is-workflow-valid.sh
This change refactors the script logic that checks if a workflow in fact built the commit matching our release tag out into a separate script. This is mainly an improvement in clarity.
1 parent ccb99d4 commit 4f678be

File tree

3 files changed

+78
-49
lines changed

3 files changed

+78
-49
lines changed

RELEASING.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ To publish a new version of `wasi-sdk` as a GitHub release:
2424
[actions]: https://github.com/WebAssembly/wasi-sdk/actions
2525
[tokens]: https://github.com/settings/tokens
2626

27-
3. Download and unzip the workflow artifacts. Note that artifacts with `+m` or
27+
3. Check that the workflow built the artifacts for the given tag and that the
28+
workflow completed successfully:
29+
30+
```shell script
31+
ci/is-worfklow-valid.sh $TAG $WORKFLOW_RUN_ID $GITHUB_TOKEN
32+
```
33+
34+
4. Download and unzip the workflow artifacts. Note that artifacts with `+m` or
2835
`.m` suffixes indicate that the Git tree was modified. Expect some duplicates
2936
since some of the same artifacts are built on multiple CI runners (e.g.,
3037
Windows, MacOS, Linux). The following script does all of this automatically:
@@ -33,7 +40,7 @@ To publish a new version of `wasi-sdk` as a GitHub release:
3340
ci/download-workflow-artifacts.sh $TAG $WORKFLOW_RUN_ID $GITHUB_TOKEN
3441
```
3542

36-
4. Draft a new release. This could be done [manually][releases] but the
43+
5. Draft a new release. This could be done [manually][releases] but the
3744
following script simplifies the uploading of all the files and auto-generates
3845
the release description:
3946

@@ -43,6 +50,6 @@ To publish a new version of `wasi-sdk` as a GitHub release:
4350

4451
[releases]: https://github.com/WebAssembly/wasi-sdk/releases
4552

46-
5. Publish the release; the previous step only creates a draft. Follow the link
53+
6. Publish the release; the previous step only creates a draft. Follow the link
4754
in the previous step or navigate to the GitHub [releases] to review the
4855
description, commit, tag, and assets before clicking "Publish"

ci/download-workflow-artifacts.sh

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,24 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
# This script downloads and unzips the artifacts produced in a workflow run. It
5-
# also checks that the workflow commit corresponds to the tag commit that these
6-
# artifacts will be released under. The script has several pre-requisites:
4+
# This script downloads and unzips the artifacts produced in a workflow run. The
5+
# script has several pre-requisites:
76
# - some standard Bash tools (curl, unzip) and one slightly more rare one (jq)
8-
# - an already-created tag in the repository (this marks the code to release)
97
# - the ID of a workflow run that has run successfully--this is where we
108
# retrieve the artifacts from
119
# - a GitHub access token, see https://github.com/settings/tokens
1210
#
13-
# Usage: download-workflow-artifacts.sh <release tag> <workflow run ID> <token>
11+
# Usage: download-workflow-artifacts.sh <workflow run ID> <token>
1412

15-
TAG=$1
16-
WORKFLOW_RUN_ID=$2
17-
GITHUB_TOKEN=$3
13+
WORKFLOW_RUN_ID=$1
14+
GITHUB_TOKEN=$2
1815
GITHUB_API_VERSION=2022-11-28
1916
GITHUB_API_URL=https://api.github.com/repos/WebAssembly/wasi-sdk
2017
TMP_DIR=$(mktemp -d -t wasi-sdk-artifacts.XXXXXXX)
2118

22-
if [ -z "${TAG}" ] || [ -z "${WORKFLOW_RUN_ID}" ] || [ -z "${GITHUB_TOKEN}" ]; then
19+
if [ -z "${WORKFLOW_RUN_ID}" ] || [ -z "${GITHUB_TOKEN}" ]; then
2320
>&2 echo "Missing parameter; exiting..."
24-
>&2 echo "Usage: download-worfklow-artifacts.sh <release tag> <workflow run ID> <token>"
25-
exit 1
26-
fi
27-
28-
# Get the commit SHA for the passed tag.
29-
# See https://docs.github.com/en/rest/commits/commits#get-a-commit
30-
MATCHING_COMMIT=$(curl \
31-
-H "Accept: application/vnd.github+json" \
32-
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
33-
-H "X-GitHub-Api-Version: ${GITHUB_API_VERSION}" \
34-
"${GITHUB_API_URL}/commits/${TAG}")
35-
COMMIT=$(echo $MATCHING_COMMIT | jq -r '.sha')
36-
>&2 echo "===== Found commit for tag ${TAG}: ${COMMIT} ====="
37-
38-
# Check that the commit of the workflow run matches the tag commit and that the
39-
# workflow was successful.
40-
# See https://docs.github.com/en/rest/actions/workflow-runs#get-a-workflow-run
41-
WORKFLOW_RUN=$(curl \
42-
-H "Accept: application/vnd.github+json" \
43-
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
44-
-H "X-GitHub-Api-Version: ${GITHUB_API_VERSION}" \
45-
"${GITHUB_API_URL}/actions/runs/${WORKFLOW_RUN_ID}")
46-
WORKFLOW_COMMIT=$(echo $WORKFLOW_RUN | jq -r '.head_sha')
47-
WORKFLOW_STATUS=$(echo $WORKFLOW_RUN | jq -r '.status')
48-
>&2 echo "===== Found commit for workflow ${WORKFLOW_RUN_ID}: ${WORKFLOW_COMMIT} ====="
49-
if [ "${COMMIT}" != "${WORKFLOW_COMMIT}" ]; then
50-
>&2 echo "Commit at tag ${TAG} did not match the commit for workflow ${WORKFLOW_RUN_ID}, exiting...:"
51-
>&2 echo " ${COMMIT} != ${WORKFLOW_COMMIT}"
52-
exit 1
53-
fi
54-
if [ "${WORKFLOW_STATUS}" != "completed" ]; then
55-
>&2 echo "Workflow ${WORKFLOW_RUN_ID} did not end successfully, exiting...:"
56-
>&2 echo " status = ${WORKFLOW_STATUS}"
21+
>&2 echo "Usage: download-worfklow-artifacts.sh <workflow run ID> <token>"
5722
exit 1
5823
fi
5924

@@ -72,10 +37,9 @@ for A in $ARTIFACTS; do
7237
URL=$(echo $A | cut -d ',' -f 3)
7338
TO=$TMP_DIR/$NAME.zip
7439
# Exclude dist-ubuntu-latest to prefer dist-ubuntu-bionic, which is
75-
# compatible with wider distributions.
76-
# cf.
77-
# https://github.com/WebAssembly/wasi-sdk/pull/273#issuecomment-1373879491
78-
# https://github.com/WebAssembly/wasi-sdk/issues/303
40+
# compatible with wider distributions. See:
41+
# - https://github.com/WebAssembly/wasi-sdk/pull/273#issuecomment-1373879491
42+
# - https://github.com/WebAssembly/wasi-sdk/issues/303
7943
if [ "${NAME}" = "dist-ubuntu-latest" ]; then
8044
continue
8145
fi

ci/is-workflow-valid.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# This script checks 1) that the workflow commit corresponds to the commit for
5+
# the given tag and 2) that the workflow has completed. This is a sanity check
6+
# to ensure the artifacts we are about to publish are in fact built from the
7+
# commit/tag we think. The script has several pre-requisites:
8+
# - some standard Bash tools (curl, unzip) and one slightly more rare one (jq)
9+
# - an already-created tag in the repository (this marks the code to release)
10+
# - the ID of a workflow run that has run successfully--this is where we
11+
# retrieve the artifacts from
12+
# - a GitHub access token, see https://github.com/settings/tokens
13+
#
14+
# Usage: is-workflow-valid.sh <release tag> <workflow run ID> <token>
15+
16+
TAG=$1
17+
WORKFLOW_RUN_ID=$2
18+
GITHUB_TOKEN=$3
19+
GITHUB_API_VERSION=2022-11-28
20+
GITHUB_API_URL=https://api.github.com/repos/WebAssembly/wasi-sdk
21+
22+
if [ -z "${TAG}" ] || [ -z "${WORKFLOW_RUN_ID}" ] || [ -z "${GITHUB_TOKEN}" ]; then
23+
>&2 echo "Missing parameter; exiting..."
24+
>&2 echo "Usage: is-workflow-valid.sh <release tag> <workflow run ID> <token>"
25+
exit 1
26+
fi
27+
28+
# Get the commit SHA for the passed tag.
29+
# See https://docs.github.com/en/rest/commits/commits#get-a-commit
30+
MATCHING_COMMIT=$(curl \
31+
-H "Accept: application/vnd.github+json" \
32+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
33+
-H "X-GitHub-Api-Version: ${GITHUB_API_VERSION}" \
34+
"${GITHUB_API_URL}/commits/${TAG}")
35+
COMMIT=$(echo $MATCHING_COMMIT | jq -r '.sha')
36+
>&2 echo "===== Found commit for tag ${TAG}: ${COMMIT} ====="
37+
38+
# Check that the commit of the workflow run matches the tag commit and that the
39+
# workflow was successful.
40+
# See https://docs.github.com/en/rest/actions/workflow-runs#get-a-workflow-run
41+
WORKFLOW_RUN=$(curl \
42+
-H "Accept: application/vnd.github+json" \
43+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
44+
-H "X-GitHub-Api-Version: ${GITHUB_API_VERSION}" \
45+
"${GITHUB_API_URL}/actions/runs/${WORKFLOW_RUN_ID}")
46+
WORKFLOW_COMMIT=$(echo $WORKFLOW_RUN | jq -r '.head_sha')
47+
WORKFLOW_STATUS=$(echo $WORKFLOW_RUN | jq -r '.status')
48+
>&2 echo "===== Found commit for workflow ${WORKFLOW_RUN_ID}: ${WORKFLOW_COMMIT} ====="
49+
if [ "${COMMIT}" != "${WORKFLOW_COMMIT}" ]; then
50+
>&2 echo "Commit at tag ${TAG} did not match the commit for workflow ${WORKFLOW_RUN_ID}, exiting...:"
51+
>&2 echo " ${COMMIT} != ${WORKFLOW_COMMIT}"
52+
exit 1
53+
fi
54+
if [ "${WORKFLOW_STATUS}" != "completed" ]; then
55+
>&2 echo "Workflow ${WORKFLOW_RUN_ID} did not end successfully, exiting...:"
56+
>&2 echo " status = ${WORKFLOW_STATUS}"
57+
exit 1
58+
fi

0 commit comments

Comments
 (0)