Skip to content

Commit 39c547d

Browse files
committed
ci: 添加自动同步上游的 workflow
1 parent 31c4aaa commit 39c547d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Sync Upstream
2+
3+
on:
4+
schedule:
5+
# 每天 UTC 0:00 检查上游更新
6+
- cron: '0 0 * * *'
7+
workflow_dispatch:
8+
inputs:
9+
sync_method:
10+
description: '同步方式'
11+
required: true
12+
default: 'rebase'
13+
type: choice
14+
options:
15+
- rebase
16+
- merge
17+
18+
jobs:
19+
sync:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Setup Git
29+
run: |
30+
git config user.name "github-actions[bot]"
31+
git config user.email "github-actions[bot]@users.noreply.github.com"
32+
33+
- name: Add upstream
34+
run: |
35+
git remote add upstream https://github.com/wyx2685/v2node.git
36+
git fetch upstream
37+
38+
- name: Check for updates
39+
id: check
40+
run: |
41+
UPSTREAM_COMMITS=$(git rev-list HEAD..upstream/main --count)
42+
echo "upstream_commits=$UPSTREAM_COMMITS" >> $GITHUB_OUTPUT
43+
if [ "$UPSTREAM_COMMITS" -gt 0 ]; then
44+
echo "有 $UPSTREAM_COMMITS 个新提交需要同步"
45+
else
46+
echo "上游没有新提交"
47+
fi
48+
49+
- name: Sync upstream (rebase)
50+
if: steps.check.outputs.upstream_commits > 0 && (github.event.inputs.sync_method == 'rebase' || github.event_name == 'schedule')
51+
run: |
52+
git rebase upstream/main
53+
git push --force-with-lease
54+
55+
- name: Sync upstream (merge)
56+
if: steps.check.outputs.upstream_commits > 0 && github.event.inputs.sync_method == 'merge'
57+
run: |
58+
git merge upstream/main -m "chore: 同步上游更新"
59+
git push

0 commit comments

Comments
 (0)