scorpiox-bot-plugin-sqlite
←release-dist.shbash
386 lines · 18 KBHEADBlameDownload
1#!/usr/bin/env bash
2# release-dist.sh — build, scan and publish plugin_disks to the plugin registry.
3#
4# Two paths:
5# A. Preferred: if `scorpiox-cli-botplugin` is installed, hand the whole job to it
6# (`scorpiox-cli-botplugin publish .`), which does the same work with a richer CLI.
7# B. Standalone (this script): secret scan -> multi-target build -> source.tar.gz ->
8# manifest.json + SHA256SUMS -> upload -> latest.json / index.json -> plugingit mirror.
9#
10# Nothing here contains a host address or a credential. Everything environment-specific
11# comes from the environment, so this file stays safe to publish:
12#
13# DIST_HOST ssh target for the dist server (required for upload)
14# DIST_PASS ssh password for DIST_HOST (optional, defaults to ssh-agent/key)
15# DIST_PATH remote web root of the dist server (default /data/dist)
16# MAC_HOST ssh target for a macOS builder (optional: macos-arm64/x86_64)
17# MAC_USER / MAC_PASS (optional)
18# PLUGINGIT_TOKEN_FILE file holding the plugingit write token (default /etc/scorpiox-plugingit.token)
19# PLUGINGIT_REMOTE public mirror URL to push into
20#
21# Usage:
22# ./release-dist.sh # full release
23# ./release-dist.sh --dry-run # build + stage in /tmp, no upload
24# ./release-dist.sh --no-macos # skip the macOS legs
25# ./release-dist.sh --no-mirror # skip the plugingit mirror
26
27set -euo pipefail
28
29SLUG="sqlite"
30ID="plugin_sqlite"
31VERSION="1.0.3"
32DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins"
33
34# Compile flags for the vendored SQLite amalgamation.
35SQLITE_DEFS="-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DQS=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_MAX_ATTACHED=0"
36
37ROOT="$(cd "$(dirname "$0")" && pwd)"
38cd "$ROOT"
39
40DRY_RUN=0
41DO_MACOS=1
42DO_MIRROR=1
43STANDALONE=0
44for arg in "$@"; do
45 case "$arg" in
46 --dry-run) DRY_RUN=1 ;;
47 --no-macos) DO_MACOS=0 ;;
48 --no-mirror) DO_MIRROR=0 ;;
49 --standalone) STANDALONE=1 ;;
50 -h|--help) sed -n '2,30p' "$0"; exit 0 ;;
51 *) echo "unknown argument: $arg" >&2; exit 2 ;;
52 esac
53done
54
55DIST_HOST="${DIST_HOST:-}"
56DIST_PASS="${DIST_PASS:-}"
57DIST_PATH="${DIST_PATH:-/data/dist}"
58PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}"
59PLUGINGIT_REMOTE="${PLUGINGIT_REMOTE:-https://plugingit.scorpiox.net/scorpiox-bot-plugin-${SLUG}.git}"
60
61STAGE="/tmp/${SLUG}-dist-${VERSION}-$$"
62mkdir -p "$STAGE"
63trap 'rm -rf "$STAGE"' EXIT
64
65say() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
66die() { printf '\033[31mERROR:\033[0m %s\n' "$1" >&2; exit 1; }
67
68# ---------------------------------------------------------------- 0. preflight
69say "0/7 preflight"
70
71if [ "$STANDALONE" -eq 0 ] && command -v scorpiox-cli-botplugin >/dev/null 2>&1; then
72 say "using scorpiox-cli-botplugin publish"
73 exec scorpiox-cli-botplugin publish "$ROOT"
74fi
75echo " running the standalone pipeline (dist + plugingit mirror)"
76
77if [ -n "$(git status --porcelain 2>/dev/null)" ]; then
78 echo " note: working tree is dirty; source.tar.gz comes from the last commit"
79fi
80COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
81echo " version $VERSION"
82echo " commit $COMMIT"
83
84# ---------------------------------------------------------------- 1. secret scan
85say "1/7 secret & LAN scan (full history)"
86
87SCAN_TMP="$STAGE/history.txt"
88# Scan every added/removed line of every commit. Two exclusions, both about the
89# audit rather than the code: the committer identity line, and any line that is
90# itself a scan definition — otherwise this file's own detector patterns read as
91# findings in every historical revision of it.
92git log -p --all 2>/dev/null \
93 | grep -v '^Author: ' \
94 | grep -vE 'scan "|HITS=|grep -E|P_ROOT=|P_WT=|\$ALL' \
95 > "$SCAN_TMP" || : > "$SCAN_TMP"
96HITS=0
97scan() { # scan <label> <regex>
98 local out
99 out=$(grep -Eo "$2" "$SCAN_TMP" 2>/dev/null | sort -u | head -5 || true)
100 if [ -n "$out" ]; then
101 printf ' \033[31mHIT\033[0m %s\n' "$1"
102 printf '%s\n' "$out" | sed 's/^/ /'
103 HITS=$((HITS + 1))
104 else
105 printf ' ok %s\n' "$1"
106 fi
107}
108scan "LAN IPs 192.168.x.x" '192\.168\.[0-9]+\.[0-9]+'
109scan "private 10.x.x.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+'
110scan "private 172.16-31.x.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+'
111scan "GitHub PAT" 'ghp_[A-Za-z0-9]{36}'
112scan "HuggingFace token" 'hf_[A-Za-z0-9]{30,}'
113scan "embedded git credentials" 'scorpioxinc:[A-Za-z0-9]{20,}'
114scan "hard-coded ssh password" 'sshpass -p [^"$]'
115P_ROOT="/codebases"
116P_PICOBOT="${P_ROOT}/pico""bot"
117P_WT=".work""trees"
118scan "internal fleet paths" "/root/tools|${P_PICOBOT}|${P_WT}"
119scan "run-token env assignment" 'RUNNER_'"PASS="
120if [ "$HITS" -ne 0 ]; then
121 die "secret scan found $HITS problem(s) — refusing to publish"
122fi
123echo " clean: 0 hits"
124
125# ---------------------------------------------------------------- 2. build
126say "2/7 build targets"
127
128build_ok() { [ -f "$1" ]; }
129
130# linux-x86_64 (glibc, native)
131if command -v cc >/dev/null 2>&1; then
132 cc -O1 -std=c99 -Wall -Wextra $SQLITE_DEFS -Ivendor -c vendor/sqlite3.c -o "$STAGE/sqlite3.o" \
133 || die "amalgamation build failed"
134 cc -O2 -std=c99 -Wall -Wextra $SQLITE_DEFS -Isrc -Ivendor -o "$STAGE/$ID" src/$ID.c "$STAGE/sqlite3.o" \
135 || die "native build failed"
136 echo " built linux-x86_64 (glibc) $(wc -c < "$STAGE/$ID" | tr -d ' ') bytes"
137else
138 die "no native cc found"
139fi
140
141# linux-x86_64-musl (fully static — the universal Linux artifact)
142if command -v musl-gcc >/dev/null 2>&1; then
143 musl-gcc -O1 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Ivendor -c vendor/sqlite3.c \
144 -o "$STAGE/sqlite3.musl.o" || die "musl amalgamation build failed"
145 musl-gcc -O2 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Isrc -Ivendor \
146 -o "$STAGE/$ID.musl" src/$ID.c "$STAGE/sqlite3.musl.o" || die "musl build failed"
147 echo " built linux-x86_64-musl $(wc -c < "$STAGE/$ID.musl" | tr -d ' ') bytes"
148else
149 echo " skip linux-x86_64-musl (no musl-gcc)"
150fi
151
152# linux-arm64-musl (static aarch64 - Raspberry Pi 5 / ARM64 servers).
153# Prefer musl; on a host that only has the Debian cross toolchain the static
154# glibc link still yields a self-contained aarch64 ELF.
155if command -v aarch64-linux-musl-gcc >/dev/null 2>&1; then
156 aarch64-linux-musl-gcc -O1 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Ivendor \
157 -c vendor/sqlite3.c -o "$STAGE/sqlite3.arm64.o" || die "arm64 musl amalgamation failed"
158 aarch64-linux-musl-gcc -O2 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Isrc -Ivendor \
159 -o "$STAGE/$ID.arm64" src/$ID.c "$STAGE/sqlite3.arm64.o" || die "arm64 musl build failed"
160 echo " built linux-arm64-musl $(wc -c < "$STAGE/$ID.arm64" | tr -d ' ') bytes"
161elif command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
162 aarch64-linux-gnu-gcc -O1 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Ivendor \
163 -c vendor/sqlite3.c -o "$STAGE/sqlite3.arm64.o" || die "arm64 amalgamation failed"
164 aarch64-linux-gnu-gcc -O2 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Isrc -Ivendor \
165 -o "$STAGE/$ID.arm64" src/$ID.c "$STAGE/sqlite3.arm64.o" || die "arm64 static build failed"
166 echo " built linux-arm64-static $(wc -c < "$STAGE/$ID.arm64" | tr -d ' ') bytes"
167else
168 echo " skip linux-arm64-musl (no aarch64 cross compiler)"
169fi
170
171# windows-x86_64 (static PE)
172if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
173 x86_64-w64-mingw32-gcc -O1 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Ivendor \
174 -c vendor/sqlite3.c -o "$STAGE/sqlite3.win.o" || die "MinGW amalgamation build failed"
175 x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static $SQLITE_DEFS -Isrc -Ivendor \
176 -o "$STAGE/$ID.exe" src/$ID.c "$STAGE/sqlite3.win.o" || die "MinGW build failed"
177 [ "$(head -c 2 "$STAGE/$ID.exe")" = "MZ" ] || die "windows artifact is not a PE"
178 echo " built windows-x86_64 $(wc -c < "$STAGE/$ID.exe" | tr -d ' ') bytes"
179else
180 echo " skip windows-x86_64 (no MinGW cross compiler)"
181fi
182
183# macOS legs — Mach-O must be produced by Apple clang on a real Mac.
184# Both slices are cross-built from one host: -arch arm64 and -arch x86_64.
185if [ "$DO_MACOS" -eq 1 ] && [ -n "${MAC_HOST:-}" ]; then
186 MAC_USER="${MAC_USER:-$(whoami)}"
187 MAC_DIR="/tmp/${ID}-mac-$$"
188 echo " building macOS legs on $MAC_HOST"
189 SSH_MAC=(ssh -o StrictHostKeyChecking=no)
190 SCP_MAC=(scp -o StrictHostKeyChecking=no)
191 if [ -n "${MAC_PASS:-}" ]; then
192 SSH_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SSH_MAC[@]}")
193 SCP_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SCP_MAC[@]}")
194 fi
195 if "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" "rm -rf '$MAC_DIR' && mkdir -p '$MAC_DIR/src' '$MAC_DIR/vendor'"; then
196 # Keep the repo layout: plugin_sqlite.c includes "../vendor/sqlite3.h".
197 if "${SCP_MAC[@]}" src/$ID.c "$MAC_USER@$MAC_HOST:$MAC_DIR/src/$ID.c" &&
198 "${SCP_MAC[@]}" vendor/sqlite3.c vendor/sqlite3.h "$MAC_USER@$MAC_HOST:$MAC_DIR/vendor/"; then
199 for slice in arm64 x86_64; do
200 if "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" \
201 "cd '$MAC_DIR' && clang -O1 -std=c99 -arch $slice $SQLITE_DEFS -c vendor/sqlite3.c -o sqlite3.$slice.o && clang -O2 -std=c99 -Wall -Wextra -arch $slice $SQLITE_DEFS -o $ID.$slice src/$ID.c sqlite3.$slice.o" \
202 2>/dev/null; then
203 "${SCP_MAC[@]}" "$MAC_USER@$MAC_HOST:$MAC_DIR/$ID.$slice" "$STAGE/$ID.macos-$slice" 2>/dev/null \
204 && echo " built macos-$slice ($(wc -c < "$STAGE/$ID.macos-$slice" | tr -d ' ') bytes)"
205 else
206 echo " warn: macos-$slice build failed on $MAC_HOST"
207 fi
208 done
209 "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" "rm -rf '$MAC_DIR'" 2>/dev/null || true
210 else
211 echo " warn: mac scp failed"
212 fi
213 else
214 echo " warn: mac host unreachable"
215 fi
216else
217 echo " skip macOS legs (set MAC_HOST/MAC_USER/MAC_PASS to include them)"
218fi
219
220# ---------------------------------------------------------------- 3. package
221say "3/7 package"
222
223git archive --format=tar.gz --prefix="${ID}-${VERSION}/" \
224 -o "$STAGE/source.tar.gz" HEAD 2>/dev/null \
225 || tar -czf "$STAGE/source.tar.gz" --exclude=.git .
226echo " source.tar.gz $(wc -c < "$STAGE/source.tar.gz" | tr -d ' ') bytes"
227
228target_meta() { # target_meta <key> <file> <format> <relpath> <name>
229 local key="$1" file="$2" fmt="$3" rel="$4" name="$5"
230 [ -f "$file" ] || return 0
231 local sha size
232 sha=$(sha256sum "$file" | awk '{print $1}')
233 size=$(wc -c < "$file" | tr -d ' ')
234 printf ' "%s": {"url": "%s/%s/%s/%s", "sha256": "%s", "size_bytes": %s, "format": "%s"}' \
235 "$key" "$DIST_BASE_URL" "$SLUG" "$VERSION" "$rel" "$sha" "$size" "$fmt"
236}
237
238{
239 printf '{\n'
240 printf ' "slug": "%s",\n' "$SLUG"
241 printf ' "id": "%s",\n' "$ID"
242 printf ' "name": "sqlite",\n'
243 printf ' "desc": "SQLite viewer",\n'
244 printf ' "title": "SQLite Explorer",\n'
245 printf ' "summary": "Zero-dependency, strictly read-only SQLite browser: discovers .db/.sqlite files under your workspace and home, shows tables, columns, indexes and row counts, and runs capped SELECT queries with a sortable result grid - the SQLite engine is compiled into the binary so no sqlite3 CLI, libsqlite3.so or sqlite3.dll is needed.",\n'
246 printf ' "category": "devtools",\n'
247 printf ' "version": "%s",\n' "$VERSION"
248 printf ' "license": "MIT",\n'
249 printf ' "trust_notice": "Executes native C code on your node. Opens databases with SQLITE_OPEN_READONLY and installs an authorizer that permits only SELECT, READ, FUNCTION and read-only PRAGMA statements, so INSERT/UPDATE/DELETE/DROP/ALTER/ATTACH/CREATE are refused by the engine. Only .db/.sqlite/.sqlite3 files under /workspace, /codebases, $HOME or $SQLITE_ALLOWED_ROOT are browsable; results are capped at 500 rows and about 2 seconds per statement. Makes zero outbound network requests and opens no sockets.",\n'
250 printf ' "capabilities": ["local_filesystem_read", "sqlite_readonly_open", "bounded_directory_walk"],\n'
251 printf ' "git_repo_url": "https://plugingit.scorpiox.net/scorpiox-bot-plugin-%s.git",\n' "$SLUG"
252 printf ' "git_web_url": "https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-%s",\n' "$SLUG"
253 printf ' "git_commit": "%s",\n' "$COMMIT"
254 printf ' "source_tarball_url": "%s/%s/%s/source.tar.gz",\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
255 printf ' "source_tarball_sha256": "%s",\n' "$(sha256sum "$STAGE/source.tar.gz" | awk '{print $1}')"
256 printf ' "build_cmd_posix": "make",\n'
257 printf ' "build_cmd_win64": "make win64",\n'
258 printf ' "published_at": "%s",\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
259 printf ' "targets": {\n'
260 first=1
261 emit() { if [ -f "$2" ]; then [ $first -eq 1 ] || printf ',\n'; first=0; target_meta "$@"; fi; }
262 emit "linux-x86_64" "$STAGE/$ID" "elf-x86_64" "linux-x86_64/$ID" "$ID"
263 emit "linux-x86_64-musl" "$STAGE/$ID.musl" "elf-x86_64-static" "linux-x86_64-musl/$ID" "$ID"
264 emit "linux-arm64-musl" "$STAGE/$ID.arm64" "elf-arm64-static" "linux-arm64-musl/$ID" "$ID"
265 emit "macos-arm64" "$STAGE/$ID.macos-arm64" "macho-arm64" "macos-arm64/$ID" "$ID"
266 emit "macos-x86_64" "$STAGE/$ID.macos-x86_64" "macho-x86_64" "macos-x86_64/$ID" "$ID"
267 emit "windows-x86_64" "$STAGE/$ID.exe" "pe-x86_64" "windows-x86_64/$ID.exe" "$ID"
268 printf '\n }\n}\n'
269} > "$STAGE/manifest.json"
270
271python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$STAGE/manifest.json" \
272 || die "generated manifest.json is not valid JSON"
273echo " manifest.json ok"
274
275# SHA256SUMS — relative paths, exactly as published
276( cd "$STAGE"
277 for f in source.tar.gz; do [ -f "$f" ] && sha256sum "$f"; done
278 [ -f "$ID" ] && sha256sum "$ID" | sed "s| $ID\$| linux-x86_64/$ID|"
279 [ -f "$ID.musl" ] && sha256sum "$ID.musl" | sed "s| $ID.musl\$| linux-x86_64-musl/$ID|"
280 [ -f "$ID.arm64" ] && sha256sum "$ID.arm64" | sed "s| $ID.arm64\$| linux-arm64-musl/$ID|"
281 [ -f "$ID.macos-arm64" ]&& sha256sum "$ID.macos-arm64"| sed "s| $ID.macos-arm64\$| macos-arm64/$ID|"
282 [ -f "$ID.macos-x86_64" ]&& sha256sum "$ID.macos-x86_64"| sed "s| $ID.macos-x86_64\$| macos-x86_64/$ID|"
283 [ -f "$ID.exe" ] && sha256sum "$ID.exe" | sed "s| $ID.exe\$| windows-x86_64/$ID.exe|"
284 true ) > "$STAGE/SHA256SUMS"
285echo " SHA256SUMS $(wc -l < "$STAGE/SHA256SUMS" | tr -d ' ') entries"
286
287# ---------------------------------------------------------------- 4. stage
288say "4/7 stage tree"
289PKG="$STAGE/pkg"
290mkdir -p "$PKG/linux-x86_64" "$PKG/linux-x86_64-musl" "$PKG/linux-arm64-musl" \
291 "$PKG/macos-arm64" "$PKG/macos-x86_64" "$PKG/windows-x86_64"
292cp -f "$STAGE/$ID" "$PKG/linux-x86_64/$ID"
293[ -f "$STAGE/$ID.musl" ] && cp -f "$STAGE/$ID.musl" "$PKG/linux-x86_64-musl/$ID"
294[ -f "$STAGE/$ID.arm64" ] && cp -f "$STAGE/$ID.arm64" "$PKG/linux-arm64-musl/$ID"
295[ -f "$STAGE/$ID.macos-arm64" ]&& cp -f "$STAGE/$ID.macos-arm64" "$PKG/macos-arm64/$ID"
296[ -f "$STAGE/$ID.macos-x86_64" ]&&cp -f "$STAGE/$ID.macos-x86_64" "$PKG/macos-x86_64/$ID"
297[ -f "$STAGE/$ID.exe" ] && cp -f "$STAGE/$ID.exe" "$PKG/windows-x86_64/$ID.exe"
298cp -f "$STAGE/manifest.json" "$STAGE/SHA256SUMS" "$STAGE/source.tar.gz" "$PKG/"
299chmod +x "$PKG"/*/$ID 2>/dev/null || true
300find "$PKG" -type f | sed 's/^/ /'
301
302if [ "$DRY_RUN" -eq 1 ]; then
303 say "dry run — staged at $STAGE/pkg (kept for inspection)"
304 trap - EXIT
305 exit 0
306fi
307
308# ---------------------------------------------------------------- 5. upload
309say "5/7 upload"
310
311[ -n "$DIST_HOST" ] || die "DIST_HOST is not set — cannot upload"
312SSH=(ssh -o StrictHostKeyChecking=no)
313SCP=(scp -o StrictHostKeyChecking=no)
314if [ -n "$DIST_PASS" ]; then
315 SSH=(scorpiox-sshpass -p "$DIST_PASS" "${SSH[@]}")
316 SCP=(scorpiox-sshpass -p "$DIST_PASS" "${SCP[@]}")
317fi
318REMOTE_DIR="$DIST_PATH/bot-plugins/$SLUG/$VERSION"
319
320"${SSH[@]}" "$DIST_HOST" "mkdir -p '$REMOTE_DIR' '$DIST_PATH/bot-plugins/$SLUG'" \
321 || die "cannot create $REMOTE_DIR on $DIST_HOST"
322# Stage to one tarball, transfer it, extract remotely. Streaming tar through
323# ssh corrupts on some OpenSSH builds (remote gzip dies with SIGPIPE), and
324# OpenSSH 9 refuses to scp a bare "." source.
325tar -czf "$STAGE/pkg.tar.gz" -C "$PKG" . || die "packaging failed"
326"${SCP[@]}" -q "$STAGE/pkg.tar.gz" "$DIST_HOST:$REMOTE_DIR/pkg.tar.gz" || die "upload failed"
327"${SSH[@]}" "$DIST_HOST" "cd '$REMOTE_DIR' && tar -xzf pkg.tar.gz && rm -f pkg.tar.gz" \
328 || die "remote extract failed"
329echo " uploaded to $DIST_HOST:$REMOTE_DIR"
330
331# latest.json = copy of this version's manifest
332"${SSH[@]}" "$DIST_HOST" "cp -f '$REMOTE_DIR/manifest.json' '$DIST_PATH/bot-plugins/$SLUG/latest.json'" \
333 || die "latest.json update failed"
334echo " updated bot-plugins/$SLUG/latest.json"
335
336# index.json — merge, preserving every sibling <slug>/latest.json
337say "index.json merge"
338"${SSH[@]}" "$DIST_HOST" "cd '$DIST_PATH/bot-plugins' && python3 - '$SLUG' <<'PY'
339import json, os, sys, glob
340slug = sys.argv[1]
341entries = {}
342for p in sorted(glob.glob('*/latest.json')):
343 s = os.path.dirname(p)
344 try:
345 entries[s] = json.load(open(p))
346 except Exception:
347 pass
348index = {
349 'ok': True,
350 'service': 'bot-plugins-dist',
351 'dist_base_url': 'https://dist.scorpiox.net/bot-plugins',
352 'count': len(entries),
353 'slugs': sorted(entries),
354 'plugins': [entries[k] for k in sorted(entries)],
355}
356open('index.json.tmp', 'w').write(json.dumps(index, indent=2) + chr(10))
357os.replace('index.json.tmp', 'index.json')
358print(' index.json now has %d plugin(s): %s' % (len(entries), ', '.join(sorted(entries))))
359PY" || die "index.json merge failed"
360
361# ---------------------------------------------------------------- 6. mirror
362say "6/7 plugingit mirror"
363if [ "$DO_MIRROR" -eq 1 ] && [ -f "$PLUGINGIT_TOKEN_FILE" ]; then
364 TOKEN=$(tr -d ' \r\n' < "$PLUGINGIT_TOKEN_FILE")
365 AUTH_REMOTE=$(printf '%s' "$PLUGINGIT_REMOTE" | sed "s|https://|https://x-access-token:${TOKEN}@|")
366 git push --all "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || die "mirror push failed"
367 git push --tags "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || true
368 echo " mirrored to $PLUGINGIT_REMOTE"
369else
370 echo " skip (no $PLUGINGIT_TOKEN_FILE or --no-mirror)"
371fi
372
373# ---------------------------------------------------------------- 7. verify
374say "7/7 verify"
375CODE=$(curl -fsS -o "$STAGE/latest.check" -w '%{http_code}' \
376 "$DIST_BASE_URL/$SLUG/latest.json" || echo 000)
377if [ "$CODE" = "200" ]; then
378 python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(" latest.json OK — %s v%s, %d target(s)" % (d["slug"], d["version"], len(d["targets"])))' \
379 "$STAGE/latest.check" || echo " warn: latest.json is not valid JSON"
380else
381 echo " warn: $DIST_BASE_URL/$SLUG/latest.json returned HTTP $CODE"
382fi
383
384printf '\n\033[1mrelease complete\033[0m\n'
385printf ' registry %s/%s/%s/\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
386printf ' manifest %s/%s/%s/manifest.json\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"