This repository was archived by the owner on Aug 2, 2023. It is now read-only.
generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
executable file
·67 lines (61 loc) · 1.68 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
57
58
59
60
61
62
63
64
65
66
67
const core = require("@actions/core");
const cdxgen = require("@appthreat/cdxgen");
const io = require("@actions/io");
const process = require("process");
const pathLib = require("path");
const fs = require("fs");
async function run() {
const output = core.getInput("output");
const projectId = core.getInput("projectId");
let projectName = core.getInput("projectName");
let projectVersion = core.getInput("projectVersion");
const serverUrl = core.getInput("serverUrl");
const apiKey = core.getInput("apiKey");
if (apiKey) {
core.setSecret(apiKey);
}
// Create any required output directories
await io.mkdirP(pathLib.dirname(output));
const repo = process.env["GITHUB_REPOSITORY"];
const repoRef = process.env["GITHUB_REF"];
const projectPath = process.env["GITHUB_WORKSPACE"];
if (!projectName) {
projectName = pathLib.basename(repo);
}
if (!projectVersion) {
projectVersion = pathLib.basename(repoRef);
}
core.debug(projectPath, projectId, projectName);
cdxgen.createBom(true, projectPath, {}, (err, bomData) => {
if (err) {
core.setFailed(err.message);
}
core.debug(
`About to submit bom data for ${projectName}, ${projectVersion}`
);
if (output) {
fs.writeFile(output, bomData, () => {});
}
if (serverUrl) {
cdxgen.submitBom(
{
output,
projectId,
projectName,
projectVersion,
serverUrl,
apiKey
},
bomData,
(err, res, body) => {
if (err) {
core.setFailed(err.message);
} else if (body) {
core.setOutput("token", body.token);
}
}
);
}
});
}
run();