|
| 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 |
0 commit comments