Skip to content

Commit 75db88c

Browse files
authored
Merge pull request #463 from TencentCloudBase/feature/auto-sync-main-to-examples
feat(ci): 🔄 auto sync main changes to examples
2 parents ef7cf02 + e65c16d commit 75db88c

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Sync Main to Examples
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "config/source/skills/**"
9+
- "config/source/guideline/**"
10+
- "config/source/editor-config/**"
11+
- "scripts/build-compat-config.mjs"
12+
- "scripts/diff-compat-config.mjs"
13+
- "scripts/update-compat-baseline.mjs"
14+
- "scripts/sync-config.mjs"
15+
- "scripts/template-config.json"
16+
- ".github/workflows/sync-main-to-examples.yml"
17+
18+
concurrency:
19+
group: sync-main-to-examples
20+
cancel-in-progress: false
21+
22+
jobs:
23+
sync:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
steps:
28+
- name: Checkout current repo
29+
uses: actions/checkout@v4
30+
31+
- name: Checkout cloudbase-examples
32+
uses: actions/checkout@v4
33+
with:
34+
repository: TencentCloudBase/awsome-cloudbase-examples
35+
ref: master
36+
path: cloudbase-examples
37+
token: ${{ secrets.CLOUDBASE_EXAMPLES_TOKEN }}
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '22'
43+
44+
- name: Validate compatibility surface
45+
run: node scripts/diff-compat-config.mjs
46+
47+
- name: Check git status before sync
48+
working-directory: cloudbase-examples
49+
run: |
50+
echo "=== Git status before sync ==="
51+
git status --short || true
52+
53+
- name: Sync config to examples
54+
run: node scripts/sync-config.mjs --skip-git
55+
env:
56+
CLOUDBASE_EXAMPLES_PATH: cloudbase-examples
57+
58+
- name: Check git status after sync
59+
working-directory: cloudbase-examples
60+
run: |
61+
echo "=== Git status after sync ==="
62+
git status --short
63+
echo "=== Files changed ==="
64+
git diff --name-only || echo "No changes detected"
65+
echo "=== Staged files ==="
66+
git diff --staged --name-only || echo "No staged files"
67+
68+
- name: Commit and push changes
69+
working-directory: cloudbase-examples
70+
env:
71+
PAT_TOKEN: ${{ secrets.CLOUDBASE_EXAMPLES_TOKEN }}
72+
run: |
73+
git config user.name "github-actions[bot]"
74+
git config user.email "github-actions[bot]@users.noreply.github.com"
75+
git add .
76+
if git diff --staged --quiet; then
77+
echo "No changes to commit, skipping commit and push"
78+
else
79+
git commit -m "chore: sync config from main"
80+
git remote set-url origin https://x-access-token:${PAT_TOKEN}@github.com/TencentCloudBase/awsome-cloudbase-examples.git
81+
git push origin master
82+
fi

CONTRIBUTING.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,23 @@ CloudBase AI ToolKit 的对外 Skill(例如对外发布的 Skill 仓库、IDE
295295
**输出**
296296
- 如果 `build_zips` 为 true,会在 Actions 页面生成 artifact `cloudbase-examples-zips`,保留 30 天
297297

298+
### Sync Main to Examples
299+
300+
**Workflow**: `.github/workflows/sync-main-to-examples.yml`
301+
302+
当本仓库 `main` 分支发生 push,且变更命中 examples 相关路径时自动触发。
303+
304+
**行为**
305+
- 先执行 `node scripts/diff-compat-config.mjs` 作为兼容面守门
306+
- 再执行 `node scripts/sync-config.mjs --skip-git`
307+
- 自动同步到 `TencentCloudBase/awsome-cloudbase-examples``master` 分支
308+
- 如果同步结果没有产生 diff,则跳过 commit / push
309+
298310
### Sync Branch to Examples
299311

300312
**Workflow**: `.github/workflows/sync-branch.yml`
301313

302-
仅用于将本仓库的指定分支同步到 cloudbase-examples 的指定分支,不构建 zip 文件。
314+
仅用于手动将本仓库的指定分支同步到 cloudbase-examples 的指定分支,不构建 zip 文件,也不替代 `main` 主线的自动同步 workflow
303315

304316
**使用场景**
305317
- 需要将某个分支的配置同步到 cloudbase-examples 的对应分支

0 commit comments

Comments
 (0)