fix: 修复硬编码 main 分支导致的兼容性问题

This commit is contained in:
sansan 2025-11-26 21:10:11 +08:00
parent c02e5cb55f
commit 648f8afd8e

View File

@ -5,7 +5,7 @@ on:
workflow_dispatch: workflow_dispatch:
concurrency: concurrency:
group: crawler-main-branch group: crawler-${{ github.ref_name }}
cancel-in-progress: true cancel-in-progress: true
permissions: permissions:
@ -20,7 +20,6 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: main
fetch-depth: 0 fetch-depth: 0
clean: true clean: true
@ -69,18 +68,20 @@ jobs:
run: python main.py run: python main.py
- name: Commit and push if changes - name: Commit and push if changes
env:
BRANCH_NAME: ${{ github.event.repository.default_branch }}
run: | run: |
git config --global user.name 'GitHub Actions' git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com' git config --global user.email 'actions@github.com'
echo "🔄 Syncing with remote..." echo "🔄 Syncing with remote (branch: $BRANCH_NAME)..."
git fetch origin main git fetch origin $BRANCH_NAME
# 保存当前更改 # 保存当前更改
git stash --include-untracked || echo "Nothing to stash" git stash --include-untracked || echo "Nothing to stash"
# 同步到远程最新 # 同步到远程最新
git reset --hard origin/main git reset --hard origin/$BRANCH_NAME
# 恢复本次更改 # 恢复本次更改
git stash pop || echo "Nothing to pop" git stash pop || echo "Nothing to pop"
@ -98,11 +99,11 @@ jobs:
echo "⬆️ Pushing changes with retry..." echo "⬆️ Pushing changes with retry..."
for i in {1..5}; do for i in {1..5}; do
git pull --rebase origin main && git push origin main && { git pull --rebase origin $BRANCH_NAME && git push origin $BRANCH_NAME && {
echo "✅ Successfully pushed on attempt $i" echo "✅ Successfully pushed on attempt $i"
exit 0 exit 0
} }
echo "⚠️ Attempt $i/$i failed, waiting $((i*3)) seconds..." echo "⚠️ Attempt $i failed, waiting $((i*3)) seconds..."
sleep $((i * 3)) sleep $((i * 3))
done done