diff --git a/.github/workflows/update-badges.yml b/.github/workflows/update-badges.yml index 8aa46d1..3b876c9 100644 --- a/.github/workflows/update-badges.yml +++ b/.github/workflows/update-badges.yml @@ -2,7 +2,7 @@ name: Update Badges on: # yamllint disable-line rule:truthy - push: + pull_request: branches: ["main"] workflow_dispatch: # Allow manual triggering @@ -14,6 +14,7 @@ jobs: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 @@ -33,11 +34,17 @@ jobs: echo "changed=true" >> $GITHUB_OUTPUT fi - - name: Commit changes + - 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]" - git push + + # Get the current branch name from the GitHub context + BRANCH_NAME="${{ github.head_ref || github.ref_name }}" + echo "Pushing to branch: $BRANCH_NAME" + + # Push to the correct branch + git push origin HEAD:$BRANCH_NAME diff --git a/scripts/update_badges.py b/scripts/update_badges.py index 1d6ba85..81d32ec 100644 --- a/scripts/update_badges.py +++ b/scripts/update_badges.py @@ -56,7 +56,7 @@ def update_readme_badges(cpp_count, python_count): # Define the new badge lines cpp_badge = f"[![C++ Solutions](https://img.shields.io/badge/C%2B%2B%20Solutions-{cpp_count}-blue?style=for-the-badge&logo=cplusplus&logoColor=white)](https://github.com/mathusanm6/LeetCode/tree/main/problems)" - python_badge = f"[![Python Solutions](https://img.shields.io/badge/Python%20Solutions-{python_count}-green?style=for-the-badge&logo=python&logoColor=white)](https://github.com/mathusanm6/LeetCode/tree/main/problems)" + python_badge = f"[![Python Solutions](https://img.shields.io/badge/Python%20Solutions-{python_count}-blue?style=for-the-badge&logo=python&logoColor=white)](https://github.com/mathusanm6/LeetCode/tree/main/problems)" # Update C++ badge cpp_pattern = r"\[\!\[C\+\+ Solutions\].*?\)\]\(.*?\)"