|
| 1 | +# When the CLI command catalog changes, regenerate skill reference markdown, |
| 2 | +# push to modelstudioai/skills, and open a PR against main. |
| 3 | +# |
| 4 | +# Required repository secret (Settings → Secrets and variables → Actions): |
| 5 | +# SKILLS_SYNC_TOKEN — PAT with repo scope on modelstudioai/skills: |
| 6 | +# Contents: Read and write |
| 7 | +# Pull requests: Read and write |
| 8 | +# Prefer a bot / machine user PAT if your org restricts personal PATs. |
| 9 | + |
| 10 | +name: Sync bailian-cli skill reference |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [main] |
| 15 | + paths: |
| 16 | + - "packages/cli/src/commands/catalog.ts" |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: sync-bailian-cli-skill-reference |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + sync: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + if: github.repository == 'modelstudioai/cli' |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout cli |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Setup pnpm |
| 35 | + uses: pnpm/action-setup@v4 |
| 36 | + with: |
| 37 | + version: 10.33.2 |
| 38 | + |
| 39 | + - name: Setup Node |
| 40 | + uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version: "22" |
| 43 | + cache: "pnpm" |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + run: pnpm install --frozen-lockfile |
| 47 | + |
| 48 | + - name: Build bailian-cli-core (required by generate-reference) |
| 49 | + run: pnpm --filter bailian-cli-core run build |
| 50 | + |
| 51 | + - name: Generate reference markdown |
| 52 | + run: pnpm --filter bailian-cli run generate:reference |
| 53 | + |
| 54 | + - name: Checkout skills repo |
| 55 | + uses: actions/checkout@v4 |
| 56 | + with: |
| 57 | + repository: modelstudioai/skills |
| 58 | + path: skills-repo |
| 59 | + token: ${{ secrets.SKILLS_SYNC_TOKEN }} |
| 60 | + fetch-depth: 0 |
| 61 | + |
| 62 | + - name: Sync reference into skills and open PR |
| 63 | + env: |
| 64 | + GH_TOKEN: ${{ secrets.SKILLS_SYNC_TOKEN }} |
| 65 | + CLI_SHA: ${{ github.sha }} |
| 66 | + CLI_RUN: ${{ github.run_id }} |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + cd "${GITHUB_WORKSPACE}/skills-repo" |
| 70 | + git config user.name "github-actions[bot]" |
| 71 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 72 | +
|
| 73 | + git fetch origin main |
| 74 | + git checkout main |
| 75 | + git pull origin main |
| 76 | +
|
| 77 | + SHORT_SHA="${CLI_SHA:0:7}" |
| 78 | + BRANCH="sync/bailian-cli-reference-${SHORT_SHA}" |
| 79 | + git checkout -B "$BRANCH" |
| 80 | +
|
| 81 | + SRC="${GITHUB_WORKSPACE}/tools/generated/reference" |
| 82 | + DEST="${GITHUB_WORKSPACE}/skills-repo/skills/bailian-cli/reference" |
| 83 | + mkdir -p "$DEST" |
| 84 | + rsync -a --delete "$SRC/" "$DEST/" |
| 85 | +
|
| 86 | + if git diff --quiet && git diff --cached --quiet; then |
| 87 | + echo "No changes to skill reference; exiting." |
| 88 | + exit 0 |
| 89 | + fi |
| 90 | +
|
| 91 | + git add skills/bailian-cli/reference |
| 92 | + RUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${CLI_RUN}" |
| 93 | + git commit \ |
| 94 | + -m "chore(bailian-cli): sync reference from cli" \ |
| 95 | + -m "Synced from modelstudioai/cli@${CLI_SHA}" \ |
| 96 | + -m "Workflow run: ${RUN_URL}" |
| 97 | +
|
| 98 | + # Branch is automation-owned; lease-safe force covers re-runs / updated main base. |
| 99 | + git push -u origin "$BRANCH" --force-with-lease |
| 100 | +
|
| 101 | + EXISTING=$(gh pr list --repo modelstudioai/skills --head "$BRANCH" --state open --json number --jq 'length') |
| 102 | + if [ "${EXISTING}" -eq 0 ]; then |
| 103 | + BODY_FILE="$(mktemp)" |
| 104 | + { |
| 105 | + echo "## Summary" |
| 106 | + echo "" |
| 107 | + 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}\`)." |
| 108 | + echo "" |
| 109 | + echo "## Test plan" |
| 110 | + echo "" |
| 111 | + echo "- [ ] Spot-check \`reference/index.md\` links and a sample group file under \`skills/bailian-cli/reference/\`." |
| 112 | + echo "- [ ] Merge if docs only." |
| 113 | + } >"$BODY_FILE" |
| 114 | + gh pr create \ |
| 115 | + --repo modelstudioai/skills \ |
| 116 | + --base main \ |
| 117 | + --head "$BRANCH" \ |
| 118 | + --title "chore(bailian-cli): sync CLI command reference" \ |
| 119 | + --body-file "$BODY_FILE" |
| 120 | + rm -f "$BODY_FILE" |
| 121 | + else |
| 122 | + echo "Open PR already exists for head ${BRANCH}." |
| 123 | + fi |
0 commit comments