File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed
Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy to Target Repo on Version Change
2+
3+ on :
4+ push :
5+ paths :
6+ - " package.json" # 仅在 package.json 更新时触发
7+
8+ jobs :
9+ deploy :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ # Step 1: 检出源仓库代码
14+ - name : Checkout Source Repository
15+ uses : actions/checkout@v3
16+
17+ # Step 2: 检查 package.json 的版本号是否变化
18+ - name : Check for Version Change
19+ id : version
20+ run : |
21+ OLD_VERSION=$(git show HEAD~1:package.json | jq -r .version)
22+ NEW_VERSION=$(jq -r .version package.json)
23+ echo "Old version: $OLD_VERSION"
24+ echo "New version: $NEW_VERSION"
25+ if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
26+ echo "version_changed=true" >> $GITHUB_ENV
27+ else
28+ echo "version_changed=false" >> $GITHUB_ENV
29+ fi
30+
31+ # Step 3: 如果版本号改变,则拉取目标仓库并执行 gh 指令
32+ - name : Deploy to Target Repo
33+ if : env.version_changed == 'true'
34+ env :
35+ TARGET_REPO_TOKEN : ${{ secrets.TARGET_REPO_TOKEN }}
36+ run : |
37+ # 克隆目标仓库
38+ git clone https://x-access-token:${TARGET_REPO_TOKEN}@github.com/VueFilesPreview/vue-files-preview-demo.git vue-files-preview-demo
39+
40+ # 进入目标仓库目录
41+ cd vue-files-preview-demo
42+
43+ # 确保脚本有执行权限
44+ npm run gh
45+
46+ # 提交并推送更改(如果脚本有更改内容)
47+ git config user.name "github-actions[bot]"
48+ git config user.email "github-actions[bot]@users.noreply.github.com"
49+ git add .
50+ git commit -m "feat: Auto-deploy on version change to $NEW_VERSION" || echo "No changes to commit"
51+ git push
Original file line number Diff line number Diff line change 4242 "unpub" : " npm unpublish" ,
4343 "pub" : " cd dist && npm publish --access=public"
4444 },
45+ "jsdelivr" : " " ,
4546 "publishConfig" : {
4647 "access" : " public"
4748 },
7374 "sass" : " 1.79.5" ,
7475 "ts-node" : " 10.9.2" ,
7576 "tslib" : " 2.7.0" ,
76- "unplugin-auto-import" : " 0.18.3" ,
7777 "tsx" : " 4.19.1" ,
7878 "unplugin-auto-import" : " 0.18.3" ,
7979 "vite" : " 5.4.10" ,
You can’t perform that action at this time.
0 commit comments