-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
41 lines (36 loc) · 1.24 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
const core = require('@actions/core');
const fs = require('fs');
const YAML = require('yaml');
const shell = require('shelljs');
const deployAll = ({ functions, yml, zipParams, alias, layer }) => {
let success = true;
for (const [key, value] of Object.entries(functions)) {
if (value === 'true') {
const { code } = shell.exec(`sh ./deploy.sh "${key}" "${yml[key][0].split('*')[0]}" "${zipParams}" "${alias}" "${layer}"`);
if (code) {
console.error(`Deployment of ${key} failed!`);
success = false;
}
}
}
return success;
};
const run = async () => {
try {
const lambdaFunctions = core.getInput('lambda-functions');
const zipParams = core.getInput('zip-params');
const alias = core.getInput('alias-name');
const layer = core.getInput('layer-name');
const functions = JSON.parse(lambdaFunctions);
const file = fs.readFileSync('./.github/filters.yml', 'utf8');
const yml = YAML.parse(file);
const success = deployAll({ functions, yml, zipParams, alias, layer });
if (!success) throw new Error('An error occured. At least one Lambda could not be deployed.');
} catch (error) {
core.setFailed(error.message);
}
};
if (require.main === module) {
run();
}
module.exports = run;