forked from Firenza/secrets-to-env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (31 loc) · 1.65 KB
/
main.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');
function run(){
try {
const secrets = core.getInput('secrets');
const secretFilterRegexString = core.getInput('secret_filter_regex');
const lowerCaseRegexString = core.getInput('env_var_name_lower_case_regex');
const parsedSecrets = JSON.parse(secrets);
for(var attributeName in parsedSecrets){
const secretFilterRegexDefined = secretFilterRegexString !== null && secretFilterRegexString !== undefined && secretFilterRegexString !== ''
if (!secretFilterRegexDefined || secretFilterRegexDefined && attributeName.match(new RegExp(secretFilterRegexString))){
variableName = attributeName;
variableValue = parsedSecrets[attributeName];
const lowerCaseRegexStringDefined = lowerCaseRegexString !== null && lowerCaseRegexString !== undefined && lowerCaseRegexString !== ''
if(lowerCaseRegexStringDefined){
variableName = variableName.replace(new RegExp(lowerCaseRegexString), function(match){
return match.toLowerCase()
})
console.log(`Exporting secret ${attributeName} as environment variable ${variableName}`);
}
else{
console.log(`Exporting secret ${attributeName} as environment variable`);
}
core.exportVariable(variableName, variableValue);
}
}
} catch (error) {
core.setFailed(error.message);
}
}
module.exports = run;
run();