🔧 chore(tsl): add playbook sync workflow
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/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}"
|
||||
@@ -0,0 +1,68 @@
|
||||
name: 📦 Sync TSL Playbook
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: sync-tsl-playbook-${{ github.repository }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
WORKSPACE_DIR: "/home/workspace"
|
||||
TARGET_BRANCH: "tsl-playbook"
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
name: 📦 Build and publish tsl-playbook
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: 📥 准备仓库
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
echo "========================================"
|
||||
echo "📦 准备仓库到 WORKSPACE_DIR"
|
||||
echo "========================================"
|
||||
|
||||
REPO_NAME="${{ github.event.repository.name }}"
|
||||
TOKEN="${{ secrets.WORKFLOW }}"
|
||||
mkdir -p "$WORKSPACE_DIR"
|
||||
REPO_DIR="$(mktemp -d "$WORKSPACE_DIR/${REPO_NAME}.XXXXXX")"
|
||||
if [ -n "$TOKEN" ]; then
|
||||
REPO_URL="https://oauth2:${TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
|
||||
else
|
||||
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||
fi
|
||||
|
||||
git clone "$REPO_URL" "$REPO_DIR"
|
||||
|
||||
git -C "$REPO_DIR" fetch origin main
|
||||
git -C "$REPO_DIR" checkout -B main origin/main
|
||||
|
||||
git config --global --add safe.directory "$REPO_DIR"
|
||||
echo "REPO_DIR=$REPO_DIR" >> "$GITHUB_ENV"
|
||||
echo "✅ 仓库准备完成"
|
||||
|
||||
- name: 📦 Build and publish tsl-playbook
|
||||
shell: bash
|
||||
env:
|
||||
WORKFLOW: ${{ secrets.WORKFLOW }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "$REPO_DIR"
|
||||
|
||||
echo "========================================"
|
||||
echo "🔨 Build bundle and sync $TARGET_BRANCH"
|
||||
echo "========================================"
|
||||
|
||||
TARGET_BRANCH="$TARGET_BRANCH" bash .gitea/ci/sync_tsl_playbook.sh
|
||||
|
||||
- name: 🧹 清理临时仓库
|
||||
if: always()
|
||||
run: |
|
||||
rm -rf "$REPO_DIR"
|
||||
Reference in New Issue
Block a user