|
1 | 1 | name: Sync Dev to Master |
2 | 2 |
|
3 | 3 | on: |
4 | | - schedule: |
5 | | - # 每天北京时间凌晨 03:00 自动运行 (UTC 19:00) |
6 | | - - cron: "0 19 * * *" |
7 | 4 | workflow_dispatch: |
8 | | - inputs: |
9 | | - auto_push: |
10 | | - description: "合并并检查成功后自动推送到 master" |
11 | | - type: boolean |
12 | | - required: true |
13 | | - default: true |
14 | 5 |
|
15 | | -# 授予仓库写入权限,确保能够正常 git push |
16 | 6 | permissions: |
17 | 7 | contents: write |
18 | | - issues: write |
| 8 | + pull-requests: write |
19 | 9 |
|
| 10 | +# 所有手动同步共享目标 master,串行执行,不中断已经创建的集成现场。 |
20 | 11 | concurrency: |
21 | 12 | group: sync-dev-to-master |
22 | | - cancel-in-progress: true |
| 13 | + cancel-in-progress: false |
23 | 14 |
|
24 | 15 | jobs: |
25 | 16 | sync: |
26 | | - name: Sync upstream/dev into master |
| 17 | + name: Prepare checked integration branch and PR |
27 | 18 | runs-on: ubuntu-latest |
| 19 | + env: |
| 20 | + CI: true |
| 21 | + GH_TOKEN: ${{ secrets.SYNC_TOKEN || github.token }} |
28 | 22 | steps: |
29 | 23 | - name: Checkout repository |
30 | | - uses: actions/checkout@v4 |
| 24 | + uses: actions/checkout@v6 |
31 | 25 | with: |
32 | 26 | ref: master |
33 | 27 | fetch-depth: 0 |
34 | 28 | token: ${{ secrets.SYNC_TOKEN || github.token }} |
35 | 29 |
|
36 | | - - name: Setup Git identity |
| 30 | + - name: Setup Git identity and upstream |
37 | 31 | run: | |
38 | 32 | git config --global user.name "github-actions[bot]" |
39 | 33 | git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 34 | + git remote add upstream https://github.com/SPlayer-Dev/SPlayer-Next.git |
40 | 35 |
|
41 | | - - name: Setup upstream remote |
42 | | - run: | |
43 | | - if ! git remote | grep -q "^upstream$"; then |
44 | | - git remote add upstream https://github.com/SPlayer-Dev/SPlayer-Next.git |
45 | | - fi |
46 | | - git fetch upstream dev |
47 | | - git fetch origin master |
48 | | -
|
49 | | - - name: Check for new commits |
50 | | - id: check_commits |
51 | | - run: | |
52 | | - COMMITS=$(git log master..upstream/dev --oneline) |
53 | | - if [ -z "$COMMITS" ]; then |
54 | | - echo "has_commits=false" >> $GITHUB_OUTPUT |
55 | | - echo "upstream/dev 的所有提交已包含在 master 中,无需合并。" |
56 | | - else |
57 | | - echo "has_commits=true" >> $GITHUB_OUTPUT |
58 | | - echo "发现待合并提交:" |
59 | | - echo "$COMMITS" |
60 | | - fi |
61 | | -
|
62 | | - - name: Merge upstream/dev |
63 | | - if: steps.check_commits.outputs.has_commits == 'true' |
64 | | - run: | |
65 | | - git checkout master |
66 | | - git merge upstream/dev -m "Merge branch 'upstream/dev' into master" |
67 | | -
|
| 36 | + # 不指定 version:pnpm/action-setup 使用 packageManager 中锁定的 pnpm 12。 |
68 | 37 | - name: Setup pnpm |
69 | | - if: steps.check_commits.outputs.has_commits == 'true' |
70 | | - uses: pnpm/action-setup@v4 |
| 38 | + uses: pnpm/action-setup@v6 |
71 | 39 |
|
72 | 40 | - name: Setup Node.js |
73 | | - if: steps.check_commits.outputs.has_commits == 'true' |
74 | | - uses: actions/setup-node@v4 |
| 41 | + uses: actions/setup-node@v6 |
75 | 42 | with: |
76 | | - node-version: 22.x |
| 43 | + node-version: 24.x |
77 | 44 | cache: pnpm |
78 | 45 |
|
79 | | - - name: Install dependencies |
80 | | - if: steps.check_commits.outputs.has_commits == 'true' |
81 | | - run: pnpm install --frozen-lockfile |
82 | | - |
83 | | - - name: Verify types |
84 | | - if: steps.check_commits.outputs.has_commits == 'true' |
85 | | - run: pnpm typecheck |
| 46 | + # Node 24 原生执行 TS;与本地 sync:master 共用唯一实现。 |
| 47 | + # 脚本在独立 worktree 合并后执行 frozen install、typecheck 和 test,再发布分支/PR。 |
| 48 | + - name: Integrate, install, check, test and open PR |
| 49 | + run: node scripts/sync-master.ts --push |
86 | 50 |
|
87 | | - - name: Push to master |
88 | | - if: steps.check_commits.outputs.has_commits == 'true' && (github.event_name == 'schedule' || inputs.auto_push == true) |
| 51 | + - name: Explain downstream checks |
| 52 | + if: always() |
| 53 | + env: |
| 54 | + HAS_SYNC_TOKEN: ${{ secrets.SYNC_TOKEN != '' }} |
89 | 55 | run: | |
90 | | - git push origin master |
| 56 | + { |
| 57 | + echo '## Dev → master integration' |
| 58 | + echo 'This workflow never pushes master; pending changes are checked in an isolated worktree and published as an integration branch/PR only after frozen installation, typecheck and tests pass.' |
| 59 | + echo 'If there are no pending commits, no installation, checks or PR are needed. A failed sync is not a successful validation.' |
| 60 | + if [ "$HAS_SYNC_TOKEN" = true ]; then |
| 61 | + echo 'SYNC_TOKEN is configured. New push/PR events can trigger downstream workflows if that token has the required repository/workflow permissions.' |
| 62 | + else |
| 63 | + echo 'GITHUB_TOKEN is in use. GitHub suppresses downstream push/PR workflow events created with this token; this sync run does NOT establish that PR CI or the three-platform build ran.' |
| 64 | + echo 'An authorized user must close and reopen the PR to trigger PR checks, or manually dispatch Test and Build Dev on the integration branch. Required checks must still pass before merging.' |
| 65 | + echo 'Repository Actions settings must allow GitHub Actions to create pull requests; otherwise configure SYNC_TOKEN and rerun to reuse the published branch.' |
| 66 | + fi |
| 67 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments