Skip to content

Commit 8040480

Browse files
ci: a release asset whose web address fails is fetched by the API; the cached xlings and mtest are not downloaded again
GitHub's web address of a release asset answered 504 for minutes while the API's address of the same asset answered 200 (2026-11-09). - fetch_release.sh follows a failed web attempt with the API's, with the job's token. - setup-macos-llvm downloaded the xlings release on every run, a cache hit or not; it now skips the download when the cached xlings is the pinned one, as bootstrap-mcpp does. - e2e-mtest keeps the mtest bundle in the cache, by version, and fetches it through fetch_release.sh; the bundle is mtest 0.5.2. Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 82e4201 commit 8040480

4 files changed

Lines changed: 67 additions & 15 deletions

File tree

‎.github/actions/bootstrap-mcpp/action.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ runs:
107107
env:
108108
XLINGS_NON_INTERACTIVE: '1'
109109
XLINGS_VERSION: ${{ inputs.xlings-version }}
110+
GITHUB_TOKEN: ${{ github.token }}
110111
run: |
111112
REPO_DIR="$(pwd)"
112113
# Always install the pinned version — the cache may hold an older
@@ -231,6 +232,7 @@ runs:
231232
env:
232233
XLINGS_NON_INTERACTIVE: '1'
233234
XLINGS_VERSION: ${{ inputs.xlings-version }}
235+
GITHUB_TOKEN: ${{ github.token }}
234236
run: |
235237
REPO_DIR="$(pwd)"
236238
# FAST PATH: see the unix leg for the reasoning. The cost on Windows is

‎.github/actions/e2e-mtest/action.yml‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ inputs:
1414
version:
1515
description: the mtest release
1616
required: false
17-
default: '0.4.0'
17+
default: '0.5.2'
1818
sha256:
1919
description: sha256 of mtest-<version>-openkal-bundle-all.tar.gz
2020
required: false
21-
default: 'b62e4ac7cd76b20dbdc48a5d041d377444e8815ee7a4ff1e7686145d13acc925'
21+
default: 'be443f8c546b3f4628dcd3f1eb6f45b4d698a7f805232f966349faf8250863c6'
2222
token:
2323
description: a token that reads this repository's actions
2424
required: false
@@ -27,18 +27,33 @@ inputs:
2727
runs:
2828
using: composite
2929
steps:
30+
# The bundle is a release's fixed bytes: kept once per version, so that a
31+
# job downloads it only when no job before it did.
32+
- name: The mtest bundle, kept
33+
id: bundle
34+
uses: actions/cache@v4
35+
with:
36+
path: ${{ runner.temp }}/mtest-bundle
37+
key: mtest-bundle-${{ inputs.version }}-${{ inputs.sha256 }}
3038
- name: mtest
3139
shell: bash
3240
env:
3341
MTEST_VERSION: ${{ inputs.version }}
3442
MTEST_SHA256: ${{ inputs.sha256 }}
43+
GITHUB_TOKEN: ${{ inputs.token }}
3544
run: |
3645
set -euo pipefail
3746
archive="mtest-$MTEST_VERSION-openkal-bundle-all.tar.gz"
3847
temp="$RUNNER_TEMP"; python=python3
3948
if [ "$RUNNER_OS" = Windows ]; then temp=$(cygpath -u "$RUNNER_TEMP"); python=python; fi
40-
curl -fsSL --retry 5 --retry-all-errors --retry-delay 5 -o "$temp/$archive" \
41-
"https://github.com/mcpp-community/mtest/releases/download/v$MTEST_VERSION/$archive"
49+
mkdir -p "$temp/mtest-bundle"
50+
if [ ! -s "$temp/mtest-bundle/$archive" ]; then
51+
# Retried, and by the API's address when the web's fails (fetch_release.sh).
52+
bash "$GITHUB_WORKSPACE/.github/tools/fetch_release.sh" \
53+
"https://github.com/mcpp-community/mtest/releases/download/v$MTEST_VERSION/$archive" \
54+
"$temp/mtest-bundle/$archive"
55+
fi
56+
cp "$temp/mtest-bundle/$archive" "$temp/$archive"
4257
actual=$("$python" -c "import hashlib,sys; print(hashlib.sha256(open(sys.argv[1],'rb').read()).hexdigest())" "$temp/$archive")
4358
[ "$actual" = "$MTEST_SHA256" ] || { echo "::error::$archive: sha256 $actual, the action pins $MTEST_SHA256"; exit 1; }
4459
mkdir -p "$temp/mtest" && tar xzf "$temp/$archive" -C "$temp/mtest"

