Skip to content

Commit 8544f40

Browse files
Merge pull request #23 from modelstudioai/feat/auto-generate-skills
Feat/auto generate skills
2 parents 832d3f7 + 6494e68 commit 8544f40

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)