68 行
2.6 KiB
Bash
68 行
2.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Build a distributable plugin archive from the *git* view of the tree.
|
|
#
|
|
# Why git archive instead of copying the working directory:
|
|
# The previous deploy scripts copied the whole folder, which swept up
|
|
# .env.imagestudio_codex_handoff.yaml (real API keys, DB password, admin
|
|
# credentials) into 19 published archives. .gitignore has no effect on a
|
|
# plain `cp -r`, but `git archive` only ever emits tracked files, so an
|
|
# ignored secret can no longer reach a package by construction.
|
|
#
|
|
# Usage:
|
|
# scripts/package_plugin.sh [ref] [outdir]
|
|
# Defaults: ref=HEAD, outdir=dist
|
|
|
|
set -euo pipefail
|
|
|
|
# Git for Windows may invoke this script from PowerShell with a PATH that omits
|
|
# its Unix core utilities. Restore them so git archive verification remains
|
|
# portable between Git Bash, PowerShell, and POSIX hosts.
|
|
if [[ -d /usr/bin ]]; then
|
|
PATH="/usr/bin:/bin:$PATH"
|
|
fi
|
|
|
|
REF="${1:-HEAD}"
|
|
OUTDIR="${2:-dist}"
|
|
PREFIX="astrbot_plugin_imagestudio/"
|
|
|
|
repo_root="$(git rev-parse --show-toplevel)"
|
|
cd "$repo_root"
|
|
|
|
if [[ "$REF" == "HEAD" ]] && { ! git diff --quiet || ! git diff --cached --quiet; }; then
|
|
echo "FATAL: HEAD has uncommitted tracked changes; commit first or pass an explicit ref." >&2
|
|
exit 2
|
|
fi
|
|
|
|
version="$(git describe --tags --always "$REF" 2>/dev/null || git rev-parse --short "$REF")"
|
|
mkdir -p "$OUTDIR"
|
|
archive="$OUTDIR/astrbot_plugin_imagestudio-$version.tar.gz"
|
|
|
|
git archive --format=tar.gz --prefix="$PREFIX" -o "$archive" "$REF"
|
|
|
|
# Git for Windows writes backslashes in git archive entries. Normalize the
|
|
# listing once so security and required-file assertions behave identically on
|
|
# Windows and POSIX hosts.
|
|
archive_paths() {
|
|
tar -tzf "$archive" | tr '\\' '/'
|
|
}
|
|
|
|
# Hard assertion: refuse to publish an archive that carries a secret-bearing
|
|
# file. This is the backstop that would have caught the 2026-07 leak.
|
|
if archive_paths | grep -nE '(^|/)(\.env|.*\.pem$|.*\.p12$|.*id_rsa.*|secrets?\.ya?ml)' ; then
|
|
echo "FATAL: secret-bearing path found in $archive — refusing to publish." >&2
|
|
rm -f "$archive"
|
|
exit 1
|
|
fi
|
|
|
|
# The plugin is unusable without the built frontend; these are tracked on
|
|
# purpose (AstrBot loads them from the package, there is no build step on the
|
|
# host). Fail loudly if they went missing rather than shipping a broken plugin.
|
|
for required in "${PREFIX}metadata.yaml" "${PREFIX}main.py" "${PREFIX}web/index.html" "${PREFIX}pages/imagestudio/index.html"; do
|
|
if ! archive_paths | grep -qx "$required"; then
|
|
echo "FATAL: $required missing from $archive — frontend not built?" >&2
|
|
rm -f "$archive"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
echo "$archive"
|