-
Notifications
You must be signed in to change notification settings - Fork 4
77 lines (67 loc) · 3.14 KB
/
update-stats.yml
File metadata and controls
77 lines (67 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Update package stats
# ── Triggers ─────────────────────────────────────────────────────────────────
on:
# Run daily at 06:00 UTC
schedule:
- cron: '0 6 * * *'
# Run whenever a human edits catalog.json (new package added / removed)
push:
branches: [main]
paths:
- 'data/catalog.json'
# Allow manual runs from the Actions tab
workflow_dispatch:
# ── Permissions ───────────────────────────────────────────────────────────────
# contents: write → lets the bot commit data/stats.json back to the repo
# actions: write → lets the bot dispatch static.yml (Pages deploy) via gh CLI
permissions:
contents: write
actions: write
# ── Job ───────────────────────────────────────────────────────────────────────
jobs:
update-stats:
runs-on: ubuntu-latest
steps:
# 1. Check out the repo
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# 2. Setup pixi (provides the Python interpreter)
- name: Setup pixi
uses: prefix-dev/setup-pixi@a0af7a228712d6121d37aba47adf55c1332c9c2e # v0.9.4
with:
pixi-version: latest
cache: true
# 3. Fetch stats and write data/stats.json
# GITHUB_TOKEN is injected automatically; script uses it for the
# GitHub API (5 000 req/h instead of 60 req/h unauthenticated).
- name: Fetch stats
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pixi run update-stats
# 3. Commit only if the file actually changed.
# The commit message intentionally does NOT include [skip ci] so that
# the Pages deploy workflow picks up the fresh stats.json.
# Note: pushes made with GITHUB_TOKEN do not re-trigger this workflow,
# so there is no circular dependency.
- name: Commit stats.json
id: commit
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add data/stats.json
if git diff --staged --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No changes — skipping commit."
else
git commit -m "chore: update package stats"
git push
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
# 4. Explicitly re-deploy Pages so the new stats are live right away.
# (GITHUB_TOKEN commits don't automatically trigger other workflows.)
# Requires static.yml to have a workflow_dispatch trigger — it does.
- name: Trigger Pages deploy
if: steps.commit.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh workflow run static.yml --ref main