-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (36 loc) · 1.33 KB
/
index.js
File metadata and controls
41 lines (36 loc) · 1.33 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
const path = require('path');
const core = require('@actions/core');
const aws = require('aws-sdk');
const fs = require('fs');
const getJobDefinition = (jobDefinitionFile) => {
const jobDefPath = path.isAbsolute(jobDefinitionFile) ?
jobDefinitionFile :
path.join(process.env.GITHUB_WORKSPACE, jobDefinitionFile);
if (!fs.existsSync(jobDefPath)) {
throw new Error(`Job definition file does not exist: ${jobDefinitionFile}`);
}
return require(jobDefPath);
}
async function run() {
try {
const batch = new aws.Batch();
const jobDefinitionFile = core.getInput('job-definition', { required: true });
const params = getJobDefinition(jobDefinitionFile);
try {
const registerResponse = await batch.registerJobDefinition(params).promise();
core.setOutput('job-definition-arn', registerResponse.jobDefinitionArn);
core.setOutput('job-definition-name', registerResponse.jobDefinitionName);
core.setOutput('revision', registerResponse.revision);
} catch (error) {
throw new Error(`Failed to register job definition with Batch: ${error.message}`);
}
}
catch (error) {
core.setFailed(error.message);
}
}
module.exports = run;
/* istanbul ignore next */
if (require.main === module) {
run();
}