Skip to content

Commit 8805f45

Browse files
hobbytpclaude
andcommitted
fix: Add intelligent push logic to image optimization workflow
- Implement smart branching logic for different scenarios: * main branch: git push origin main * pull request: git push origin HEAD:${{ github.ref }} * feature branches: git push origin HEAD:${{ github.ref_name }} - Fixes refname issues with GitHub Actions context - Handles both push and pull_request events properly - Ensures compatibility across different branch types 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 76ece2b commit 8805f45

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

.github/workflows/image-optimization.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
- "!static/images/optimized/**"
1010
- "!static/images/backup/**"
1111
pull_request:
12+
branches:
13+
- main
1214
paths:
1315
- "static/images/**"
1416
- "!static/images/optimized/**"
@@ -88,5 +90,17 @@ jobs:
8890
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
8991
run: |
9092
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
91-
git push origin ${{ github.ref_name }}
93+
94+
# 智能推送逻辑
95+
if [[ "${{ github.ref_name }}" == "main" ]]; then
96+
echo "Pushing to main branch"
97+
git push origin main
98+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
99+
echo "Pull request detected, pushing to current branch"
100+
git push origin HEAD:${{ github.ref }}
101+
else
102+
echo "Pushing to current branch"
103+
git push origin HEAD:${{ github.ref_name }}
104+
fi
105+
92106
echo "推送优化后的图片到仓库"

0 commit comments

Comments
 (0)