~ knotless Search/
↑↓ move↵ open⇧↵ all results

socialweb.computer/socialweb-computer-kcp

socialweb.computer: a compute market on atproto (kcp)

1 collaborator
0
0
33 lines · 2.3 KB Raw History
#!/usr/bin/env bash
# The staging gate of one commit: the `test` workflow's check and its step log's `gate: staging: K of M PASS` line
# (scripts/ci-test.sh staging).
#   scripts/ci-staging-total.sh <commit> [--wait <secs>]
# Prints `test: <status> K of M PASS`, then `gate: staging: N of 47 PASS` (47: the staging entries of tests/entries.txt).
# Exit 0: the check ended success with its line, and N is the whole list. Exit 3: not decided yet (queued or running, or
# no check). Exit 1: anything else (a failure, a cancel, a skip, no line, N short). `did the staging gate of this commit
# pass` is this exit code. --wait: `knotless run list --wait` for the check to be filed.
# KNOTLESS_REPO (default knotless://socialweb.computer/socialweb-computer-kcp), KNOTLESS_APPVIEW (default
# https://knotless.socialweb.computer), KNOTLESS (the CLI, default knotless).
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
commit=${1:?usage: scripts/ci-staging-total.sh <commit> [--wait <secs>]}
wait_args=()
if [ "${2:-}" = --wait ]; then wait_args=(--wait "${3:?--wait <secs>}"); fi
repo=${KNOTLESS_REPO:-knotless://socialweb.computer/socialweb-computer-kcp}
export KNOTLESS_APPVIEW=${KNOTLESS_APPVIEW:-https://knotless.socialweb.computer}
want=$(tests/gate.sh --list staging | wc -l)
log=$("${KNOTLESS:-knotless}" run list "$repo" --workflow test --commit "$commit" --log "${wait_args[@]}" 2>&1) || log=
# the newest check of the workflow at this commit: the first run line (status, workflow, ref, sha, startedAt; tab-separated)
status=$(awk -F'\t' '$2 == "test" && $1 ~ /^(queued|running|success|failure|skipped|cancelled)$/ { print $1; exit }' <<<"$log")
# that check's own log: up to the next run line (an older attempt)
line=$(awk -F'\t' '$1 ~ /^(queued|running|success|failure|skipped|cancelled)$/ && NF >= 4 { if (seen++) exit } seen' <<<"$log" \
  | grep -oE "gate: staging: [0-9]+ of [0-9]+ PASS" | tail -1 || true)
k=$(awk '{print $3}' <<<"$line") m=$(awk '{print $5}' <<<"$line")
if [ -n "$line" ]; then echo "test: ${status:-no check} $k of $m PASS"; else echo "test: ${status:-no check}, no gate line"; fi
rc=1
case ${status:-none} in
  success) [ -n "$line" ] && [ "$m" = "$want" ] && [ "$k" = "$want" ] && rc=0 ;;
  queued|running|none) rc=3 ;;
esac
echo "gate: staging: ${k:-0} of $want PASS"
exit $rc