Skip to content

Commit a835dd9

Browse files
mathusanm6Copilot
andauthored
fix: update badges workflow fails trying to push to main (#75)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ee52675 commit a835dd9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.github/workflows/update-badges.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
with:
1616
token: ${{ secrets.GITHUB_TOKEN }}
17+
fetch-depth: 0
1718

1819
- name: Set up Python
1920
uses: actions/setup-python@v5
@@ -33,11 +34,17 @@ jobs:
3334
echo "changed=true" >> $GITHUB_OUTPUT
3435
fi
3536
36-
- name: Commit changes
37+
- name: Commit and push changes
3738
if: steps.verify-changed-files.outputs.changed == 'true'
3839
run: |
3940
git config --local user.email "action@github.com"
4041
git config --local user.name "GitHub Action"
4142
git add README.md
4243
git commit -m "docs: update problem count badges [skip ci]"
43-
git push
44+
45+
# Get the correct branch name for pushing
46+
BRANCH_NAME="${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}"
47+
echo "Pushing to branch: $BRANCH_NAME"
48+
49+
# Push to the correct branch
50+
git push origin HEAD:$BRANCH_NAME

scripts/update_badges.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def update_readme_badges(cpp_count, python_count):
5656

5757
# Define the new badge lines
5858
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)"
59-
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)"
59+
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)"
6060

6161
# Update C++ badge
6262
cpp_pattern = r"\[\!\[C\+\+ Solutions\].*?\)\]\(.*?\)"

0 commit comments

Comments
 (0)