Like 0

AppStore完善同步更新Action脚本,支持强制同步,自动合入,解决冲突

LiuShen revised this gist 4 months ago · 49aa716

2 files changed, 312 insertions

renovate-app-version.yml (file created)

Diff is too large to be shown

sync-to-cnb.yml (file created)
@@ -0,0 +1,100 @@
1 + name: Sync commits to CNB (force)
2 +
3 + on:
4 + schedule:
5 + - cron: "0 0 * * *" # 每天凌晨 0 点强制同步(兜底)
6 + - cron: "0 */6 * * *" # 每 6 小时检查一次
7 + push:
8 + branches:
9 + - main
10 + workflow_call: # 允许被其他工作流调用
11 + workflow_dispatch:
12 + inputs:
13 + reason:
14 + description: 'Manual trigger reason'
15 + required: false
16 + default: 'Manual run'
17 + force_sync:
18 + description: 'Force sync without checking for new commits'
19 + required: false
20 + default: 'false'
21 +
22 + jobs:
23 + sync:
24 + runs-on: ubuntu-latest
25 + outputs:
26 + synced: ${{ steps.sync.outputs.synced }}
27 +
28 + steps:
29 + - name: Checkout GitHub repository
30 + uses: actions/checkout@v5
31 + with:
32 + ref: main
33 + fetch-depth: 0
34 +
35 + - name: Determine sync mode
36 + id: mode
37 + run: |
38 + # 每天凌晨的定时任务强制同步
39 + if [[ "${{ github.event.schedule }}" == "0 0 * * *" ]]; then
40 + echo "Daily scheduled sync - forcing sync"
41 + echo "force=true" >> $GITHUB_OUTPUT
42 + exit 0
43 + fi
44 +
45 + # 手动触发且指定强制同步
46 + if [[ "${{ github.event.inputs.force_sync }}" == "true" ]]; then
47 + echo "Manual force sync requested"
48 + echo "force=true" >> $GITHUB_OUTPUT
49 + exit 0
50 + fi
51 +
52 + # 被 workflow_call 调用时强制同步
53 + if [[ "${{ github.event_name }}" == "workflow_call" ]]; then
54 + echo "Called by another workflow - forcing sync"
55 + echo "force=true" >> $GITHUB_OUTPUT
56 + exit 0
57 + fi
58 +
59 + echo "force=false" >> $GITHUB_OUTPUT
60 +
61 + - name: Check if there are new commits
62 + if: steps.mode.outputs.force != 'true'
63 + id: check
64 + run: |
65 + NEW_COMMITS=$(git log --since="6 hours ago" --oneline)
66 + if [ -z "$NEW_COMMITS" ]; then
67 + echo "No new commits in the last 6 hours, skip sync."
68 + echo "skip=true" >> $GITHUB_OUTPUT
69 + else
70 + echo "New commits found:"
71 + echo "$NEW_COMMITS"
72 + echo "skip=false" >> $GITHUB_OUTPUT
73 + fi
74 +
75 + - name: Sync to CNB
76 + id: sync
77 + if: steps.mode.outputs.force == 'true' || steps.check.outputs.skip == 'false'
78 + env:
79 + CNB_USERNAME: ${{ secrets.CNB_USERNAME }}
80 + CNB_TOKEN: ${{ secrets.CNB_TOKEN }}
81 + run: |
82 + echo "Syncing to CNB mirror..."
83 + rm -rf .git
84 + git init
85 + git config --global user.name 'GitHub Action'
86 + git config --global user.email 'action@github.com'
87 + git add .
88 + git commit -m "Sync commit ==> [$(date +"%Y-%m-%d %H:%M:%S")]"
89 + git branch -M main
90 + git remote add origin "https://${{ secrets.CNB_USERNAME }}:${{ secrets.CNB_TOKEN }}@cnb.cool/liiiu/appstore.git"
91 + git push --force --quiet origin main
92 + echo "synced=true" >> $GITHUB_OUTPUT
93 +
94 + - name: Report result
95 + run: |
96 + if [[ "${{ steps.sync.outputs.synced }}" == "true" ]]; then
97 + echo "✅ Successfully synced to CNB mirror"
98 + else
99 + echo "⏭️ Skipped sync (no new commits)"
100 + fi