-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (25 loc) · 951 Bytes
/
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
"use strict";
const core = require("@actions/core");
const { promises: fs } = require("fs");
const main = () => {
const filePaths = JSON.parse(core.getInput("files"));
const regularExpression = core.getInput("pattern");
const pattern = new RegExp(regularExpression);
const matchingFilePaths = filePaths
.filter((filePath) => pattern.test(filePath));
return Promise.all([
Promise.resolve(matchingFilePaths),
...matchingFilePaths.map((filePath) => fs.readFile(process.env.GITHUB_WORKSPACE + "/" + filePath, "utf8"))
]);
};
main()
.then((response) => {
const [matchingFilePaths, ...fileContents] = response;
let output = '';
fileContents.forEach((content, index) => {
output += `========================== ${matchingFilePaths[index]} ==========================\n\n`;
output += content + "\n\n";
})
core.setOutput("content", output);
})
.catch((err) => core.setFailed(err.message));