Skip to content

Commit 72f8543

Browse files
committed
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]
1 parent ee52675 commit 72f8543

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.github/workflows/update-badges.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Update Badges
33

44
on: # yamllint disable-line rule:truthy
5-
push:
5+
pull_request:
66
branches: ["main"]
77
workflow_dispatch: # Allow manual triggering
88

@@ -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 current branch name from the GitHub context
46+
BRANCH_NAME="${{ github.head_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)