67 lines
2.1 KiB
Bash
67 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Build the minimal TSL playbook bundle and publish its *expanded* contents to
|
|
# the tsl-playbook branch. The branch tree mirrors the bundle root directly
|
|
# (AGENTS.md, docs/, skills/) — there is no wrapping tsl-playbook/ directory.
|
|
|
|
REPO_DIR="${REPO_DIR:-$(pwd)}"
|
|
TARGET_BRANCH="${TARGET_BRANCH:-tsl-playbook}"
|
|
BUILD_SCRIPT="${BUILD_SCRIPT:-scripts/build_tsl_playbook.py}"
|
|
COMMIT_AUTHOR_NAME="${COMMIT_AUTHOR_NAME:-ci[bot]}"
|
|
COMMIT_AUTHOR_EMAIL="${COMMIT_AUTHOR_EMAIL:-ci-bot@local}"
|
|
|
|
cd "$REPO_DIR"
|
|
|
|
git config user.name "$COMMIT_AUTHOR_NAME"
|
|
git config user.email "$COMMIT_AUTHOR_EMAIL"
|
|
|
|
source_sha="$(git rev-parse HEAD)"
|
|
source_short="$(git rev-parse --short HEAD)"
|
|
|
|
# Build the bundle into a temp dir *outside* the repo so that resetting the
|
|
# target branch's working tree can never clobber the freshly built artifact.
|
|
build_dir="$(mktemp -d)"
|
|
cleanup() {
|
|
rm -rf "$build_dir"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
bundle="$build_dir/tsl-playbook"
|
|
python3 "$BUILD_SCRIPT" --output "$bundle"
|
|
|
|
# Check out (or create) the target branch. It is a content-only branch that
|
|
# shares no history with main, so an orphan branch keeps it clean.
|
|
if git show-ref --verify --quiet "refs/remotes/origin/$TARGET_BRANCH"; then
|
|
git fetch origin "$TARGET_BRANCH"
|
|
git checkout -B "$TARGET_BRANCH" "origin/$TARGET_BRANCH"
|
|
else
|
|
git checkout --orphan "$TARGET_BRANCH"
|
|
fi
|
|
|
|
# Replace the entire tracked tree with the bundle contents. `git rm` clears
|
|
# tracked files; then copy the expanded bundle to the repo root.
|
|
git rm -rf --quiet . >/dev/null 2>&1 || true
|
|
|
|
# Copy bundle contents (including dotfiles) to the repo root.
|
|
cp -R "$bundle"/. "$REPO_DIR"/
|
|
|
|
git add -A
|
|
|
|
if git diff --cached --quiet; then
|
|
echo "No tsl-playbook changes to publish."
|
|
exit 0
|
|
fi
|
|
|
|
git commit -m ":package: deps(tsl): sync tsl-playbook from ${source_short}
|
|
|
|
Source-Commit: ${source_sha}"
|
|
|
|
TOKEN="${WORKFLOW:-}"
|
|
if [ -n "$TOKEN" ] && [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ]; then
|
|
git remote set-url origin "https://oauth2:${TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
|
|
fi
|
|
|
|
git push origin "$TARGET_BRANCH"
|
|
echo "✅ Published tsl-playbook @ ${source_short}"
|