Unverified Commit 64839033 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add update fonts workflow (#53645)

This adds a workflow to auto update our fonts data so we can stay up to date easier. 

Closes: https://github.com/vercel/next.js/pull/53246
Closes: https://github.com/vercel/next.js/pull/53510
parent bb380e77
name: update-font-data
on:
# Run every every day at midnight https://crontab.guru/#0_0_*_*_*/1
schedule:
- cron: '0 0 * * */1'
# Allow manual runs
workflow_dispatch:
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Commits made with the default `GITHUB_TOKEN` won't trigger workflows.
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
- name: Install dependencies
shell: bash
run: pnpm i
- name: Create Pull Request
shell: bash
run: node scripts/update-fonts-data-workflow.js
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
......@@ -171,6 +171,7 @@
"node-fetch": "2.6.7",
"npm-run-all": "4.1.5",
"nprogress": "0.2.0",
"octokit": "3.1.0",
"open": "9.0.0",
"outdent": "0.8.0",
"pixrem": "5.0.0",
......
This diff is collapsed.
const { promisify } = require('util')
const { Octokit } = require('octokit')
const { exec: execOriginal } = require('child_process')
const exec = promisify(execOriginal)
const GITHUB_TOKEN = process.env.GITHUB_TOKEN || ''
if (!GITHUB_TOKEN) {
console.log('missing GITHUB_TOKEN env')
process.exit(1)
}
async function main() {
const octokit = new Octokit({ auth: GITHUB_TOKEN })
const branchName = `update/fonts-data-${Date.now()}`
await exec(`node scripts/update-google-fonts.js`)
const changes = await exec('git status')
if (!changes.stdout.includes('Changes not staged')) {
console.log('No changes found', changes)
return
}
await exec(`git config user.name "vercel-release-bot"`)
await exec(`git config user.email "infra+release@vercel.com"`)
await exec(`git checkout -b ${branchName}`)
await exec(`git add -A`)
await exec(`git commit --message ${branchName}`)
await exec(`git push origin ${branchName}`)
const repo = 'next.js'
const owner = 'vercel'
const { data: pullRequests } = await octokit.rest.pulls.list({
owner,
repo,
state: 'open',
sort: 'created',
direction: 'desc',
per_page: 100,
})
const pullRequest = await octokit.rest.pulls.create({
owner,
repo,
head: branchName,
base: 'canary',
title: `Update font data`,
body: `This auto-generated PR updates font data with latest available`,
})
console.log('Created pull request', pullRequest.url)
const previousPullRequests = pullRequests.filter(({ title }) => {
return title.startsWith('Update font data')
})
if (previousPullRequests.length) {
for await (const previousPullRequest of previousPullRequests) {
console.log(
`Closing previous pull request: ${previousPullRequest.html_url}`
)
await octokit.rest.pulls.update({
owner,
repo,
pull_number: previousPullRequest.number,
state: 'closed',
})
}
}
}
main().catch(console.error)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment