@@ -2,12 +2,12 @@ name: Backup Fork and Sync
22
33on :
44 schedule :
5- - cron : ' 0 0 * * 0 ' # 每週日午夜執行
5+ - cron : ' 0 0 * * 1 ' # 每週日午夜執行
66 workflow_dispatch : # 允許手動觸發
77
88env :
99 UPSTREAM_REPO : ${{ vars.UPSTREAM_REPO || 'https://github.com/OpenMDAO/pyCycle.git' }}
10- MAIN_BRANCH : ${{ vars.MAIN_BRANCH || 'main ' }}
10+ MAIN_BRANCH : ${{ vars.MAIN_BRANCH || 'master ' }}
1111
1212jobs :
1313 backup-and-sync :
@@ -38,19 +38,45 @@ jobs:
3838 git remote add upstream ${{ env.UPSTREAM_REPO }} || git remote set-url upstream ${{ env.UPSTREAM_REPO }}
3939 git fetch --all --tags
4040
41+ # 同步上游的標籤
42+ - name : Sync tags from upstream
43+ run : |
44+ echo "Syncing tags from upstream..."
45+ # 保存同步狀態標籤
46+ SYNC_TAGS=$(git tag -l "pre-sync-*" "post-sync-*")
47+ # 刪除非同步狀態的標籤
48+ git tag -l | grep -v "^pre-sync-\|^post-sync-" | xargs -r git tag -d
49+ # 獲取上游標籤
50+ git fetch upstream --tags
51+ # 重新添加同步狀態標籤(如果有)
52+ if [ ! -z "$SYNC_TAGS" ]; then
53+ echo "$SYNC_TAGS" | while read tag; do
54+ git tag -f "$tag" $(git rev-list -n 1 "$tag")
55+ done
56+ fi
57+ # 推送所有標籤
58+ git push origin --tags --force
59+
4160 - name : Sync and handle conflicts
4261 run : |
4362 branches=$(git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | sed 's/origin\///')
44-
63+
4564 for branch in $branches; do
4665 echo "Processing branch: $branch"
47-
66+
4867 if git ls-remote --exit-code --heads upstream $branch > /dev/null 2>&1; then
49- git checkout -B $branch origin/$branch
68+ # Force reset the branch to its remote state
69+ git checkout -B $branch origin/$branch --force
70+
71+ # Forcefully remove untracked files and directories
72+ git clean -fdx
5073
74+ # Reset any changes in tracked files
75+ git reset --hard origin/$branch
76+
5177 echo "Changes in upstream $branch:"
5278 git log --oneline $branch..upstream/$branch
53-
79+
5480 if git merge upstream/$branch --no-edit --allow-unrelated-histories; then
5581 echo "Successfully merged changes for $branch"
5682 else
@@ -81,6 +107,13 @@ jobs:
81107 echo "Sync Report" > sync_report.md
82108 echo "===========" >> sync_report.md
83109 echo "" >> sync_report.md
110+ echo "## Tags Sync Status" >> sync_report.md
111+ echo "Upstream tags:" >> sync_report.md
112+ git ls-remote --tags upstream | awk '{print $2}' | sed 's/refs\/tags\///' >> sync_report.md
113+ echo "" >> sync_report.md
114+ echo "Local tags:" >> sync_report.md
115+ git tag -l >> sync_report.md
116+ echo "" >> sync_report.md
84117 git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | sed 's/origin\///' | while read branch; do
85118 echo "## Branch: $branch" >> sync_report.md
86119 if git log HEAD..origin/$branch --oneline | grep -q .; then
95128
96129 - name : Upload sync report
97130 if : always()
98- uses : actions/upload-artifact@v3
131+ uses : actions/upload-artifact@v4
99132 with :
100133 name : sync-report
101134 path : sync_report.md
0 commit comments