Skip to content

Best Practices

Best Practices #2

name: Best Practices
on:
push:
paths:
- 'BestPracticesChecklist.md'
schedule:
- cron: '0 9 * * 1' # Every Monday 9am UTC (for criteria sync)
workflow_dispatch:
permissions:
contents: write
jobs:
update-score:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Parse checklist and compute score
run: |
python3 << 'EOF'
import json, re
from datetime import date
CATEGORY_HEADERS = {
"## πŸ—οΈ Basics": "basics",
"## πŸ”„ Change Control": "change_control",
"## πŸ› Reporting": "reporting",
"## βœ… Quality": "quality",
"## πŸ” Security": "security",
"## πŸ”¬ Analysis": "analysis",
}
CATEGORY_TOTALS = {
"basics": 7,
"change_control": 6,
"reporting": 8,
"quality": 6,
"security": 9,
"analysis": 7,
}
with open("BestPracticesChecklist.md") as f:
content = f.read()
lines = content.splitlines()
current_cat = None
counts = {k: 0 for k in CATEGORY_TOTALS}
for line in lines:
stripped = line.strip()
for header, cat in CATEGORY_HEADERS.items():
if stripped == header:
current_cat = cat
break
# [x] = Met, [~] = N/A (counts as met)
if current_cat and re.match(r'- \[[xX~]\]', stripped):
counts[current_cat] += 1
total_met = sum(counts.values())
total = sum(CATEGORY_TOTALS.values())
percent = round((total_met / total) * 100) if total > 0 else 0
if percent >= 80:
color = "brightgreen"
elif percent >= 60:
color = "yellow"
elif percent >= 40:
color = "orange"
else:
color = "red"
status = {
"schemaVersion": 1,
"label": "Best Practices",
"message": f"{percent}%",
"schema": "aossie-best-practices-v1",
"updated": str(date.today()),
"met": total_met,
"total": total,
"percent": percent,
"color": color,
"categories": {
cat: {"met": counts[cat], "total": CATEGORY_TOTALS[cat]}
for cat in CATEGORY_TOTALS
}
}
with open("checklist-status.json", "w") as f:
json.dump(status, f, indent=2)
print(f"Score: {total_met}/{total} ({percent}%)")
EOF
- name: Update score table in BestPracticesChecklist.md
run: |
python3 << 'EOF'
import json, re
with open("checklist-status.json") as f:
status = json.load(f)
# Format status icon for categories based on completion
def get_status_icon(met, total):
if met == total:
return "🟒"
elif met >= total * 0.75:
return "🟑"
return "πŸ”΄"
cats = status["categories"]
table = f"""| Category | Met | Total | Status |
|--------------------|-----|-------|--------|
| Basics | {cats['basics']['met']} | {cats['basics']['total']} | {get_status_icon(cats['basics']['met'], cats['basics']['total'])} |
| Change Control | {cats['change_control']['met']} | {cats['change_control']['total']} | {get_status_icon(cats['change_control']['met'], cats['change_control']['total'])} |
| Reporting | {cats['reporting']['met']} | {cats['reporting']['total']} | {get_status_icon(cats['reporting']['met'], cats['reporting']['total'])} |
| Quality | {cats['quality']['met']} | {cats['quality']['total']} | {get_status_icon(cats['quality']['met'], cats['quality']['total'])} |
| Security | {cats['security']['met']} | {cats['security']['total']} | {get_status_icon(cats['security']['met'], cats['security']['total'])} |
| Analysis | {cats['analysis']['met']} | {cats['analysis']['total']} | {get_status_icon(cats['analysis']['met'], cats['analysis']['total'])} |
| **Total** | **{status['met']}** | **{status['total']}** | **{status['percent']}%** |"""
with open("BestPracticesChecklist.md", "r") as f:
content = f.read()
# Replace everything between the marker and the next --- line
new_content = re.sub(
r'(?<=<!-- Auto-updated by checklist-score\.yml workflow β€” do not edit manually -->\n).*?(?=\n---)',
table.strip(),
content,
flags=re.DOTALL
)
with open("BestPracticesChecklist.md", "w") as f:
f.write(new_content)
EOF
- name: Commit and push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add BestPracticesChecklist.md checklist-status.json
git commit -m "chore: auto-update Best Practices checklist score and status [skip ci]" || echo "No changes to commit"
git push