-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (35 loc) · 1.02 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
'use strict';
const core = require('@actions/core');
const parseEnvironmentName = require('./src/parseEnvironmentName');
async function getEnvironment(githubRef, map) {
const env = parseEnvironmentName(githubRef, map);
if (!env) {
throw new Error('Could not parse environment name');
}
return env;
}
async function getMappings(mappings) {
let result = {};
if (mappings) {
result = JSON.parse(mappings);
}
return result;
}
async function run() {
const githubRef = core.getInput('github-ref', { required: true });
const map = core.getInput('map');
try {
const mappings = await getMappings(map);
const environment = await getEnvironment(githubRef, mappings);
core.info(`Setup environment name: ${environment} by mappings: ${mappings}`);
core.setOutput('environment', environment);
} catch (e) {
core.setFailed(
`Cannot setup env name by ref context: ${githubRef} and map: ${map}, message: ${e.message}`
);
}
}
module.exports = run;
if (require.main === module) {
run();
}