Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'CI checks'

on:
push:
branches: ['*']
branches: ['master']
pull_request:
branches: ['master']

Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
76 changes: 52 additions & 24 deletions update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,76 @@ 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 !== '') {
console.info("Changes detected! Here's the diff:");
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!');
Expand Down