Skip to content

Commit ba2b402

Browse files
committed
auto sync #3
1 parent d1bb5aa commit ba2b402

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

.github/workflows/sync.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,14 @@ jobs:
5858
- name: Check if target_sync_branch exists in the remote
5959
id: check-branch-exists
6060
run: |
61-
# Use GitHub API to get the branch information
62-
RESPONSE=$(curl -s -H "Authorization: token${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ inputs.target_sync_repo }}/branches/${{ inputs.target_sync_branch }}")
63-
# Check if the response contains 'Not Found' which indicates the branch does not exist
64-
if echo "$RESPONSE" | grep -q "Not Found"; then
65-
echo "branch_exists=false" >> $GITHUB_OUTPUT
66-
echo "Remote branch ${{ inputs.target_sync_branch }} does not exist."
67-
# 创建一个临时分支来fetch远程分支的内容
68-
git fetch upstream ${{ inputs.upstream_sync_branch }}:temp_${{ inputs.upstream_sync_branch }}
69-
# 基于临时分支创建新的本地分支
70-
git checkout -b ${{ inputs.target_sync_branch }} temp_${{ inputs.upstream_sync_branch }}
71-
# 推送新分支到远程仓库
72-
git push origin ${{ inputs.target_sync_branch }}
73-
else
74-
echo "branch_exists=true" >> $GITHUB_OUTPUT
75-
echo "Remote branch ${{ inputs.target_sync_branch }} exists."
7661
# 创建一个临时分支来fetch远程分支的内容
7762
git fetch upstream ${{ inputs.upstream_sync_branch }}:temp_${{ inputs.upstream_sync_branch }}
7863
git checkout temp_${{ inputs.upstream_sync_branch }}
79-
git branch -D ${{ inputs.target_sync_branch }} # 强制删除本地分支
64+
# 强制删除本地分支 并忽略报错(如果分支不存在)
65+
git branch -D ${{ inputs.target_sync_branch }} || true
8066
git branch ${{ inputs.target_sync_branch }} temp_${{ inputs.upstream_sync_branch }} # 创建新分支
8167
# 强制推送新分支到远程仓库
8268
git push --force origin ${{ inputs.target_sync_branch }}
83-
fi
8469
8570
# # REQUIRED step
8671
# # Step 2: run the sync action

0 commit comments

Comments
 (0)