-
-
Notifications
You must be signed in to change notification settings - Fork 660
Expand file tree
/
Copy pathpr.mjs
More file actions
91 lines (74 loc) · 2.07 KB
/
pr.mjs
File metadata and controls
91 lines (74 loc) · 2.07 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
#!/usr/bin/env node
/**
* Run this script (from root directory):
*
* $ corepack pnpm node scripts/pr.mjs path/1 path/2 path/3
*
* This will run following checks:
*
* 1. Find the exercises at all the paths provided
* 2. Run tests for those exercises against sample solutions
*/
import shell from 'shelljs';
import {
findExerciseDirectory,
prepareAndRun,
prepare,
cleanUp,
registerExitHandler,
assignments,
} from './helpers.mjs';
const files = process.argv.slice(2);
if (files.length === 0) {
shell.echo(
'[Failure] No files passed in. Pass in paths to exercise directories or its file.',
);
shell.exit(-1);
}
shell.echo('[Files] The files passed in are as follows:');
files.forEach((file) => {
shell.echo(`[Files] ${file}`);
});
const _exercises = files
.map(findExerciseDirectory)
.filter(Boolean)
.filter((exercise, index, array) => array.indexOf(exercise) === index);
const hasRootFile = files.some((file) => file === 'package.json');
if (hasRootFile) {
shell.echo(
'[Root PR] When package.json is changed, all exercises need to be checked',
);
} else if (_exercises.length > 8) {
shell.echo(
'[Big PR] When more than 8 exercises are being checked, all of them are ' +
'checked as this is likely a PR affecting everything.',
);
}
const exercises =
hasRootFile || _exercises.length > 8 ? assignments : _exercises;
if (exercises.length === 0) {
shell.echo('[Skip] None of the files are inside an exercise directory.');
shell.exit(0);
}
registerExitHandler(false);
shell.env['PREPARE'] = false;
shell.env['CLEANUP'] = false;
const infoStr = `Running tests for ${
exercises.length === 1 ? exercises[0] : `${exercises.length} exercises\n`
}`;
const failureStr = '[Failure] Tests failed!';
// Prepare exercises
exercises.forEach(prepare);
// Run tests
prepareAndRun(
'corepack pnpm jest --bail tmp_exercises --runInBand',
infoStr,
failureStr,
);
shell.echo(
exercises.length === 1
? `[Success] Tests passed for ${exercises[0]}`
: `[Success] Tests passed for all ${exercises.length} exercises`,
);
// Cleanup
cleanUp();