@@ -2,75 +2,78 @@ name: Backup Fork and Sync
2
2
3
3
on :
4
4
schedule :
5
- - cron : ' 0 0 * * 0' # 每週日午夜運行一次
5
+ - cron : ' 0 0 * * 0' # 每週日午夜執行
6
6
workflow_dispatch : # 允許手動觸發
7
7
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
+
8
12
jobs :
9
13
backup-and-sync :
10
14
runs-on : ubuntu-latest
15
+ permissions :
16
+ contents : write
17
+
11
18
steps :
12
19
- name : Checkout repository
13
20
uses : actions/checkout@v4
14
21
with :
15
- fetch-depth : 0 # 獲取所有歷史記錄和標籤
16
- token : ${{ secrets.GITHUB_TOKEN }}
22
+ fetch-depth : 0
23
+ token : ${{ secrets.PAT_TOKEN }}
17
24
18
25
- name : Configure Git
19
26
run : |
20
27
git config --global user.name 'github-actions[bot]'
21
28
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"
23
35
24
36
- name : Add upstream repository
25
37
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 }}
27
39
git fetch --all --tags
28
40
29
41
- name : Sync and handle conflicts
30
42
run : |
31
- # 獲取所有本地分支
32
43
branches=$(git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | sed 's/origin\///')
33
44
34
45
for branch in $branches; do
35
46
echo "Processing branch: $branch"
36
47
37
- # 檢查分支是否存在於上游
38
48
if git ls-remote --exit-code --heads upstream $branch > /dev/null 2>&1; then
39
- # 切換到分支
40
49
git checkout -B $branch origin/$branch
41
50
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
44
55
echo "Successfully merged changes for $branch"
45
- git push origin $branch
46
56
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
61
65
fi
66
+ git push origin $branch || echo "Failed to push $branch, please check and push manually if needed"
62
67
else
63
68
echo "Branch $branch does not exist in upstream. Skipping."
64
69
fi
65
70
done
66
- env :
67
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68
71
69
- - name : Create version tag
72
+ - name : Create post-sync version tag
70
73
run : |
71
74
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"
74
77
75
78
- name : Generate sync report
76
79
if : always()
81
84
git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | sed 's/origin\///' | while read branch; do
82
85
echo "## Branch: $branch" >> sync_report.md
83
86
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
85
88
echo "Changes:" >> sync_report.md
86
89
git log HEAD..origin/$branch --oneline >> sync_report.md
87
90
else
92
95
93
96
- name : Upload sync report
94
97
if : always()
95
- uses : actions/upload-artifact@v2
98
+ uses : actions/upload-artifact@v3
96
99
with :
97
100
name : sync-report
98
101
path : sync_report.md
0 commit comments