From 72f8543268f436f22d121e39fa218ec5ae7c6deb Mon Sep 17 00:00:00 2001 From: mathusanm6 Date: Sun, 31 Aug 2025 11:27:50 +0200 Subject: [PATCH 1/3] fix: update badges workflow fails trying to push to main fix: error on push docs: update problem count badges [skip ci] fix: color docs: update problem count badges [skip ci] --- .github/workflows/update-badges.yml | 13 ++++++++++--- scripts/update_badges.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) 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\].*?\)\]\(.*?\)" From 2d753c527fe777d5af9156644711869bc2bfafb9 Mon Sep 17 00:00:00 2001 From: Mathusan Selvakumar Date: Sun, 31 Aug 2025 11:55:16 +0200 Subject: [PATCH 2/3] Update .github/workflows/update-badges.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/update-badges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-badges.yml b/.github/workflows/update-badges.yml index 3b876c9..343f7e5 100644 --- a/.github/workflows/update-badges.yml +++ b/.github/workflows/update-badges.yml @@ -42,8 +42,8 @@ jobs: git add README.md git commit -m "docs: update problem count badges [skip ci]" - # Get the current branch name from the GitHub context - BRANCH_NAME="${{ github.head_ref || github.ref_name }}" + # 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 From d3f29116b510d57d92fb4679ea222738800c2829 Mon Sep 17 00:00:00 2001 From: Mathusan Selvakumar Date: Sun, 31 Aug 2025 11:55:35 +0200 Subject: [PATCH 3/3] Update .github/workflows/update-badges.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/update-badges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-badges.yml b/.github/workflows/update-badges.yml index 343f7e5..ecac212 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 - pull_request: + push: branches: ["main"] workflow_dispatch: # Allow manual triggering