Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/tools/aien-local-ci/forgejo-webhook.sh # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / tools / aien-local-ci / forgejo-webhook.sh` 101 lines ยท 4407 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # forgejo-webhook.sh: offline push trigger for the trusted worker (A3). 18 # 19 # Trigger file contract (consumed by `aien-test worker`, lane ENGINE): 20 # directory $OP_HOME/.local/state/aien-local-ci/trigger/ (OP_HOME = $AIEN_OPERATOR_HOME, default $HOME) 21 # file name . (repo = Forgejo repository name, sha = full 40-hex new commit) 22 # content one line: " " (ref = refs/heads/) 23 # semantics the worker treats the file's presence as "please verify at "; it deletes the file when 24 # the run is recorded. A deleted branch (new-sha all zeros) writes no file. Re-pushing the same sha 25 # rewrites the same file (idempotent). No network, no HTTP receiver: Forgejo's post-receive hook 26 # runs as the operator on this host and writes the file directly. 27 # 28 # forgejo-webhook.sh install install the post-receive hook into the Forgejo bare repo 29 # $OP_HOME/atlas-forgejo/data/git/repositories/drake/.git 30 # (hooks/post-receive runs every hooks/post-receive.d/*, Forgejo's own layout, 31 # so a later "resynchronize hooks" from the admin page keeps our script) 32 # forgejo-webhook.sh hook the hook body (reads "old new ref" lines on stdin) 33 # forgejo-webhook.sh list show pending trigger files 34 set -euo pipefail 35 OP_HOME=${AIEN_OPERATOR_HOME:-$HOME} 36 TRIGGER_DIR=$OP_HOME/.local/state/aien-local-ci/trigger 37 REPOS=$OP_HOME/atlas-forgejo/data/git/repositories/drake 38 39 case "${1:-}" in 40 hook) 41 repo=${2:?repo} 42 mkdir -p "$TRIGGER_DIR" 43 now=$(date +%s) 44 while read -r old new ref; do 45 [[ $new =~ ^[0-9a-f]{40}$ ]] || continue 46 [[ $new != `0000000000000000000000000000000000000000` ]] || continue 47 [[ $ref == refs/heads/* ]] || continue 48 tmp="$TRIGGER_DIR/.$repo.$new.$$" 49 printf '%s %s %s %s\n' "$ref" "$old" "$new" "$now" > "$tmp" 50 mv -f "$tmp" "$TRIGGER_DIR/$repo.$new" 51 done 52 ;; 53 install) 54 repo=${2:?repo} 55 [[ $repo =~ ^[A-Za-z0-9._-]+$ ]] || { echo "bad repo" >&2; exit 2; } 56 bare="$REPOS/$repo.git" 57 [[ -d $bare && -f $bare/HEAD ]] || { echo "no bare repo at $bare" >&2; exit 2; } 58 mkdir -p "$bare/hooks/post-receive.d" 59 if [[ ! -f $bare/hooks/post-receive ]]; then 60 cat > "$bare/hooks/post-receive" <<'EOF' 61 #!/usr/bin/env bash 62 data=$(cat) 63 exitcodes="" 64 hookname=$(basename "$0") 65 GIT_DIR=${GIT_DIR:-$(dirname "$0")/..} 66 for hook in "$GIT_DIR"/hooks/"$hookname".d/*; do 67 test -x "$hook" && test -f "$hook" || continue 68 echo "$data" | "$hook" 69 exitcodes="$exitcodes $?" 70 done 71 for i in $exitcodes; do 72 [ "$i" -eq 0 ] || exit "$i" 73 done 74 EOF 75 chmod 0755 "$bare/hooks/post-receive" 76 fi 77 { 78 printf '#!/usr/bin/env bash\n# installed by tools/aien-local-ci/forgejo-webhook.sh (sovereign-core); writes the worker trigger file\n' 79 printf 'TRIGGER_DIR=%q\nrepo=%q\n' "$TRIGGER_DIR" "$repo" 80 cat <<'EOF' 81 mkdir -p "$TRIGGER_DIR" 82 now=$(date +%s) 83 while read -r old new ref; do 84 [[ $new =~ ^[0-9a-f]{40}$ ]] || continue 85 [[ $new != `0000000000000000000000000000000000000000` ]] || continue 86 [[ $ref == refs/heads/* ]] || continue 87 tmp="$TRIGGER_DIR/.$repo.$new.$$" 88 printf '%s %s %s %s\n' "$ref" "$old" "$new" "$now" > "$tmp" 89 mv -f "$tmp" "$TRIGGER_DIR/$repo.$new" 90 done 91 exit 0 92 EOF 93 } > "$bare/hooks/post-receive.d/aien-local-ci" 94 chmod 0755 "$bare/hooks/post-receive.d/aien-local-ci" 95 echo "installed $bare/hooks/post-receive.d/aien-local-ci -> $TRIGGER_DIR/$repo." 96 ;; 97 list) 98 ls -l "$TRIGGER_DIR" 2>/dev/null || echo "no trigger dir" 99 ;; 100 *) sed -n '2,18p' "$0" >&2; exit 2 ;; 101 esac