Skip to content

Commit 08d2d03

Browse files
committed
🐳 chore(sync workflow): 增强同步工作流,添加比较哈希和同步信息步骤
1 parent 64922bf commit 08d2d03

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

.github/workflows/sync-upstream.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,52 @@ on:
66
workflow_dispatch: # 支持手动触发
77

88
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
need_sync: ${{ steps.compare.outputs.need_sync }}
13+
upstream_hash: ${{ steps.compare.outputs.upstream_hash }}
14+
current_hash: ${{ steps.compare.outputs.current_hash }}
15+
steps:
16+
- name: Checkout up-sync branch
17+
uses: actions/checkout@v4
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
fetch-depth: 0
21+
ref: up-sync
22+
23+
- name: Add upstream remote
24+
run: git remote add upstream https://github.com/ddnet/ddnet-maps
25+
26+
- name: Fetch upstream
27+
run: git fetch upstream
28+
29+
- name: Compare commit hashes
30+
id: compare
31+
run: |
32+
# 获取当前 up-sync 分支的 commit hash
33+
CURRENT_HASH=$(git rev-parse HEAD)
34+
echo "current_hash=$CURRENT_HASH" >> $GITHUB_OUTPUT
35+
echo "当前 up-sync 分支 commit hash: $CURRENT_HASH"
36+
37+
# 获取 upstream/master 的 commit hash
38+
UPSTREAM_HASH=$(git rev-parse upstream/master)
39+
echo "upstream_hash=$UPSTREAM_HASH" >> $GITHUB_OUTPUT
40+
echo "upstream/master commit hash: $UPSTREAM_HASH"
41+
42+
# 比较两个 hash 是否相同
43+
if [ "$CURRENT_HASH" = "$UPSTREAM_HASH" ]; then
44+
echo "need_sync=false" >> $GITHUB_OUTPUT
45+
echo "✅ commit hash 相同,无需同步"
46+
else
47+
echo "need_sync=true" >> $GITHUB_OUTPUT
48+
echo "🔄 commit hash 不同,需要同步"
49+
fi
50+
951
sync:
1052
runs-on: ubuntu-latest
53+
needs: check
54+
if: needs.check.outputs.need_sync == 'true'
1155
permissions:
1256
contents: write
1357
steps:
@@ -24,6 +68,12 @@ jobs:
2468
- name: Fetch upstream
2569
run: git fetch upstream
2670

71+
- name: Show sync information
72+
run: |
73+
echo "🔄 开始同步..."
74+
echo "当前分支: $(git rev-parse HEAD)"
75+
echo "目标分支: $(git rev-parse upstream/master)"
76+
2777
- name: Hard reset up-sync to upstream/master
2878
run: |
2979
git reset --hard upstream/master
@@ -32,4 +82,9 @@ jobs:
3282
run: |
3383
git push origin up-sync --force
3484
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
87+
- name: Sync completed
88+
run: |
89+
echo "✅ 同步完成!"
90+
echo "新的 commit hash: $(git rev-parse HEAD)"

0 commit comments

Comments
 (0)