Repository navigation
170 lines (158 loc) · 8.22 KB
/
Copy pathplugin-stats.yml
File metadata and controls
170 lines (158 loc) · 8.22 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Daily plugin stats refresh: runs scripts/fetch_plugin_stats.py (reads
# data/plugin-registry.json, writes data/plugin-stats.json) and opens a PR with
# the output only when it changed.
#
# Tokens:
# - GITHUB_TOKEN can no longer commit to main: the branch ruleset rejects a
# direct push with GH013 ("Changes must be made through a pull request"),
# which is what had been failing every daily run. It is still enough to
# push a branch and open the PR, given `pull-requests: write` below.
# - Work opened or pushed by github-actions[bot] leaves pr-build.yml stuck in
# `action_required`: the bot never graduates into a contributor, so the
# required "Lint, typecheck & PR-mode build" check reports nothing until
# someone approves the run by hand, every single day.
# Relaxing the fork-PR approval policy does NOT fix this — that setting
# governs PRs from forks, and this branch lives in the repo. (Verified
# 2026-08-30: policy relaxed to first_time_contributors_new_to_github, a
# fresh run still came back action_required, policy reverted.) The fix is
# identity — work carrying the fiestaboard-ci-bot App's token runs ungated,
# as PR #50 shows.
# - The App token is minted first and handed to BOTH checkout and the PR
# step. Checkout matters as much as the PR call: the branch is long-lived
# and reused, so on most days the trigger is `synchronize` from the
# force-push rather than `opened` from the PR creation, and a run is
# attributed to whoever pushed.
# - continue-on-error plus the `||` fallbacks mean a missing or rotated App
# secret degrades to the old gated-but-working behavior rather than failing
# the daily refresh outright.
# - pr-build.yml's synced-paths guard skips this branch by name — its whole
# diff is data/, which that guard otherwise rejects.
# - The traffic API (repos/*/traffic/clones) needs Administration:read on
# each plugin repo. The CI App token above cannot carry it: it is scoped to
# `repositories: fiestaboard.github.io`. So the fetch step mints a SECOND
# token — every repo the App is installed on (all 52 org plugin repos),
# scoped down to Administration+Contents read and nothing else. It is a
# read-only credential that never touches this repo's contents.
# This requires `Administration: Read-only` on the fiestaboard-ci-bot App;
# without it the mint fails, the `||` chain falls back to RELEASE_PAT and
# then GITHUB_TOKEN, neither of which can read traffic, and the fetch
# script now exits nonzero rather than publishing null stats.
# The community-hosted plugin (breedloj/*) is outside the installation and
# stays null by design; the site excludes it from the ranking.
name: Plugin stats
on:
schedule:
- cron: "17 6 * * *" # daily, off the top of the hour
workflow_dispatch: {}
concurrency:
group: plugin-stats
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
jobs:
refresh:
runs-on: ubuntu-latest
# data/ is owned by the branch this site builds from. Scheduled runs only
# ever fire from the default branch's workflow file anyway; this guard is
# belt-and-suspenders so a cron run never mutates a non-main ref (e.g.
# while this file exists on other branches pre-cutover). workflow_dispatch
# stays allowed on any ref for testing.
if: github.event_name != 'schedule' || github.ref == 'refs/heads/main'
steps:
- name: Mint CI App token
id: app-token
continue-on-error: true
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.CLAUDE_BOT_APP_ID }}
private-key: ${{ secrets.CLAUDE_BOT_APP_PRIVATE_KEY }}
owner: Fiestaboard
repositories: fiestaboard.github.io
- uses: actions/checkout@v7
with:
# Persisted as the origin credential, so the force-push below is
# attributed to the App and its `synchronize` run is ungated.
token: ${{ steps.app-token.outputs.token || github.token }}
# Org-wide but read-only: omitting `repositories` covers every repo the
# App is installed on, and the permission-* inputs scope the token down
# to exactly what the fetch needs — traffic (Administration) and
# manifest.json (Contents).
- name: Mint traffic-read token
id: traffic-token
continue-on-error: true
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.CLAUDE_BOT_APP_ID }}
private-key: ${{ secrets.CLAUDE_BOT_APP_PRIVATE_KEY }}
owner: Fiestaboard
permission-administration: read
permission-contents: read
permission-metadata: read
- name: Fetch plugin stats
env:
GH_TOKEN: ${{ steps.traffic-token.outputs.token || secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }}
run: python3 scripts/fetch_plugin_stats.py
- name: Open PR if changed
id: commit
env:
GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
run: |
set -euo pipefail
git add -- data/plugin-stats.json
if git diff --cached --quiet; then
echo "No stats changes; skipping commit."
echo "pushed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git config user.name "FiestaBoard CI"
git config user.email "ci@fiestaboard.app"
git commit -m "data: refresh plugin stats"
# Only main is protected; a workflow_dispatch rehearsal on a scratch
# ref still commits straight to it. Rebase-and-retry guards against
# races with other daily commits.
if [ "$GITHUB_REF_NAME" != "main" ]; then
git pull --rebase origin "$GITHUB_REF_NAME"
git push origin "HEAD:$GITHUB_REF_NAME"
echo "pushed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# One long-lived branch, force-pushed from today's main, so an
# unmerged refresh is replaced rather than turning into a PR a day.
# Same shape as release-snapshot.yml's snapshot PR.
BRANCH="data/plugin-stats"
git push --force origin "HEAD:$BRANCH"
# REST, not `gh pr view`: that answers about any PR on the branch,
# including yesterday's merged one, which on a reused branch would
# skip the create and strand the refresh. `state=open` is the
# question actually being asked.
EXISTING=$(gh api \
"repos/$GITHUB_REPOSITORY/pulls?head=${GITHUB_REPOSITORY%%/*}:$BRANCH&state=open" \
--jq '.[0].number // empty')
if [ -n "$EXISTING" ]; then
echo "refreshed the open stats PR #$EXISTING"
else
NUM=$(gh api -X POST "repos/$GITHUB_REPOSITORY/pulls" \
-f title="data: refresh plugin stats" \
-f head="$BRANCH" -f base=main \
-f body="Daily plugin-stats refresh cut by \`.github/workflows/plugin-stats.yml\`. The branch is force-pushed on every run, so this PR always carries the newest numbers; merging publishes them through \`build-deploy.yml\`." \
--jq .number)
echo "opened stats PR #$NUM"
fi
# The refresh is on a branch, not on main, so the deploy trigger
# below must not fire — merging the PR is a push to main, which
# starts build-deploy.yml by itself.
echo "pushed=false" >> "$GITHUB_OUTPUT"
# Reachable only on the non-main rehearsal path above: that push used
# GITHUB_TOKEN, which never fires other workflows' push triggers, so
# start the site build+deploy explicitly. The App token, not
# github.token: dispatching needs `actions: write`, which the job's
# GITHUB_TOKEN is not granted (verified 2026-08-30 — a rehearsal run
# 403'd here on `.../actions/workflows/335166277/dispatches`). Borrowing
# the App's existing actions:write beats widening GITHUB_TOKEN for a
# step that never runs on main.
- name: Trigger site build & deploy
if: steps.commit.outputs.pushed == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
run: gh workflow run build-deploy.yml --repo "$GITHUB_REPOSITORY" --ref "$GITHUB_REF_NAME"