Skip to content

Commit b230aac

Browse files
committed
chore: refresh theme stats monthly
1 parent f0574a4 commit b230aac

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Refresh Theme Stats
2+
3+
on:
4+
schedule:
5+
- cron: '43 4 8 * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
concurrency:
13+
group: refresh-theme-stats
14+
cancel-in-progress: false
15+
16+
jobs:
17+
refresh:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- uses: actions/setup-node@v6
23+
with:
24+
node-version: 24
25+
cache: npm
26+
27+
- run: npm ci
28+
29+
- name: Refresh repository metadata
30+
env:
31+
GITHUB_TOKEN: ${{ github.token }}
32+
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
33+
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
34+
run: npm run refresh:themes
35+
36+
- run: npm test
37+
- run: npm run build
38+
39+
- name: Open theme stats refresh PR
40+
env:
41+
GH_TOKEN: ${{ secrets.STATS_PR_TOKEN || github.token }}
42+
shell: bash
43+
run: |
44+
if git diff --quiet -- src/content/themes; then
45+
echo "No theme stats changes found."
46+
exit 0
47+
fi
48+
49+
branch="automation/theme-stats-refresh-$(date -u +%Y-%m)"
50+
report="theme-stats-refresh.md"
51+
52+
{
53+
echo "## Theme stats refresh"
54+
echo ""
55+
echo "Updates repository metadata for existing catalog entries:"
56+
echo ""
57+
echo "- stars"
58+
echo "- last update date"
59+
echo "- owner avatar"
60+
echo "- accessibility status"
61+
echo ""
62+
echo "This workflow does not discover new themes or change editorial fields."
63+
} > "$report"
64+
65+
git config user.name "github-actions[bot]"
66+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
67+
git checkout -B "$branch"
68+
git add src/content/themes
69+
git commit -m "chore: refresh theme repository stats"
70+
git fetch --no-tags --depth=1 origin "$branch:refs/remotes/origin/$branch" || true
71+
git push --force-with-lease origin "$branch"
72+
73+
manual_url="https://github.com/${GITHUB_REPOSITORY}/pull/new/${branch}"
74+
title="Refresh theme repository stats"
75+
76+
if pr_url="$(gh pr view "$branch" --json url --jq .url 2>/dev/null)"; then
77+
gh pr edit "$branch" \
78+
--title "$title" \
79+
--body-file "$report"
80+
echo "Updated theme stats refresh PR: ${pr_url}" >> "$GITHUB_STEP_SUMMARY"
81+
else
82+
if pr_url="$(gh pr create \
83+
--base main \
84+
--head "$branch" \
85+
--title "$title" \
86+
--body-file "$report" 2>pr-create-error.txt)"; then
87+
echo "Created theme stats refresh PR: ${pr_url}" >> "$GITHUB_STEP_SUMMARY"
88+
else
89+
echo "::warning::The stats refresh branch was pushed, but GitHub refused to create the PR automatically."
90+
cat pr-create-error.txt
91+
{
92+
echo "Theme stats changes were pushed to \`${branch}\`, but the workflow token could not create the PR automatically."
93+
echo ""
94+
echo "Open it manually: ${manual_url}"
95+
echo ""
96+
echo "To allow automatic PR creation, enable **Settings > Actions > General > Workflow permissions > Allow GitHub Actions to create and approve pull requests**, or add a \`STATS_PR_TOKEN\` secret with permission to create pull requests."
97+
} >> "$GITHUB_STEP_SUMMARY"
98+
fi
99+
fi

MEMORY.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ This file stores durable project context so future conversations can resume work
3636
- `.github/workflows/create-theme-submission.yml`
3737
- `.github/workflows/publish-approved-theme-submission.yml`
3838
- `.github/workflows/close-merged-theme-submission.yml`
39+
- `.github/workflows/refresh-theme-stats.yml`
3940
- CI workflows now opt into Node 24 for JavaScript actions explicitly and use `actions/checkout@v6` plus `actions/setup-node@v6`
4041
- Build workflow runs automatically on pushes to `main` that affect Astro site/build inputs and deploys `dist/` through GitHub Pages artifacts
4142
- PR validation runs `npm test` and `npm run build` for site-related changes
4243
- Theme submission automation uses GitHub Issue Forms plus `.github/workflows/create-theme-submission.yml`; it creates candidate PRs from complete submission issues without Decap or external auth hosting
4344
- Approved submission PRs are finalized by `.github/workflows/publish-approved-theme-submission.yml`, which sets `status: "published"` and assigns the next available low `catalogIndex`; maintainers still merge the PR explicitly
4445
- Merged submission PRs close their source issue through `.github/workflows/close-merged-theme-submission.yml`; new generated PR bodies also include `Closes #<issue>`
46+
- `.github/workflows/refresh-theme-stats.yml` runs monthly and opens a PR for changed repository stars, update dates, owner avatars, or accessibility values
4547
- The build workflow syntax also requires `workflow_dispatch:` with a trailing colon; missing it makes GitHub mark the workflow file as invalid even if other checks still pass
4648

4749
## Repo Notes
@@ -72,7 +74,7 @@ This file stores durable project context so future conversations can resume work
7274
## Known Technical Risks
7375

7476
- Automatic submission PR creation depends on repository workflow permissions. If `GITHUB_TOKEN` cannot create PRs, the workflow still pushes `submissions/theme-<issue-number>` and reports a manual PR URL; add `SUBMISSION_PR_TOKEN` or enable GitHub Actions PR creation to make it fully automatic.
75-
- `scripts/refresh-theme-stats.mjs` uses external APIs when run manually or in future automation; it should never discover new repositories
77+
- `scripts/refresh-theme-stats.mjs` uses external APIs when run manually or through the monthly stats refresh workflow; it should never discover new repositories
7678
- `.github/workflows/audit-theme-repositories.yml` runs monthly and creates a PR when repositories should be archived or removed; it audits both `published` and `archived` entries, but only `published` entries are moved into the archive. If an archived entry later becomes unavailable, it is proposed for removal. If `GITHUB_TOKEN` is blocked from creating PRs, it still pushes the audit branch and reports a manual PR URL. Automatic PR creation requires enabling the repository's "Allow GitHub Actions to create and approve pull requests" setting or adding an `AUDIT_PR_TOKEN` secret with PR creation permission.
7779
- Existing legacy theme entries are marked with `submitterRole: "legacy"` because original submitter relationship is unknown
7880

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ The generated entry remains `status: "candidate"` until a maintainer approves th
5656

5757
It does not search for new themes, crawl topics, or change editorial fields such as title, description, tags, screenshots, or publication status.
5858

59+
The monthly `Refresh Theme Stats` workflow runs the same refresh command and opens a review PR when stars, update dates, avatars, or accessibility values change.
60+
5961
## Repository Audit
6062

6163
`npm run audit:theme-repos` checks the repositories already listed in the catalog. It does not discover new repositories.

0 commit comments

Comments
 (0)