Skip to content

Commit fc6d3c1

Browse files
committed
ci: update code
Signed-off-by: David Mandy <smallprogramzhusir@gmail.com>
1 parent cd5bf9b commit fc6d3c1

1 file changed

Lines changed: 59 additions & 25 deletions

File tree

.github/workflows/Build_Multi_Platform(V6).yml

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,36 @@ jobs:
135135
git config user.email "smallprogram@foxmail.com"
136136
git commit -m "Configuration: update code for ${{ matrix.source_code_platform }}"
137137
138-
git checkout ${{ github.ref_name }}
139-
git fetch origin
140-
git reset --hard origin/${{ github.ref_name }}
141-
142-
git checkout temp-${{ matrix.source_code_platform }}
143-
git merge origin/${{ github.ref_name }} --no-ff --strategy-option theirs --no-edit || {
144-
echo "Merge conflict in temp branch, please resolve manually."
138+
MAX_RETRIES=10
139+
RETRY_COUNT=0
140+
141+
# 循环重试机制解决矩阵并发 Push 冲突
142+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
143+
git checkout ${{ github.ref_name }}
144+
git fetch origin ${{ github.ref_name }}
145+
git reset --hard origin/${{ github.ref_name }}
146+
147+
# 合并当前的临时分支
148+
git merge temp-${{ matrix.source_code_platform }} --strategy-option theirs --no-edit
149+
150+
if git push origin ${{ github.ref_name }}; then
151+
echo "Push successful!"
152+
break
153+
else
154+
echo "Push failed due to concurrent update. Retrying in a few seconds..."
155+
git reset --hard HEAD~1
156+
RETRY_COUNT=$((RETRY_COUNT+1))
157+
sleep $((RANDOM % 5 + 3)) # 随机等待 3-7 秒错开并发
158+
fi
159+
done
160+
161+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
162+
echo "Failed to push after $MAX_RETRIES attempts."
145163
exit 100
146-
}
164+
fi
147165
148-
git checkout ${{ github.ref_name }}
149-
git merge temp-${{ matrix.source_code_platform }} --strategy-option theirs --no-edit
150-
git push origin ${{ github.ref_name }} --force
151-
git branch -d temp-${{ matrix.source_code_platform }} || echo "Local temp-${{ matrix.source_code_platform }} not found"
152-
git push origin --delete temp-${{ matrix.source_code_platform }} || echo "Remote temp-${{ matrix.source_code_platform }} not found"
166+
# 只删除本地临时分支
167+
git branch -D temp-${{ matrix.source_code_platform }} || echo "Local temp branch not found"
153168
else
154169
echo "No changes to commit."
155170
fi
@@ -261,24 +276,43 @@ jobs:
261276
git config user.name "smallprogram"
262277
git config user.email "smallprogram@foxmail.com"
263278
git commit -m "Git Log: update code"
264-
git checkout ${{ github.ref_name }}
265-
git fetch origin
266-
git reset --hard origin/${{ github.ref_name }}
267-
git checkout temp-tag-gitlog
268-
git merge origin/${{ github.ref_name }} --no-ff --strategy-option theirs --no-edit || { exit 100; }
269-
git checkout ${{ github.ref_name }}
270-
git merge temp-tag-gitlog --strategy-option theirs --no-edit
271-
git push origin ${{ github.ref_name }} --force
272-
git branch -d temp-tag-gitlog || echo "Local temp-tag-gitlog not found"
273-
git push origin --delete temp-tag-gitlog || echo "Remote temp-tag-gitlog not found"
279+
280+
MAX_RETRIES=10
281+
RETRY_COUNT=0
282+
283+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
284+
git checkout ${{ github.ref_name }}
285+
git fetch origin ${{ github.ref_name }}
286+
git reset --hard origin/${{ github.ref_name }}
287+
288+
git merge temp-tag-gitlog --strategy-option theirs --no-edit
289+
290+
if git push origin ${{ github.ref_name }}; then
291+
echo "Push successful!"
292+
break
293+
else
294+
echo "Push failed. Retrying..."
295+
git reset --hard HEAD~1
296+
RETRY_COUNT=$((RETRY_COUNT+1))
297+
sleep $((RANDOM % 5 + 3))
298+
fi
299+
done
300+
301+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
302+
echo "Failed to push git log after $MAX_RETRIES attempts."
303+
exit 100
304+
fi
305+
306+
# 只删除本地临时分支
307+
git branch -D temp-tag-gitlog || echo "Local temp-tag-gitlog not found"
274308
else
275309
echo "No changes to commit."
276310
fi
277311
278312
job_compile_and_upload:
279313
needs: [job_init, job_source_init, job_generate_release_tag]
280314
runs-on: ${{ matrix.value.OS }}
281-
if: ${{ always() && !cancelled() }}
315+
if: ${{ !cancelled() && needs.job_source_init.result == 'success' && needs.job_generate_release_tag.result == 'success' }}
282316
strategy:
283317
fail-fast: false
284318
matrix:
@@ -673,7 +707,7 @@ jobs:
673707

674708
job_organize_tags:
675709
needs: [job_init, job_source_init, job_generate_release_tag, job_compile_and_upload]
676-
if: ${{ always() && !cancelled() }}
710+
if: ${{ !cancelled() && needs.job_source_init.result == 'success' && needs.job_generate_release_tag.result == 'success' }}
677711
runs-on: ubuntu-latest
678712
name: Organize-Release-Tags
679713
outputs:

0 commit comments

Comments
 (0)