-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
54 lines (51 loc) · 1.59 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
const core = require("@actions/core");
const github = require("@actions/github");
const glob = require("glob");
const path = require("path");
const fs = require("fs");
try {
let sourceDir = core.getInput("source-dir");
if (!sourceDir) {
sourceDir = ".";
}
var getDirectories = function (src, callback) {
glob(src + "/**/*", callback);
};
getDirectories(sourceDir, function (err, res) {
if (err) {
throw err;
} else {
let foundDumps = false;
for (let i = 0; i < res.length; i++) {
let extension = path.extname(res[i]);
if (extension == ".twig") {
let re =
/((?<!{#\s*){{[ ]*dump\([^)]*\)[ ]*}}(?!\s*#}))|((?<={#\s*){{[ ]*dump\([^)]*\)[ ]*}}(?!\s*#}))|((?<!{#\s*){{[ ]*dump\([^)]*\)[ ]*}}(?=\s*#}))/gm;
const data = fs.readFileSync(res[i], "utf8");
var myArray = data.match(re);
if (myArray) {
foundDumps = true;
let errorMessage =
"Found " +
myArray.length +
" dumps in " +
res[i] +
" : " +
myArray.join(", ");
core.setFailed(errorMessage);
}
}
}
if (!foundDumps) {
core.setOutput("No dumps found in twig files");
}
}
});
const time = new Date().toTimeString();
core.setOutput("time", time);
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2);
console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}