forked from nodejs/node-core-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminorUpdate.js
More file actions
93 lines (85 loc) · 2.33 KB
/
Copy pathminorUpdate.js
File metadata and controls
93 lines (85 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import path from 'node:path';
import { promises as fs } from 'node:fs';
import Enquirer from 'enquirer';
import { execa } from 'execa';
import { Listr } from 'listr2';
import { getCurrentV8Version } from './common.js';
import { isVersionString } from './util.js';
export default function minorUpdate() {
return {
title: 'Minor V8 update',
task: () => {
return new Listr([
getCurrentV8Version(),
getLatestV8Version(),
doMinorUpdate()
], {
injectWrapper: {
enquirer: new Enquirer()
}
});
}
};
};
function getLatestV8Version() {
return {
title: 'Get latest V8 version',
task: async(ctx) => {
const version = ctx.currentVersion;
const currentV8Tag = `${version.major}.${version.minor}.${version.build}`;
const result = await execa('git', ['tag', '-l', `${currentV8Tag}.*`], {
cwd: ctx.v8Dir,
encoding: 'utf8'
});
const tags = filterAndSortTags(result.stdout);
ctx.latestVersion = tags[0];
}
};
}
function doMinorUpdate() {
return {
title: 'Do minor update',
task: (ctx, task) => {
if (ctx.latestVersion.length === 3) {
throw new Error('minor update can only be done on release branches');
}
const latestStr = ctx.latestVersion.join('.');
task.title = `Do minor update to ${latestStr}`;
return applyPatch(ctx, latestStr);
},
skip: (ctx) => {
if (ctx.currentVersion.patch >= ctx.latestVersion[3]) {
ctx.skipped = 'V8 is up-to-date';
return ctx.skipped;
}
return false;
}
};
}
async function applyPatch(ctx, latestStr) {
const { stdout: diff } = await execa(
'git',
['format-patch', '--stdout', `${ctx.currentVersion}...${latestStr}`],
{ cwd: ctx.v8Dir, encoding: 'utf8' }
);
try {
await execa('git', ['apply', '--directory', 'deps/v8'], {
cwd: ctx.nodeDir,
input: diff
});
} catch (e) {
const file = path.join(ctx.nodeDir, `${latestStr}.diff`);
await fs.writeFile(file, diff);
throw new Error(`Could not apply patch.\n${e}\nDiff was stored in ${file}`);
}
}
function filterAndSortTags(tags) {
return tags
.split(/[\r\n]+/)
.filter(isVersionString)
.map((tag) => tag.split('.'))
.sort(sortVersions);
}
function sortVersions(v1, v2) {
return v2[3] - v1[3];
}