#!/usr/bin/env bash # The socialweb-computer the staging run (test) puts under test: `release`'s linux/amd64 of this commit: the bucket's main// when release has published it (main), # else, on a branch, what release pushed to ttl.sh (an anonymous, ephemeral # OCI registry: no credential, so a fork's run works) by scripts/oci-push.sh, its manifest-digest reference this commit's release run's artifact oci/binary.ref. # It is pulled by digest (scripts/oci-pull.sh: oras checks every part against the manifest) to $CI_HOME/swc-under-test (default /home/r2; by hand scripts/ci-test.sh sets it), and the requester spec the staging VMs get # it by is written to $CI_HOME/requester.spec as `oci:@sha256:`: each VM pulls it the same way. Nothing here builds a binary: release is # the only workflow that compiles anything. With no reference (release did not run for this commit, or ttl.sh refused its push) this fails and says so. set -euo pipefail bin=socialweb-computer-linux-amd64 home=${CI_HOME:-/home/r2} out=$home/swc-under-test spec=$home/requester.spec own=(); [ "$(id -u)" = 0 ] && own=(-o r2) mkdir -p "$home" base=https://socialweb-computer-kcp.sfo3.digitaloceanspaces.com sha=$(git rev-parse HEAD) # on main release's last steps have published this commit (main//) before `test` runs: the public bucket serves it, checked against its SHA256SUMS, and the # staging VMs download it the same way (requester spec `sha:`) if curl -fsI -o /dev/null "$base/main/$sha/binaries/SHA256SUMS"; then echo "binary: main/$sha (published by release)" tmp=$(mktemp -d) curl -fsSL --retry 3 -o "$tmp/$bin" "$base/main/$sha/binaries/$bin" curl -fsSL --retry 3 "$base/main/$sha/binaries/SHA256SUMS" | grep " $bin\$" > "$tmp/SUMS" (cd "$tmp" && sha256sum -c --quiet SUMS) install -D -m 0755 "${own[@]}" "$tmp/$bin" "$out" rm -rf "$tmp" echo "sha:$sha" > "$spec" "$out" version | sed -n 1p echo "requester $(cat "$spec")" exit 0 fi # by hand (no CI run): the hand build of this commit, local// (scripts/ci-release.sh publish with no CI ref) if [ -z "${KNOTLESS_RUN_REF:-}" ] && curl -fsI -o /dev/null "$base/local/$sha/binaries/SHA256SUMS"; then echo "binary: local/$sha (a hand build)" tmp=$(mktemp -d) curl -fsSL --retry 3 -o "$tmp/$bin" "$base/local/$sha/binaries/$bin" curl -fsSL --retry 3 "$base/local/$sha/binaries/SHA256SUMS" | grep " $bin\$" > "$tmp/SUMS" (cd "$tmp" && sha256sum -c --quiet SUMS) install -D -m 0755 "${own[@]}" "$tmp/$bin" "$out" rm -rf "$tmp" echo "local:$sha" > "$spec" "$out" version | sed -n 1p echo "requester $(cat "$spec")" exit 0 fi ref= if [ -n "${KNOTLESS_ARTIFACTS_URL:-}" ]; then ref=$(curl -sf -H "Authorization: Bearer $KNOTLESS_ARTIFACTS_TOKEN" "$KNOTLESS_ARTIFACTS_URL?workflow=release&name=oci/binary.ref" || true) case "$ref" in ttl.sh/swc-*@sha256:????????????????????????????????????????????????????????????????) ;; *) ref= ;; esac fi if [ -z "$ref" ]; then echo "binary: this commit's release run left no oci/binary.ref (it did not run for this commit, or ttl.sh refused its push): there is no binary to put under test" >&2 exit 1 fi echo "binary: release's linux/amd64 of this commit, $ref" tmp=$(mktemp -d) bash scripts/oci-pull.sh "$ref" "$tmp" [ -f "$tmp/$bin" ] || { echo "binary: the artifact has no $bin" >&2; exit 1; } install -D -m 0755 "${own[@]}" "$tmp/$bin" "$out" rm -rf "$tmp" echo "oci:$ref" > "$spec" "$out" version | sed -n 1p echo "requester $(cat "$spec")"