CI: Add caching and retries to the wasm-tools download

Cache the wasm-tools binary rather than doing (trying) a re-fetch of it
on every build job. And when we ever do need to re-download it (after a
cache miss), then do it with some sensible retry-with-backoff-and-wait.

Otherwise, a single network hiccup when trying to download wasm-tools
was failing multiple CI jobs at once — before their builds even started.
This commit is contained in:
sideshowbarker 2026-06-08 16:43:26 +09:00 committed by Jelle Raaijmakers
parent d819152b4e
commit 1484686c70

View file

@ -114,7 +114,8 @@ runs:
if: ${{ inputs.os == 'macOS' || inputs.os == 'Android' }}
uses: dtolnay/rust-toolchain@stable
- name: 'Install wasm-tools'
- name: 'Resolve wasm-tools release'
id: 'wasm-tools'
if: ${{ inputs.type == 'build' }}
shell: bash
run: |
@ -131,19 +132,49 @@ runs:
EXTENSION=tar.gz
fi
NAME="wasm-tools-${VERSION}-${ARCH}-${LOWERCASE_OS}"
FILENAME="${NAME}.${EXTENSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "name=${NAME}" >> "$GITHUB_OUTPUT"
echo "filename=${NAME}.${EXTENSION}" >> "$GITHUB_OUTPUT"
echo "extension=${EXTENSION}" >> "$GITHUB_OUTPUT"
curl --fail --location --write-out '%{url}' --output "${FILENAME}" \
"https://github.com/bytecodealliance/wasm-tools/releases/download/v${VERSION}/${FILENAME}"
- name: 'Cache wasm-tools'
id: 'wasm-tools-cache'
if: ${{ inputs.type == 'build' }}
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/${{ steps.wasm-tools.outputs.name }}
key: ${{ steps.wasm-tools.outputs.name }}
if [ "${EXTENSION}" == 'zip' ]; then
- name: 'Install wasm-tools'
if: ${{ inputs.type == 'build' && steps.wasm-tools-cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
FILENAME="${{ steps.wasm-tools.outputs.filename }}"
URL="https://github.com/bytecodealliance/wasm-tools/releases/download/v${{ steps.wasm-tools.outputs.version }}/${FILENAME}"
delays=(5 15 45)
attempt=1
until curl --fail --location --output "${FILENAME}" "${URL}"; do
if (( attempt > ${#delays[@]} )); then
echo "wasm-tools download failed after $(( ${#delays[@]} + 1 )) attempts" >&2
exit 1
fi
echo "wasm-tools download failed; retrying in ${delays[attempt-1]}s" >&2
sleep "${delays[attempt-1]}"
attempt=$(( attempt + 1 ))
done
if [ "${{ steps.wasm-tools.outputs.extension }}" == 'zip' ]; then
unzip "${FILENAME}"
else
tar -xzf "${FILENAME}"
fi
rm "${FILENAME}"
echo "${GITHUB_WORKSPACE}/${NAME}" >> $GITHUB_PATH
- name: 'Add wasm-tools to PATH'
if: ${{ inputs.type == 'build' }}
shell: bash
run: echo "${GITHUB_WORKSPACE}/${{ steps.wasm-tools.outputs.name }}" >> "$GITHUB_PATH"
- name: 'Set required environment variables'
if: ${{ inputs.os == 'Linux' && inputs.arch == 'arm64' }}