Something went wrong. Try again.
Shuttle runs GitLab CI pipelines for Tangled repositories on an ordinary GitLab runner, and publishes the job logs to the repository owner's tangled.org/dracoblue.de/shuttle
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109#!/usr/bin/env bashset -euo pipefail
config_dir="$HOME/.config/shuttle-test"env_file="$config_dir/.env"key_file="$config_dir/id_ed25519"knot_url="http://127.0.0.1:5555"knot_did="did:web:knot.example.org"
if [[ ! -f "$env_file" ]]; then echo "missing $env_file" >&2 exit 1fiset -a# shellcheck disable=SC1090source "$env_file"set +a: "${SHUTTLE_TEST_HANDLE:?missing SHUTTLE_TEST_HANDLE}": "${SHUTTLE_TEST_PASSWORD:?missing SHUTTLE_TEST_PASSWORD}": "${SHUTTLE_TEST_DID:=did:plc:tdw3iqyznnma3t2ylthfpyd5}": "${SHUTTLE_TEST_PDS:=https://auriporia.us-west.host.bsky.network}"
mkdir -p "$config_dir"chmod 700 "$config_dir"if [[ ! -f "$key_file" ]]; then ssh-keygen -q -t ed25519 -N '' -C shuttle-dev -f "$key_file"fichmod 600 "$key_file"
# Tokens remain shell variables. Curl receives responses through pipes, never files.session=$(jq -nc --arg identifier "$SHUTTLE_TEST_HANDLE" --arg password "$SHUTTLE_TEST_PASSWORD" \ '{identifier:$identifier,password:$password}' | \ curl -fsS "$SHUTTLE_TEST_PDS/xrpc/com.atproto.server.createSession" \ -H 'Content-Type: application/json' --data-binary @-)access_jwt=$(jq -er '.accessJwt' <<<"$session")session=created_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)public_key=$(<"$key_file.pub")
put_record() { local collection=$1 rkey=$2 record=$3 jq -nc --arg repo "$SHUTTLE_TEST_DID" --arg collection "$collection" \ --arg rkey "$rkey" --argjson record "$record" \ '{repo:$repo,collection:$collection,rkey:$rkey,record:$record}' | \ curl -fsS "$SHUTTLE_TEST_PDS/xrpc/com.atproto.repo.putRecord" \ -H 'Content-Type: application/json' -H "Authorization: Bearer $access_jwt" \ --data-binary @- >/dev/null}
key_record=$(jq -nc --arg key "$public_key" --arg createdAt "$created_at" \ '{"$type":"sh.tangled.publicKey",key:$key,name:"Shuttle development",createdAt:$createdAt}')put_record sh.tangled.publicKey shuttle-dev "$key_record"echo "public key record: sh.tangled.publicKey/shuttle-dev"
if [[ -n "${SHUTTLE_TEST_REPO_DID:-}" ]]; then describe=$(curl -sS -H 'Host: knot.example.org' \ --get "$knot_url/xrpc/sh.tangled.repo.describeRepo" \ --data-urlencode "repoDid=$SHUTTLE_TEST_REPO_DID" -w $'\n%{http_code}') status=${describe##*$'\n'} body=${describe%$'\n'*} if [[ "$status" != 200 ]]; then echo "describeRepo failed ($status): $body" >&2 exit 1 fi echo "describeRepo response: $body"else service_auth_response=$(curl -sS --get \ "$SHUTTLE_TEST_PDS/xrpc/com.atproto.server.getServiceAuth" \ -H "Authorization: Bearer $access_jwt" --data-urlencode "aud=$knot_did" \ --data-urlencode 'lxm=sh.tangled.repo.create' -w $'\n%{http_code}') status=${service_auth_response##*$'\n'} service_auth=${service_auth_response%$'\n'*} service_auth_response= if [[ "$status" != 200 ]]; then echo "getServiceAuth failed ($status): $service_auth" >&2 exit 1 fi service_jwt=$(jq -er '.token' <<<"$service_auth") service_auth= echo "getServiceAuth: succeeded (aud=$knot_did, lxm=sh.tangled.repo.create)"
# This request is deliberately issued exactly once. Never add retry logic here. create_response=$(jq -nc \ '{rkey:"shuttle-test",name:"shuttle-test",defaultBranch:"main"}' | \ curl -sS -H 'Host: knot.example.org' "$knot_url/xrpc/sh.tangled.repo.create" \ -H 'Content-Type: application/json' -H "Authorization: Bearer $service_jwt" \ --data-binary @- -w $'\n%{http_code}') service_jwt= status=${create_response##*$'\n'} body=${create_response%$'\n'*} echo "repo.create response ($status): $body" minted_did=$(jq -er '.repoDid // .did // empty' <<<"$body" || true) if [[ -n "$minted_did" ]]; then printf '\nSHUTTLE_TEST_REPO_DID=%s\n' "$minted_did" >>"$env_file" export SHUTTLE_TEST_REPO_DID=$minted_did echo "recorded minted repo DID immediately: $minted_did" fi if [[ "$status" != 200 || -z "$minted_did" ]]; then echo "repo.create failed; it will not be retried" >&2 exit 1 fifi
repo_record=$(jq -nc --arg knot knot.example.org --arg repoDid "$SHUTTLE_TEST_REPO_DID" \ --arg createdAt "$created_at" \ '{"$type":"sh.tangled.repo",knot:$knot,repoDid:$repoDid,name:"shuttle-test",createdAt:$createdAt}')put_record sh.tangled.repo shuttle-test "$repo_record"echo "repo record: sh.tangled.repo/shuttle-test ($SHUTTLE_TEST_REPO_DID)"