From fae3027f30cc8d9bd3270d44ded9937f97bb4b60 Mon Sep 17 00:00:00 2001 From: Fredrik Nicol Date: Thu, 27 Nov 2025 11:16:06 +0100 Subject: [PATCH] Add automated update workflow --- .github/workflows/checks.yaml | 2 +- .github/workflows/update.yaml | 21 ++++++++++ update.ts | 76 ++++++++++++++++++++++++----------- 3 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/update.yaml diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 09d9c91..ef0f4e0 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -2,7 +2,7 @@ name: 'CI checks' on: push: - branches: ['*'] + branches: ['master'] pull_request: branches: ['master'] diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml new file mode 100644 index 0000000..f67281a --- /dev/null +++ b/.github/workflows/update.yaml @@ -0,0 +1,21 @@ +name: 'Update types' + +on: + schedule: + - cron: '0 6 * * *' + +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run tests + uses: actions/setup-node@v4 + with: + node-version: 24.x + cache: 'npm' + + - run: npm ci + - run: npm run update -- --auto + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/update.ts b/update.ts index ed97e8c..a8305b3 100644 --- a/update.ts +++ b/update.ts @@ -48,12 +48,11 @@ async function update() { await writeFileAsync('./package.json', JSON.stringify(nextPackageJson, null, 2) + '\n'); await install(); - await build(); const [indexDtsDiff, indexFlowDiff] = [ - await spawnAsync('git', '--no-pager', 'diff', '--color', TYPESCRIPT_FILENAME), - await spawnAsync('git', '--no-pager', 'diff', '--color', FLOW_FILENAME), + await spawnAsync('git', '--no-pager', 'diff', TYPESCRIPT_FILENAME), + await spawnAsync('git', '--no-pager', 'diff', FLOW_FILENAME), ]; if (indexDtsDiff !== '' || indexFlowDiff !== '') { @@ -61,35 +60,64 @@ async function update() { console.info(indexDtsDiff); console.info(indexFlowDiff); - const doPrepare = await questionAsync('Do you want to prepare a release for this? (y/n) '); - - if (doPrepare === 'y') { + if (process.argv.includes('--auto')) { await spawnAsync('git', 'commit', '-am', 'Bump MDN'); + await spawnAsync('git', 'push', 'origin', 'HEAD'); + + let body = 'Automated update of types based on the latest MDN data:'; - const [major, minor, patch] = nextPackageJson.version.split('.'); - const version = `${major}.${minor}.${Number(patch) + 1}`; - const tag = `v${version}`; + if (currentMdnDataVersion !== latestMdnDataVersion) { + body += `\n- ${MDN_DATA}: ${currentMdnDataVersion} → ${latestMdnDataVersion}`; + } - nextPackageJson.version = version; + if (currentMdnCompatVersion !== latestMdnCompatVersion) { + body += `\n- ${MDN_COMPAT}: ${currentMdnCompatVersion} → ${latestMdnCompatVersion}`; + } - await writeFileAsync('./package.json', JSON.stringify(nextPackageJson, null, 2) + '\n'); - await spawnAsync('git', 'commit', '-am', tag); - await spawnAsync('git', 'tag', tag); + await spawnAsync( + 'gh', + 'pr', + 'create', + '-B', + 'master', + '-H', + 'HEAD', + '--title', + '"Update types"', + '--body', + JSON.stringify(body), + ); + } else { + const doPrepare = await questionAsync('Do you want to prepare a release for this? (y/n) '); - console.info(`The changes are committed and tagged with: ${tag}`); + if (doPrepare === 'y') { + await spawnAsync('git', 'commit', '-am', 'Bump MDN'); - const doPush = await questionAsync('Do you want to push now? (y/n) '); + const [major, minor, patch] = nextPackageJson.version.split('.'); + const version = `${major}.${minor}.${Number(patch) + 1}`; + const tag = `v${version}`; - if (doPush === 'y') { - console.info('Pushing...'); - await spawnAsync('git', 'push', 'origin', 'HEAD', '--tags'); + nextPackageJson.version = version; + + await writeFileAsync('./package.json', JSON.stringify(nextPackageJson, null, 2) + '\n'); + await spawnAsync('git', 'commit', '-am', tag); + await spawnAsync('git', 'tag', tag); + + console.info(`The changes are committed and tagged with: ${tag}`); + + const doPush = await questionAsync('Do you want to push now? (y/n) '); + + if (doPush === 'y') { + console.info('Pushing...'); + await spawnAsync('git', 'push', 'origin', 'HEAD', '--tags'); + } + } else { + console.info('Maybe next time!'); + console.info('Resetting...'); + await reset(); + console.info('Downgrading...'); + await install(true); } - } else { - console.info('Maybe next time!'); - console.info('Resetting...'); - await reset(); - console.info('Downgrading...'); - await install(true); } } else { console.info('No changes detected!');