-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
testpr-script.js
64 lines (56 loc) · 1.69 KB
/
testpr-script.js
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
const { spawn } = require('child_process');
const { argv } = require('yargs');
const username = require('username');
const id = argv._[0];
function spawnPromise(command, args) {
return new Promise((resolve, reject) => {
const p = spawn(command, args);
p.stdout.on('data', data => {
// eslint-disable-next-line
console.log(data.toString());
});
p.stderr.on('data', data => {
console.error(data.toString());
});
p.on('exit', code => {
if (code === 0) {
resolve();
} else {
reject();
}
});
});
}
async function test(prId) {
const branchName = `pr-${username.sync()}-${prId}`;
Promise.resolve()
.then(() => spawnPromise('git', ['checkout', 'master']))
.then(() => spawnPromise('git', ['branch', '-D', branchName]))
.catch(() => {
/* Do not care if this fails */
})
.then(() => spawnPromise('git', ['pull']))
.then(() =>
spawnPromise('git', [
'fetch',
'origin',
`pull/${prId}/head:${branchName}`,
])
)
.then(() => spawnPromise('git', ['checkout', branchName]))
.then(() => spawnPromise('git', ['merge', 'master']))
.then(() => spawnPromise('yarn', ['install']))
.then(() => spawnPromise('yarn', ['build:deps']))
.then(() => spawnPromise('yarn', ['typecheck']))
.then(() => spawnPromise('yarn', ['lint']))
.catch(() => {
console.error(
'Something wrong happened building the deps, maybe missing a new package added. Please install and run build:deps manually before continuing'
);
});
}
if (id && Number(id)) {
test(Number(id));
} else {
throw new Error('You have to pass the ID of a PR, ex: yarn test:pr 1234');
}