-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (63 loc) · 2.28 KB
/
index.js
File metadata and controls
71 lines (63 loc) · 2.28 KB
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
68
69
70
71
const { setupMSVCDevCmd } = require('./lib')
const core = require('@actions/core')
const axios = require("axios")
const fs = require('fs')
async function validateSubscription() {
let repoPrivate;
const eventPath = process.env.GITHUB_EVENT_PATH;
if (eventPath && fs.existsSync(eventPath)) {
const payload = JSON.parse(fs.readFileSync(eventPath, "utf8"));
repoPrivate = payload?.repository?.private;
}
const upstream = "ilammy/msvc-dev-cmd";
const action = process.env.GITHUB_ACTION_REPOSITORY;
const docsUrl =
"https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions";
core.info("");
core.info("\u001b[1;36mStepSecurity Maintained Action\u001b[0m");
core.info(`Secure drop-in replacement for ${upstream}`);
if (repoPrivate === false)
core.info("\u001b[32m\u2713 Free for public repositories\u001b[0m");
core.info(`\u001b[36mLearn more:\u001b[0m ${docsUrl}`);
core.info("");
if (repoPrivate === false) return;
const serverUrl = process.env.GITHUB_SERVER_URL || "https://github.com";
const body = { action: action || "" };
if (serverUrl !== "https://github.com") body.ghes_server = serverUrl;
try {
await axios.post(
`https://agent.api.stepsecurity.io/v1/github/${process.env.GITHUB_REPOSITORY}/actions/maintained-actions-subscription`,
body,
{ timeout: 3000 },
);
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 403) {
core.error(
`\u001b[1;31mThis action requires a StepSecurity subscription for private repositories.\u001b[0m`,
);
core.error(
`\u001b[31mLearn how to enable a subscription: ${docsUrl}\u001b[0m`,
);
process.exit(1);
}
core.info("Timeout or API not reachable. Continuing to next step.");
}
}
function main() {
var arch = core.getInput('arch')
const sdk = core.getInput('sdk')
const toolset = core.getInput('toolset')
const uwp = core.getInput('uwp')
const spectre = core.getInput('spectre')
const vsversion = core.getInput('vsversion')
setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion)
}
(async () => {
try {
await validateSubscription();
main()
}
catch (e) {
core.setFailed('Could not setup Developer Command Prompt: ' + e.message)
}
})()