-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (33 loc) · 1.19 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
const core = require('@actions/core')
const axios = require('axios');
const fs = require('fs')
async function validateSubscription() {
const API_URL = `https://agent.api.stepsecurity.io/v1/github/${process.env.GITHUB_REPOSITORY}/actions/subscription`;
try {
await axios.get(API_URL, { timeout: 3000 });
} catch (error) {
if (error.response) {
console.error(
'Subscription is not valid. Reach out to [email protected]'
);
process.exit(1);
} else {
core.info('Timeout or API not reachable. Continuing to next step.');
}
}
}
async function main() {
try {
await validateSubscription();
const source = core.getInput('source')
const find = core.getInput('find')
const replace = core.getInput('replace')
const replaceAllInput = core.getInput('replaceAll')
const replaceAll = replaceAllInput ? replaceAllInput == 'true' : false
const resultValue = replaceAll ? source.replaceAll(find, replace) : source.replace(find, replace)
core.setOutput('value', resultValue)
} catch (error) {
core.setFailed(error.message)
}
}
main()