‎.github/actions/setup-macos-llvm/action.yml‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,25 @@ runs:
5151
env:
5252
XLINGS_NON_INTERACTIVE: '1'
5353
XLINGS_VERSION: ${{ inputs.xlings-version }}
54+
GITHUB_TOKEN: ${{ github.token }}
5455
run: |
55-
WORK=$(mktemp -d)
56-
tarball="xlings-${XLINGS_VERSION}-macosx-arm64.tar.gz"
57-
# Retried and verified — .github/tools/fetch_release.sh. A bare curl
58-
# here is the `curl: (52) Empty reply from server` flake.
59-
bash "$GITHUB_WORKSPACE/.github/tools/fetch_release.sh" \
60-
"https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${tarball}" \
61-
"${WORK}/${tarball}"
62-
tar -xzf "${WORK}/${tarball}" -C "${WORK}"
63-
XLINGS_DIR="${WORK}/xlings-${XLINGS_VERSION}-macosx-arm64"
64-
"$XLINGS_DIR/subos/default/bin/xlings" self install
56+
# THE CACHE ALREADY HOLDS THE PINNED XLINGS (its key names the version):
57+
# nothing is downloaded, as bootstrap-mcpp's fast path does. This step
58+
# fetched the release on every run, a cache hit or not, and a 504 of
59+
# that fetch failed the job (2026-11-09).
60+
XL="$HOME/.xlings/subos/default/bin/xlings"
61+
if ! { [ -x "$XL" ] && "$XL" --version 2>/dev/null | head -1 | grep -qF "$XLINGS_VERSION"; }; then
62+
WORK=$(mktemp -d)
63+
tarball="xlings-${XLINGS_VERSION}-macosx-arm64.tar.gz"
64+
# Retried and verified, and by the API's address when the web's
65+
# fails — .github/tools/fetch_release.sh.
66+
bash "$GITHUB_WORKSPACE/.github/tools/fetch_release.sh" \
67+
"https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${tarball}" \
68+
"${WORK}/${tarball}"
69+
tar -xzf "${WORK}/${tarball}" -C "${WORK}"
70+
XLINGS_DIR="${WORK}/xlings-${XLINGS_VERSION}-macosx-arm64"
71+
"$XLINGS_DIR/subos/default/bin/xlings" self install
72+
fi
6573
export PATH="$HOME/.xlings/subos/default/bin:$PATH"
6674
xlings --version
6775
echo "PATH=$HOME/.xlings/subos/default/bin:$PATH" >> "$GITHUB_ENV"

‎.github/tools/fetch_release.sh‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ verify() {
4545
esac
4646
}
4747

48+
# THE SAME FILE BY GITHUB'S API. The web address of a release asset
49+
# (`github.com/<owner>/<repo>/releases/download/<tag>/<name>`) answered 504 for
50+
# minutes at a time while the API's address of the same asset answered 200
51+
# (measured 2026-11-09 on xlings-2026.10.26.1-macosx-arm64.tar.gz, three times
52+
# each). A failed web attempt is followed by the API's, with the job's token
53+
# where there is one (the API's anonymous limit is 60 requests an hour).
54+
api_fetch() {
55+
local rest="${url#https://github.com/}"
56+
[ "$rest" != "$url" ] || return 1
57+
local owner repo releases download tag name
58+
IFS=/ read -r owner repo releases download tag name <<<"$rest"
59+
[ "$releases/$download" = "releases/download" ] && [ -n "$name" ] || return 1
60+
local auth=()
61+
local token="${GITHUB_TOKEN:-${GH_TOKEN:-}}"
62+
[ -z "$token" ] || auth=(-H "Authorization: Bearer $token")
63+
local id
64+
id=$(curl -fsSL --retry 3 --retry-all-errors --connect-timeout 20 --max-time 60 "${auth[@]}" \
65+
"https://api.github.com/repos/$owner/$repo/releases/tags/$tag" \
66+
| python3 -c 'import json,sys; n=sys.argv[1]; print(next((str(a["id"]) for a in json.load(sys.stdin)["assets"] if a["name"] == n), ""))' "$name") \
67+
|| return 1
68+
[ -n "$id" ] || return 1
69+
echo "fetch_release: the web address failed; asking the API for asset $id" >&2
70+
curl -fsSL --retry 3 --retry-delay 2 --retry-all-errors --connect-timeout 20 --max-time 600 \
71+
"${auth[@]}" -H "Accept: application/octet-stream" \
72+
-o "$dest" "https://api.github.com/repos/$owner/$repo/releases/assets/$id"
73+
}
74+
4875
for i in $(seq 1 "$attempts"); do
4976
rm -f "$dest"
5077
# --retry-all-errors is what covers exit 52; the rest bound how long a single
@@ -53,7 +80,7 @@ for i in $(seq 1 "$attempts"); do
5380
if curl -fsSL \
5481
--retry 3 --retry-delay 2 --retry-all-errors \
5582
--connect-timeout 20 --max-time 600 \
56-
-o "$dest" "$url"; then
83+
-o "$dest" "$url" || { rm -f "$dest"; api_fetch; }; then
5784
if verify; then
5885
[ "$i" -eq 1 ] || echo "fetch_release: succeeded on attempt $i" >&2
5986
exit 0

0 commit comments

Comments
 (0)