From 3461e534047987d689ed93eedca22616dfd6909d Mon Sep 17 00:00:00 2001 From: qcq01083097 Date: Thu, 4 Jun 2026 15:22:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5skills=E7=9A=84workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sync-bailian-cli-skill-reference.yml | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 .github/workflows/sync-bailian-cli-skill-reference.yml diff --git a/.github/workflows/sync-bailian-cli-skill-reference.yml b/.github/workflows/sync-bailian-cli-skill-reference.yml new file mode 100644 index 0000000..0985876 --- /dev/null +++ b/.github/workflows/sync-bailian-cli-skill-reference.yml @@ -0,0 +1,123 @@ +# When the CLI command catalog changes, regenerate skill reference markdown, +# push to modelstudioai/skills, and open a PR against main. +# +# Required repository secret (Settings → Secrets and variables → Actions): +# SKILLS_SYNC_TOKEN — PAT with repo scope on modelstudioai/skills: +# Contents: Read and write +# Pull requests: Read and write +# Prefer a bot / machine user PAT if your org restricts personal PATs. + +name: Sync bailian-cli skill reference + +on: + push: + branches: [main] + paths: + - "packages/cli/src/commands/catalog.ts" + workflow_dispatch: + +concurrency: + group: sync-bailian-cli-skill-reference + cancel-in-progress: true + +jobs: + sync: + runs-on: ubuntu-latest + if: github.repository == 'modelstudioai/cli' + permissions: + contents: read + + steps: + - name: Checkout cli + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10.33.2 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "22" + cache: "pnpm" + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build bailian-cli-core (required by generate-reference) + run: pnpm --filter bailian-cli-core run build + + - name: Generate reference markdown + run: pnpm --filter bailian-cli run generate:reference + + - name: Checkout skills repo + uses: actions/checkout@v4 + with: + repository: modelstudioai/skills + path: skills-repo + token: ${{ secrets.SKILLS_SYNC_TOKEN }} + fetch-depth: 0 + + - name: Sync reference into skills and open PR + env: + GH_TOKEN: ${{ secrets.SKILLS_SYNC_TOKEN }} + CLI_SHA: ${{ github.sha }} + CLI_RUN: ${{ github.run_id }} + run: | + set -euo pipefail + cd "${GITHUB_WORKSPACE}/skills-repo" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + git fetch origin main + git checkout main + git pull origin main + + SHORT_SHA="${CLI_SHA:0:7}" + BRANCH="sync/bailian-cli-reference-${SHORT_SHA}" + git checkout -B "$BRANCH" + + SRC="${GITHUB_WORKSPACE}/tools/generated/reference" + DEST="${GITHUB_WORKSPACE}/skills-repo/skills/bailian-cli/reference" + mkdir -p "$DEST" + rsync -a --delete "$SRC/" "$DEST/" + + if git diff --quiet && git diff --cached --quiet; then + echo "No changes to skill reference; exiting." + exit 0 + fi + + git add skills/bailian-cli/reference + RUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${CLI_RUN}" + git commit \ + -m "chore(bailian-cli): sync reference from cli" \ + -m "Synced from modelstudioai/cli@${CLI_SHA}" \ + -m "Workflow run: ${RUN_URL}" + + # Branch is automation-owned; lease-safe force covers re-runs / updated main base. + git push -u origin "$BRANCH" --force-with-lease + + EXISTING=$(gh pr list --repo modelstudioai/skills --head "$BRANCH" --state open --json number --jq 'length') + if [ "${EXISTING}" -eq 0 ]; then + BODY_FILE="$(mktemp)" + { + echo "## Summary" + echo "" + echo "- Regenerated \`skills/bailian-cli/reference/*.md\` from [\`packages/cli/src/commands/catalog.ts\`](https://github.com/modelstudioai/cli/blob/${CLI_SHA}/packages/cli/src/commands/catalog.ts) in [\`modelstudioai/cli\`](https://github.com/modelstudioai/cli) (commit \`${SHORT_SHA}\`)." + echo "" + echo "## Test plan" + echo "" + echo "- [ ] Spot-check \`reference/index.md\` links and a sample group file under \`skills/bailian-cli/reference/\`." + echo "- [ ] Merge if docs only." + } >"$BODY_FILE" + gh pr create \ + --repo modelstudioai/skills \ + --base main \ + --head "$BRANCH" \ + --title "chore(bailian-cli): sync CLI command reference" \ + --body-file "$BODY_FILE" + rm -f "$BODY_FILE" + else + echo "Open PR already exists for head ${BRANCH}." + fi