Update fonts data #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update fonts data | |
| on: | |
| schedule: | |
| # Mondays 06:00 UTC. | |
| - cron: "0 6 * * 1" | |
| workflow_dispatch: | |
| inputs: | |
| skip-svg: | |
| description: "Skip SVG preview generation" | |
| type: boolean | |
| default: false | |
| skip-stats: | |
| description: "Skip popular stats refresh" | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| concurrency: | |
| group: fonts-refresh | |
| cancel-in-progress: false | |
| jobs: | |
| refresh: | |
| # Don't run on forks — they don't have the secret and will spam issues. | |
| if: github.repository == 'gridaco/fonts' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| fetch-depth: 1 | |
| - name: Bump vendor/google submodule to latest | |
| run: | | |
| git submodule update --remote --force vendor/google | |
| echo "vendor/google now at: $(git -C vendor/google rev-parse --short HEAD)" | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: pip | |
| cache-dependency-path: tools/requirements.txt | |
| - name: Install Python deps | |
| run: pip install -r tools/requirements.txt | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: pnpm | |
| cache-dependency-path: www/pnpm-lock.yaml | |
| - name: Run refresh pipeline | |
| env: | |
| GOOGLE_FONTS_API_KEY: ${{ secrets.GOOGLE_FONTS_API_KEY }} | |
| run: | | |
| FLAGS="" | |
| if [ "${{ inputs.skip-svg }}" = "true" ]; then FLAGS="$FLAGS --skip-svg"; fi | |
| if [ "${{ inputs.skip-stats }}" = "true" ]; then FLAGS="$FLAGS --skip-stats"; fi | |
| ./tools/refresh.sh $FLAGS | |
| - name: Typecheck www (sanity gate) | |
| working-directory: www | |
| run: | | |
| pnpm install --frozen-lockfile | |
| pnpm typecheck | |
| - name: Summarize changes | |
| id: summary | |
| run: | | |
| { | |
| echo "summary<<EOF" | |
| git diff --stat | |
| echo "" | |
| echo "## broken.lock.json counts" | |
| if [ -f broken.lock.json ]; then | |
| python -c "import json; d=json.load(open('broken.lock.json')); [print(f'- {k}: {v}') for k,v in d['counts'].items()]" | |
| fi | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Create pull request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| commit-message: "chore(data): refresh fonts data" | |
| branch: bot/fonts-update | |
| delete-branch: true | |
| title: "chore(data): refresh fonts data" | |
| body: | | |
| Automated refresh from `tools/refresh.sh`. | |
| Review `broken.lock.json` for families in a degraded state. | |
| ${{ steps.summary.outputs.summary }} | |
| labels: | | |
| bot:fonts-refresh | |
| - name: Open or update failure issue | |
| if: failure() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = "[bot] fonts refresh failing"; | |
| const label = "bot:fonts-refresh"; | |
| const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
| const body = `Run [${context.runId}](${runUrl}) failed on \`${context.sha.slice(0,7)}\`.\n\nCheck the logs and the \`tools/refresh.sh\` preflight output. If \`vendor/google\` layout changed upstream, the preflight will have aborted with exit code 10/11.`; | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, repo: context.repo.repo, | |
| state: "open", labels: label, per_page: 5, | |
| }); | |
| const existing = issues.find(i => i.title === title); | |
| if (existing) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, repo: context.repo.repo, | |
| issue_number: existing.number, body, | |
| }); | |
| } else { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, repo: context.repo.repo, | |
| title, body, labels: [label], | |
| }); | |
| } |