sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / tests / forkpush / expected.sh
| 1 | #!/bin/sh |
| 2 | # fork-push: push the fork-only branches of my personal GitHub forks to their Radicle projects. |
| 3 | # Generated by tools/forkpush.om from stack/FORKS.tsv; do not edit by hand. |
| 4 | # |
| 5 | # For every stack/FORKS.tsv row whose action is radicle, it fetches the branch from |
| 6 | # https://github.com/<owner>/<repo> into a Radicle working copy of the project, checks that the |
| 7 | # fetched commit is the head the manifest names, and only then pushes it to Radicle as |
| 8 | # fork/<branch>. Rows kept private and rows already in this repository are listed below as |
| 9 | # comments and are never fetched or pushed. |
| 10 | # |
| 11 | # Needs git, and rad authenticated as the project's delegate with its node running |
| 12 | # (rad auth, rad node start). It refuses to run as root. |
| 13 | # FP_DIR=path the one directory it creates and works in (default ./fork-push); each project |
| 14 | # is cloned there once, into a directory named after its RID without rad: |
| 15 | # Exit status: 0 every branch OK, 2 a fetched commit is not the manifest head, |
| 16 | # 3 a clone, fetch or push failed (3 wins over 2). |
| 17 | # Manifest: 3 to push to Radicle, 1 kept private, 1 in this repository. |
| 18 | |
| 19 | set -eu |
| 20 | umask 022 |
| 21 | |
| 22 | FP_DIR="${FP_DIR:-./fork-push}" |
| 23 | fp_say() { printf '%s\n' "$*"; } |
| 24 | fp_die() { printf 'fork-push: %s\n' "$*" >&2; exit 1; } |
| 25 | |
| 26 | if [ "$(id -u)" = "0" ]; then fp_die "refusing to run as root; run it as your own user"; fi |
| 27 | command -v git >/dev/null 2>&1 || fp_die "git is required: https://git-scm.com" |
| 28 | command -v rad >/dev/null 2>&1 || fp_die "rad is required: https://radicle.xyz" |
| 29 | mkdir -p -- "$FP_DIR" |
| 30 | cd -- "$FP_DIR" |
| 31 | fp_ok=0 |
| 32 | fp_bad=0 |
| 33 | fp_fail=0 |
| 34 | |
| 35 | fp() { |
| 36 | fp_d="${1#rad:}" |
| 37 | if [ ! -d "$fp_d" ]; then |
| 38 | if ! rad clone "$1" "$fp_d" </dev/null; then |
| 39 | fp_say "FAILED $1 rad clone" |
| 40 | fp_fail=$((fp_fail + 1)) |
| 41 | rm -rf -- "./$fp_d" |
| 42 | return 0 |
| 43 | fi |
| 44 | fi |
| 45 | if ! git -C "$fp_d" fetch --no-tags --quiet "https://github.com/$2" "+refs/heads/$3:refs/heads/fork/$3" </dev/null; then |
| 46 | fp_say "FAILED $1 fork/$3 fetch from https://github.com/$2" |
| 47 | fp_fail=$((fp_fail + 1)) |
| 48 | return 0 |
| 49 | fi |
| 50 | fp_got="$(git -C "$fp_d" rev-parse "refs/heads/fork/$3" 2>/dev/null || true)" |
| 51 | if [ "$fp_got" != "$4" ]; then |
| 52 | fp_say "MISMATCH $1 fork/$3 manifest $4, fetched ${fp_got:-none}" |
| 53 | fp_bad=$((fp_bad + 1)) |
| 54 | return 0 |
| 55 | fi |
| 56 | if git -C "$fp_d" push --quiet rad "refs/heads/fork/$3:refs/heads/fork/$3" </dev/null; then |
| 57 | fp_say "OK $1 fork/$3 $4" |
| 58 | fp_ok=$((fp_ok + 1)) |
| 59 | else |
| 60 | fp_say "FAILED $1 fork/$3 push" |
| 61 | fp_fail=$((fp_fail + 1)) |
| 62 | fi |
| 63 | } |
| 64 | |
| 65 | fp 'rad:zAAAA1111' 'me/alpha' 'feat/one' '0123456789abcdef0123456789abcdef01234567' |
| 66 | # private, kept off Radicle: me/alpha fix/crypto-x |
| 67 | fp 'rad:zAAAA1111' 'me/alpha' 'docs/v1.2_x' 'fedcba9876543210fedcba9876543210fedcba98' |
| 68 | # in this repository at docs/site: me/beta.site main |
| 69 | fp 'rad:zBBBB2222' 'me/gamma-1' 'node-8d75/run_2' 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' |
| 70 | |
| 71 | fp_say "" |
| 72 | fp_say "Done in $(pwd): $fp_ok OK, $fp_bad MISMATCH, $fp_fail FAILED." |
| 73 | if [ "$fp_fail" -gt 0 ]; then exit 3; fi |
| 74 | if [ "$fp_bad" -gt 0 ]; then exit 2; fi |
| 75 | exit 0 |