@@ -2,75 +2,78 @@ name: Backup Fork and Sync
22
33on :
44 schedule :
5- - cron : ' 0 0 * * 0' # 每週日午夜運行一次
5+ - cron : ' 0 0 * * 0' # 每週日午夜執行
66 workflow_dispatch : # 允許手動觸發
77
8+ env :
9+ UPSTREAM_REPO : ${{ vars.UPSTREAM_REPO || 'https://github.com/CMU-Perceptual-Computing-Lab/openpose.git' }}
10+ MAIN_BRANCH : ${{ vars.MAIN_BRANCH || 'master' }}
11+
812jobs :
913 backup-and-sync :
1014 runs-on : ubuntu-latest
15+ permissions :
16+ contents : write
17+
1118 steps :
1219 - name : Checkout repository
1320 uses : actions/checkout@v4
1421 with :
15- fetch-depth : 0 # 獲取所有歷史記錄和標籤
16- token : ${{ secrets.GITHUB_TOKEN }}
22+ fetch-depth : 0
23+ token : ${{ secrets.PAT_TOKEN }}
1724
1825 - name : Configure Git
1926 run : |
2027 git config --global user.name 'github-actions[bot]'
2128 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
22- git config --global checkout.defaultRemote origin
29+
30+ - name : Tag current state
31+ run : |
32+ TIMESTAMP=$(date +"%Y%m%d%H%M%S")
33+ git tag -a "pre-sync-$TIMESTAMP" -m "Pre-sync state on $TIMESTAMP"
34+ git push origin "pre-sync-$TIMESTAMP"
2335
2436 - name : Add upstream repository
2537 run : |
26- git remote add upstream https://github.com/CMU-Perceptual-Computing-Lab/openpose.git
38+ git remote add upstream ${{ env.UPSTREAM_REPO }} || git remote set-url upstream ${{ env.UPSTREAM_REPO }}
2739 git fetch --all --tags
2840
2941 - name : Sync and handle conflicts
3042 run : |
31- # 獲取所有本地分支
3243 branches=$(git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | sed 's/origin\///')
3344
3445 for branch in $branches; do
3546 echo "Processing branch: $branch"
3647
37- # 檢查分支是否存在於上游
3848 if git ls-remote --exit-code --heads upstream $branch > /dev/null 2>&1; then
39- # 切換到分支
4049 git checkout -B $branch origin/$branch
4150
42- # 嘗試合併上游更改
43- if git merge upstream/$branch --no-edit; then
51+ echo "Changes in upstream $branch:"
52+ git log --oneline $branch..upstream/$branch
53+
54+ if git merge upstream/$branch --no-edit --allow-unrelated-histories; then
4455 echo "Successfully merged changes for $branch"
45- git push origin $branch
4656 else
47- echo "Merge conflict in $branch. Attempting automatic resolution..."
48-
49- # 嘗試自動解決衝突
50- git diff --name-only --diff-filter=U | xargs git checkout --theirs
51- git add .
52- git commit -m "Auto-resolve conflicts in $branch"
53-
54- # 推送更改
55- if git push origin $branch; then
56- echo "Pushed auto-resolved changes for $branch"
57- else
58- echo "Failed to push changes for $branch. Manual intervention required."
59- git merge --abort
60- fi
57+ echo "Merge conflict in $branch. Creating a new branch with upstream changes."
58+ git merge --abort
59+ conflict_branch="${branch}-upstream-changes"
60+ git checkout -b $conflict_branch upstream/$branch
61+ echo "Created new branch $conflict_branch with upstream changes"
62+ git push origin $conflict_branch
63+ echo "Please manually review and merge changes from $conflict_branch into $branch"
64+ git checkout $branch
6165 fi
66+ git push origin $branch || echo "Failed to push $branch, please check and push manually if needed"
6267 else
6368 echo "Branch $branch does not exist in upstream. Skipping."
6469 fi
6570 done
66- env :
67- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6871
69- - name : Create version tag
72+ - name : Create post-sync version tag
7073 run : |
7174 TIMESTAMP=$(date +"%Y%m%d%H%M%S")
72- git tag -a "sync-$TIMESTAMP" -m "Sync on $TIMESTAMP"
73- git push --tags origin
75+ git tag -a "post- sync-$TIMESTAMP" -m "Post-sync state on $TIMESTAMP"
76+ git push origin "post-sync-$TIMESTAMP"
7477
7578 - name : Generate sync report
7679 if : always()
8184 git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | sed 's/origin\///' | while read branch; do
8285 echo "## Branch: $branch" >> sync_report.md
8386 if git log HEAD..origin/$branch --oneline | grep -q .; then
84- echo "Status: Changes pushed " >> sync_report.md
87+ echo "Status: Changes synced " >> sync_report.md
8588 echo "Changes:" >> sync_report.md
8689 git log HEAD..origin/$branch --oneline >> sync_report.md
8790 else
9295
9396 - name : Upload sync report
9497 if : always()
95- uses : actions/upload-artifact@v2
98+ uses : actions/upload-artifact@v3
9699 with :
97100 name : sync-report
98101 path : sync_report.md
0 commit comments