Skip to content

Commit d68bd55

Browse files
committed
progress bar python script & github actions yml
1 parent c1e6e06 commit d68bd55

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Update Progress in Markdown
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.md'
7+
- update_progress.py
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
update:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Run update script
25+
run: python update_progress.py
26+
27+
- name: Commit changes
28+
run: |
29+
git config user.name "github-actions[bot]"
30+
git config user.email "github-actions[bot]@users.noreply.github.com"
31+
git add README.md
32+
git commit -m "Update progress" || echo "No changes to commit"
33+
git push

update_progress.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
3+
MARKDOWN_FILE = "README.md"
4+
5+
with open(MARKDOWN_FILE, "r") as f:
6+
content = f.read()
7+
8+
# Extract all checkboxes
9+
tasks = re.findall(r"- \[( |x)\]", content, re.IGNORECASE)
10+
total = len(tasks)
11+
completed = tasks.count("x") + tasks.count("X")
12+
percent = (completed / total * 100) if total > 0 else 0
13+
progress_line = f"**Progress: {percent:.2f}% completed ({completed}/{total})**"
14+
15+
# Replace between markers
16+
new_content = re.sub(
17+
r"<!-- progress:start -->.*?<!-- progress:end -->",
18+
f"<!-- progress:start -->\n{progress_line}\n<!-- progress:end -->",
19+
content,
20+
flags=re.DOTALL
21+
)
22+
23+
with open(MARKDOWN_FILE, "w") as f:
24+
f.write(new_content)
25+
26+
print("Updated progress.")

0 commit comments

Comments
 (0)