-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (50 loc) · 1.61 KB
/
index.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
const fs = require('fs');
const path = require('path');
const core = require('@actions/core')
function gatherPathsRecursive(dir, baseDir, allPaths) {
fs.readdirSync(dir).forEach(fileName => {
const filePath = path.join(dir, fileName);
if (fs.lstatSync(filePath).isDirectory()) {
gatherPathsRecursive(filePath, baseDir, allPaths);
} else {
allPaths.push(path.relative(baseDir, filePath));
}
});
}
function gatherPathsLongestFirst(baseDir) {
allPaths = [];
gatherPathsRecursive(baseDir, baseDir, allPaths);
allPaths.sort((a, b) => {
// sort longest first
const lengthCmp = b.length - a.length;
if (lengthCmp != 0) {
return lengthCmp;
} else {
// if same length then sort alphabetically
return a.localeCompare(b)
}
});
return allPaths;
}
try {
const limit = core.getInput('limit') || 150
core.info(`Checking for paths exceeding limit=${limit}`)
allPaths = gatherPathsLongestFirst('.');
// print every path that exceeds the limit
let failed = false;
for (const filePath of allPaths) {
if (filePath.length > limit) {
failed = true
core.setFailed(`Path length=${filePath.length} exceeds limit=${limit}: ${filePath}`);
} else {
break;
}
}
// just FYI, here's you're longest path
if (!failed && allPaths.length > 0) {
longestPath = allPaths[0]
core.info(`Longest path length=${longestPath.length}: ${longestPath}`)
}
} catch (error) {
core.setFailed(error.message)
}