-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
43 lines (35 loc) · 1.11 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
const core = require('@actions/core');
const glob = require('glob');
const path = require('path');
const getDirectoryNames = (fileNames) =>
fileNames.map((fileName) => path.basename(path.dirname(fileName)));
function findFromDirectory({ searchDirectory, fileGlob, unique }) {
const adjustedSearchPath = `${process.cwd()}${searchDirectory}`
core.debug(process.cwd());
core.debug({ adjustedSearchPath });
const fileNames = glob.sync(fileGlob, { cwd: adjustedSearchPath });
core.debug({ fileNames });
const directoryNames = unique
? [...new Set(getDirectoryNames(fileNames))]
: getDirectoryNames(fileNames);
core.debug({ directoryNames });
return directoryNames;
}
try {
const searchDirectory = core.getInput('search-directory');
const fileGlob = core.getInput('file-glob');
const unique = JSON.parse(core.getInput('unique'));
core.debug({
searchDirectory,
fileGlob,
unique,
});
const directoryNames = findFromDirectory({
searchDirectory,
fileGlob,
unique,
});
core.setOutput('directory-names', directoryNames);
} catch (error) {
core.setFailed(error.message);
}