fix: update badges workflow fails trying to push to main #13
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Update Badges | |
| on: # yamllint disable-line rule:truthy | |
| pull_request: | |
| branches: ["main"] | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| update-badges: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Update badges | |
| run: | | |
| python3 scripts/update_badges.py | |
| - name: Check for changes | |
| id: verify-changed-files | |
| run: | | |
| if git diff --quiet; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit and push changes | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add README.md | |
| git commit -m "docs: update problem count badges [skip ci]" | |
| # Get the correct branch name for pushing | |
| BRANCH_NAME="${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}" | |
| echo "Pushing to branch: $BRANCH_NAME" | |
| # Push to the correct branch | |
| git push origin HEAD:$BRANCH_NAME |