Skip to content

Commit fae3027

Browse files
committed
Add automated update workflow
1 parent ab21aaa commit fae3027

3 files changed

Lines changed: 74 additions & 25 deletions

File tree

.github/workflows/checks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 'CI checks'
22

33
on:
44
push:
5-
branches: ['*']
5+
branches: ['master']
66
pull_request:
77
branches: ['master']
88

.github/workflows/update.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Update types'
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 * * *'
6+
7+
jobs:
8+
update:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Run tests
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: 24.x
16+
cache: 'npm'
17+
18+
- run: npm ci
19+
- run: npm run update -- --auto
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update.ts

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,48 +48,76 @@ async function update() {
4848

4949
await writeFileAsync('./package.json', JSON.stringify(nextPackageJson, null, 2) + '\n');
5050
await install();
51-
5251
await build();
5352

5453
const [indexDtsDiff, indexFlowDiff] = [
55-
await spawnAsync('git', '--no-pager', 'diff', '--color', TYPESCRIPT_FILENAME),
56-
await spawnAsync('git', '--no-pager', 'diff', '--color', FLOW_FILENAME),
54+
await spawnAsync('git', '--no-pager', 'diff', TYPESCRIPT_FILENAME),
55+
await spawnAsync('git', '--no-pager', 'diff', FLOW_FILENAME),
5756
];
5857

5958
if (indexDtsDiff !== '' || indexFlowDiff !== '') {
6059
console.info("Changes detected! Here's the diff:");
6160
console.info(indexDtsDiff);
6261
console.info(indexFlowDiff);
6362

64-
const doPrepare = await questionAsync('Do you want to prepare a release for this? (y/n) ');
65-
66-
if (doPrepare === 'y') {
63+
if (process.argv.includes('--auto')) {
6764
await spawnAsync('git', 'commit', '-am', 'Bump MDN');
65+
await spawnAsync('git', 'push', 'origin', 'HEAD');
66+
67+
let body = 'Automated update of types based on the latest MDN data:';
6868

69-
const [major, minor, patch] = nextPackageJson.version.split('.');
70-
const version = `${major}.${minor}.${Number(patch) + 1}`;
71-
const tag = `v${version}`;
69+
if (currentMdnDataVersion !== latestMdnDataVersion) {
70+
body += `\n- ${MDN_DATA}: ${currentMdnDataVersion}${latestMdnDataVersion}`;
71+
}
7272

73-
nextPackageJson.version = version;
73+
if (currentMdnCompatVersion !== latestMdnCompatVersion) {
74+
body += `\n- ${MDN_COMPAT}: ${currentMdnCompatVersion}${latestMdnCompatVersion}`;
75+
}
7476

75-
await writeFileAsync('./package.json', JSON.stringify(nextPackageJson, null, 2) + '\n');
76-
await spawnAsync('git', 'commit', '-am', tag);
77-
await spawnAsync('git', 'tag', tag);
77+
await spawnAsync(
78+
'gh',
79+
'pr',
80+
'create',
81+
'-B',
82+
'master',
83+
'-H',
84+
'HEAD',
85+
'--title',
86+
'"Update types"',
87+
'--body',
88+
JSON.stringify(body),
89+
);
90+
} else {
91+
const doPrepare = await questionAsync('Do you want to prepare a release for this? (y/n) ');
7892

79-
console.info(`The changes are committed and tagged with: ${tag}`);
93+
if (doPrepare === 'y') {
94+
await spawnAsync('git', 'commit', '-am', 'Bump MDN');
8095

81-
const doPush = await questionAsync('Do you want to push now? (y/n) ');
96+
const [major, minor, patch] = nextPackageJson.version.split('.');
97+
const version = `${major}.${minor}.${Number(patch) + 1}`;
98+
const tag = `v${version}`;
8299

83-
if (doPush === 'y') {
84-
console.info('Pushing...');
85-
await spawnAsync('git', 'push', 'origin', 'HEAD', '--tags');
100+
nextPackageJson.version = version;
101+
102+
await writeFileAsync('./package.json', JSON.stringify(nextPackageJson, null, 2) + '\n');
103+
await spawnAsync('git', 'commit', '-am', tag);
104+
await spawnAsync('git', 'tag', tag);
105+
106+
console.info(`The changes are committed and tagged with: ${tag}`);
107+
108+
const doPush = await questionAsync('Do you want to push now? (y/n) ');
109+
110+
if (doPush === 'y') {
111+
console.info('Pushing...');
112+
await spawnAsync('git', 'push', 'origin', 'HEAD', '--tags');
113+
}
114+
} else {
115+
console.info('Maybe next time!');
116+
console.info('Resetting...');
117+
await reset();
118+
console.info('Downgrading...');
119+
await install(true);
86120
}
87-
} else {
88-
console.info('Maybe next time!');
89-
console.info('Resetting...');
90-
await reset();
91-
console.info('Downgrading...');
92-
await install(true);
93121
}
94122
} else {
95123
console.info('No changes detected!');

0 commit comments

Comments
 (0)