-
Notifications
You must be signed in to change notification settings - Fork 82
99 lines (85 loc) · 3.38 KB
/
refresh-theme-stats.yml
File metadata and controls
99 lines (85 loc) · 3.38 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
name: Refresh Theme Stats
on:
schedule:
- cron: '43 4 8 * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
concurrency:
group: refresh-theme-stats
cancel-in-progress: false
jobs:
refresh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- run: npm ci
- name: Refresh repository metadata
env:
GITHUB_TOKEN: ${{ github.token }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
run: npm run refresh:themes
- run: npm test
- run: npm run build
- name: Open theme stats refresh PR
env:
GH_TOKEN: ${{ secrets.STATS_PR_TOKEN || github.token }}
shell: bash
run: |
if git diff --quiet -- src/content/themes; then
echo "No theme stats changes found."
exit 0
fi
branch="automation/theme-stats-refresh-$(date -u +%Y-%m)"
report="theme-stats-refresh.md"
{
echo "## Theme stats refresh"
echo ""
echo "Updates repository metadata for existing catalog entries:"
echo ""
echo "- stars"
echo "- last update date"
echo "- owner avatar"
echo "- accessibility status"
echo ""
echo "This workflow does not discover new themes or change editorial fields."
} > "$report"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$branch"
git add src/content/themes
git commit -m "chore: refresh theme repository stats"
git fetch --no-tags --depth=1 origin "$branch:refs/remotes/origin/$branch" || true
git push --force-with-lease origin "$branch"
manual_url="https://github.com/${GITHUB_REPOSITORY}/pull/new/${branch}"
title="Refresh theme repository stats"
if pr_url="$(gh pr view "$branch" --json url --jq .url 2>/dev/null)"; then
gh pr edit "$branch" \
--title "$title" \
--body-file "$report"
echo "Updated theme stats refresh PR: ${pr_url}" >> "$GITHUB_STEP_SUMMARY"
else
if pr_url="$(gh pr create \
--base main \
--head "$branch" \
--title "$title" \
--body-file "$report" 2>pr-create-error.txt)"; then
echo "Created theme stats refresh PR: ${pr_url}" >> "$GITHUB_STEP_SUMMARY"
else
echo "::warning::The stats refresh branch was pushed, but GitHub refused to create the PR automatically."
cat pr-create-error.txt
{
echo "Theme stats changes were pushed to \`${branch}\`, but the workflow token could not create the PR automatically."
echo ""
echo "Open it manually: ${manual_url}"
echo ""
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."
} >> "$GITHUB_STEP_SUMMARY"
fi
fi