-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-lang-ci.js
100 lines (88 loc) · 2.47 KB
/
check-lang-ci.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
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
94
95
96
97
98
99
100
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
function allLanguages() {
return fs
.readdirSync('examples')
.filter(
(x) =>
x.endsWith('.yaml') && fs.statSync(path.join('examples', x)).isFile()
)
.map((x) => x.replace(/\.yaml$/, ''));
}
function transitiveLanguages() {
const langs = allLanguages();
const transitive = {};
for (const lang of langs) {
transitive[lang] = [];
}
for (const lang of langs) {
const languageYaml = yaml.load(
fs.readFileSync(path.join('examples', lang + '.yaml'))
);
if (languageYaml.extends) {
const ext = languageYaml.extends;
if (ext.startsWith('dcc://')) {
transitive[ext.replace('dcc://', '')].push(lang);
}
}
}
return transitive;
}
function output(langs = [], buildBase = false) {
console.log(`languages=${JSON.stringify(langs)}`);
allLanguages().forEach((lang) => {
console.log(
`dcc${lang.substring(0, 1).toUpperCase()}${lang.substring(
1
)}=${langs.includes(lang)}`
);
});
console.log(`buildLanguages=${!!langs.length}`);
console.log(`buildBase=${buildBase}`);
process.exit(0);
}
const fallback = setTimeout(() => {
output(allLanguages());
}, 2000);
const stdin = process.openStdin();
let data = '';
stdin.on('data', function (chunk) {
data += chunk;
});
stdin.on('end', function () {
const changed = data.split('\n').filter((x) => x);
const buildBase = changed.some(
(x) =>
['.github/workflows/publish.yaml', 'check-lang-ci.js'].includes(x) ||
['base-images/', 'features/'].some((p) => x.startsWith(p))
);
if (
buildBase ||
changed.some((x) =>
[
'package.json',
'webpack.config.js',
'tsconfig.json',
'language_schema.json',
].includes(x)
) ||
changed.some((x) => ['src/'].some((p) => x.startsWith(p)))
) {
output(allLanguages(), buildBase);
} else if (changed.some((x) => x.startsWith('examples/'))) {
const transitive = transitiveLanguages();
const build = changed
.filter((x) => x.startsWith('examples/'))
.map((x) => x.replace(/^examples\//, '').replace(/\.yaml$/, ''));
const buildWithTransitive = [];
for (const lang of build) {
buildWithTransitive.push(lang);
transitive[lang].forEach((x) => buildWithTransitive.push(x));
}
output(buildWithTransitive.filter((v, i, a) => a.indexOf(v) === i));
} else {
output();
}
fallback.unref();
});