|
| 1 | +name: aggregate-ratings |
| 2 | +on: |
| 3 | + push: |
| 4 | + paths: |
| 5 | + - 'reviews/**/*.json' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + aggregate: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + - name: Aggregate ratings |
| 16 | + run: | |
| 17 | + python3 << 'EOF' |
| 18 | + import json, os, glob |
| 19 | + from collections import defaultdict |
| 20 | +
|
| 21 | + ratings = {"version": "1", "updated": "", "skills": {}} |
| 22 | +
|
| 23 | + # Scan all review files |
| 24 | + for f in glob.glob("reviews/*/*.json"): |
| 25 | + try: |
| 26 | + with open(f) as fh: |
| 27 | + data = json.load(fh) |
| 28 | + skill_id = f.split("/")[1] |
| 29 | + if skill_id not in ratings["skills"]: |
| 30 | + ratings["skills"][skill_id] = { |
| 31 | + "average": 0, |
| 32 | + "count": 0, |
| 33 | + "reviews": [] |
| 34 | + } |
| 35 | + ratings["skills"][skill_id]["reviews"].append({ |
| 36 | + "rating": data.get("rating", 0), |
| 37 | + "content": data.get("content", ""), |
| 38 | + "author": data.get("author", ""), |
| 39 | + "createdAt": data.get("createdAt", ""), |
| 40 | + }) |
| 41 | + except Exception: |
| 42 | + pass |
| 43 | +
|
| 44 | + # Calculate averages |
| 45 | + from datetime import datetime, timezone |
| 46 | + for sid, skill in ratings["skills"].items(): |
| 47 | + if skill["reviews"]: |
| 48 | + skill["average"] = round( |
| 49 | + sum(r["rating"] for r in skill["reviews"]) / len(skill["reviews"]), 1 |
| 50 | + ) |
| 51 | + skill["count"] = len(skill["reviews"]) |
| 52 | +
|
| 53 | + ratings["updated"] = datetime.now(timezone.utc).isoformat() |
| 54 | +
|
| 55 | + with open("ratings.json", "w") as fh: |
| 56 | + json.dump(ratings, fh, indent=2, ensure_ascii=False) |
| 57 | + print(f"Aggregated {len(ratings['skills'])} skills with reviews") |
| 58 | + EOF |
| 59 | + - name: Commit updated ratings |
| 60 | + run: | |
| 61 | + git config user.name "github-actions[bot]" |
| 62 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 63 | + git add ratings.json |
| 64 | + git diff --staged --quiet || git commit -m "chore: aggregate ratings [automated]" |
| 65 | + git push |
0 commit comments