-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubscription.mjs
More file actions
43 lines (37 loc) · 1.77 KB
/
Copy pathsubscription.mjs
File metadata and controls
43 lines (37 loc) · 1.77 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
import fs from "fs";
import * as core from "@actions/core";
import axios from "axios";
export 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 = 'actions4git/add-commit-push';
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.');
}
}