Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/update-progress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Update Progress in Markdown

on:
push:
paths:
- '**.md'
- update_progress.py

permissions:
contents: write

jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Run update script
run: python update_progress.py

- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "Update progress" || echo "No changes to commit"
git push
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,5 +662,5 @@
5. [500 Data Structures and Algorithms Practice Problems](https://kingrayhan.medium.com/500-data-structures-and-algorithms-practice-problems-and-their-solutions-b45a83d803f0)

<!-- progress:start -->
**Progress: calculating...**
**Progress: 19.12% completed (104/544)**
<!-- progress:end -->
26 changes: 26 additions & 0 deletions update_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import re

MARKDOWN_FILE = "README.md"

with open(MARKDOWN_FILE, "r") as f:
content = f.read()

# Extract all checkboxes
tasks = re.findall(r"- \[( |x)\]", content, re.IGNORECASE)
total = len(tasks)
completed = tasks.count("x") + tasks.count("X")
percent = (completed / total * 100) if total > 0 else 0
progress_line = f"**Progress: {percent:.2f}% completed ({completed}/{total})**"

# Replace between markers
new_content = re.sub(
r"<!-- progress:start -->.*?<!-- progress:end -->",
f"<!-- progress:start -->\n{progress_line}\n<!-- progress:end -->",
content,
flags=re.DOTALL
)

with open(MARKDOWN_FILE, "w") as f:
f.write(new_content)

print("Updated progress.")