interplane.Get Omega
Read in your language

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

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>.<sha> (repo = Forgejo repository name, sha = full 40-hex new commit)
22# content one line: "<ref> <old-sha> <new-sha> <unix-time>" (ref = refs/heads/<branch>)
23# semantics the worker treats the file's presence as "please verify <repo> at <sha>"; 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 <repo> install the post-receive hook into the Forgejo bare repo
29# $OP_HOME/atlas-forgejo/data/git/repositories/drake/<repo>.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 <repo> the hook body (reads "old new ref" lines on stdin)
33# forgejo-webhook.sh list show pending trigger files
34set -euo pipefail
35OP_HOME=${AIEN_OPERATOR_HOME:-$HOME}
36TRIGGER_DIR=$OP_HOME/.local/state/aien-local-ci/trigger
37REPOS=$OP_HOME/atlas-forgejo/data/git/repositories/drake
38
39case "${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
62data=$(cat)
63exitcodes=""
64hookname=$(basename "$0")
65GIT_DIR=${GIT_DIR:-$(dirname "$0")/..}
66for hook in "$GIT_DIR"/hooks/"$hookname".d/*; do
67 test -x "$hook" && test -f "$hook" || continue
68 echo "$data" | "$hook"
69 exitcodes="$exitcodes $?"
70done
71for i in $exitcodes; do
72 [ "$i" -eq 0 ] || exit "$i"
73done
74EOF
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'
81mkdir -p "$TRIGGER_DIR"
82now=$(date +%s)
83while 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"
90done
91exit 0
92EOF
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.<sha>"
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 ;;
101esac