0
0
#!/usr/bin/env bash
# 0009's page for `test`: the requester page (web/webrtc with its four wasm modules and their module.json, the round's two
# scripts, COMMIT) built from the commits pinned in tests/compositions/staging/page-tools.json `page` (the requester repo
# and atlibs; move a pin: edit there, both commits are printed here) and published as tests/publish-test-host.sh publishes
# the test host. The one script of CI's `release` (scripts/ci-release.sh page) and of a hand run.
# scripts/ci-page.sh build and publish; nothing is built when <bucket>/page/<key>/SHA256SUMS is there
# scripts/ci-page.sh key the key: sha256 of the pin object (jq -cS .page)
# With SPACES_ACCESS_KEY_ID in the environment (CI on main and v* tags; by hand the key file sourced into this one command):
# page/<key>/page.tar.gz, SHA256SUMS last. Without one (a branch's CI run, a hand rehearsal): nothing is published, the payload
# is built into DIST, an absolute path, as page.tar.gz and page.SHA256SUMS (the release workflow keeps dist/ as the run's
# artifacts; `test` reads it). PAGE_WORK (default ~/.tmp/ci-page) holds the clones and the build, removed at the end.
# The tarball unpacks to page/: what SWC_PAGE_REPO names (scripts/ci-test.sh page).
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
pins=tests/compositions/staging/page-tools.json
export SPACES_BUCKET=${SPACES_BUCKET:-socialweb-computer-kcp} SPACES_REGION=${SPACES_REGION:-sfo3}
base="https://$SPACES_BUCKET.$SPACES_REGION.digitaloceanspaces.com"
key=$(jq -ceS .page "$pins" | sha256sum | cut -d' ' -f1)
if [ "${1:-}" = key ]; then echo "$key"; exit 0; fi
pin() { jq -er --arg r "$1" --arg k "$2" '.page[$r][$k]' "$pins"; }
echo "page: requester $(pin requester commit) of $(pin requester url)"
echo "page: atlibs $(pin atlibs commit) of $(pin atlibs url)"
echo "page: key $key"
if curl -sfo /dev/null "$base/page/$key/SHA256SUMS"; then
echo "page/$key/ is published: nothing to build"
exit 0
fi
if [ -z "${SPACES_ACCESS_KEY_ID:-}" ]; then
: "${DIST:?no SPACES_ACCESS_KEY_ID and no DIST to build into}"
mkdir -p "$DIST"
publish() { :; }
else
: "${SPACES_SECRET_ACCESS_KEY:?}"
DIST=""
publish() { deno run -A --no-lock scripts/publish-spaces.ts --dir "$1" --prefix "$2" --content-addressed; }
fi
work=${PAGE_WORK:-$HOME/.tmp/ci-page}
src="$work/$key" out="$work/out" sums="$work/sums"
rm -rf "$src" "$out" "$sums" && mkdir -p "$src" "$out" "$sums"
# siblings: web/webrtc/modules links ../../../../atlibs/..., so atlibs is a directory of that name beside the requester checkout
for r in requester atlibs; do
for i in 1 2 3 4; do
rm -rf "${src:?}/$r"
git clone -q "$(pin "$r" url)" "$src/$r" && break
echo "page: clone of $r: attempt $i failed" >&2
[ "$i" -lt 4 ] || exit 1
sleep $((i * 15))
done
git -C "$src/$r" checkout -q --detach "$(pin "$r" commit)"
done
echo "page: $(rustc --version), $(cargo --version)"
# only what the page loads: three modules of the requester workspace, one of atlibs; each repo's target/ is where its links point
(cd "$src/requester" && CARGO_TARGET_DIR="$PWD/target" cargo wasm --locked -p requester -p user-data -p policy-requester-tangled-vouch >&2)
(cd "$src/atlibs" && CARGO_TARGET_DIR="$PWD/target" cargo wasm --locked -p iroh-user-data >&2)
mkdir -p "$src/page/web" "$src/page/scripts"
cp -rL "$src/requester/web/webrtc" "$src/page/web/"
cp "$src/requester/scripts/page-round.mjs" "$src/requester/scripts/browser.mjs" "$src/page/scripts/"
git -C "$src/requester" rev-parse HEAD > "$src/page/COMMIT"
tar -C "$src" --sort=name --owner=0 --group=0 --numeric-owner -czf "$out/page.tar.gz" page
tar -tzf "$out/page.tar.gz"
(cd "$src/page/web/webrtc/modules" && sha256sum ./*.wasm)
(cd "$out" && sha256sum page.tar.gz > "$sums/SHA256SUMS" && cat "$sums/SHA256SUMS")
publish "$out" "page/$key"
publish "$sums" "page/$key"
[ -z "$DIST" ] || { cp "$out/page.tar.gz" "$DIST/" && cp "$sums/SHA256SUMS" "$DIST/page.SHA256SUMS"; }
rm -rf "$src" "$out" "$sums"
if [ -z "$DIST" ]; then echo "$base/page/$key/"; else echo "built into $DIST (unpublished, no bucket key)"; fi