11#! /usr/bin/env bash
22set -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
1815GITHUB_API_VERSION=2022-11-28
1916GITHUB_API_URL=https://api.github.com/repos/WebAssembly/wasi-sdk
2017TMP_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
5823fi
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
0 commit comments