Skip to content

Commit fb466c9

Browse files
author
chengww
committed
fix: sync 内容一致时改为对齐上游,避免历史分叉越积越多
1 parent 665ab6f commit fb466c9

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

.github/workflows/sync.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,28 @@ jobs:
1515
if: ${{ github.event.repository.fork }}
1616

1717
steps:
18-
# Step 1: run a standard checkout action
1918
- name: Checkout target repo
2019
uses: actions/checkout@v6
20+
with:
21+
fetch-depth: 0
2122

22-
# Step 2: run the sync action
2323
- name: Sync upstream changes
24-
id: sync
25-
uses: aormsby/fork-sync-with-upstream-action@v3.4.3
26-
with:
27-
upstream_sync_repo: cmliu/edgetunnel
28-
upstream_sync_branch: main
29-
target_sync_branch: main
30-
target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set
24+
run: |
25+
git config user.name "GH Action - Upstream Sync"
26+
git config user.email "action@github.com"
3127
32-
# Set test_mode true to run tests instead of the true action!!
33-
test_mode: false
28+
git remote add upstream https://github.com/cmliu/edgetunnel.git
29+
git fetch upstream main
3430
35-
- name: Sync check
36-
if: failure()
37-
run: |
38-
echo "[Error] 由于上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次,详细教程请查看项目README.md "
39-
echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork. Please refer to the project README.md for instructions. "
40-
exit 1
31+
if git diff --quiet HEAD upstream/main; then
32+
# 内容和上游一致,直接对齐,顺带清理历史分叉留下的多余 merge commit
33+
git reset --hard upstream/main
34+
git push --force-with-lease origin main
35+
else
36+
# 有本地修改,保持原来的合并方式,不覆盖任何人的改动
37+
git pull --no-rebase upstream main && git push origin main || {
38+
echo "[Error] 合并上游变更产生冲突,自动同步已暂停,请手动 Sync Fork 并解决冲突。"
39+
echo "[Error] Merge conflict detected while syncing upstream. Please sync your fork manually and resolve the conflicts."
40+
exit 1
41+
}
42+
fi

0 commit comments

Comments
 (0)