forked from machulav/ec2-github-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
69 lines (60 loc) · 2.22 KB
/
config.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const core = require('@actions/core');
const github = require('@actions/github');
class Config {
constructor() {
this.input = {
mode: core.getInput('mode'),
githubToken: core.getInput('github-token'),
ec2ImageId: core.getInput('ec2-image-id'),
ec2InstanceType: core.getInput('ec2-instance-type'),
subnetId: core.getInput('subnet-id'),
securityGroupId: core.getInput('security-group-id'),
label: core.getInput('label'),
ec2InstanceId: core.getInput('ec2-instance-id'),
iamRoleName: core.getInput('iam-role-name'),
runnerHomeDir: core.getInput('runner-home-dir'),
preRunnerScript: core.getInput('pre-runner-script'),
};
const tags = JSON.parse(core.getInput('aws-resource-tags'));
this.tagSpecifications = null;
if (tags.length > 0) {
this.tagSpecifications = [{ResourceType: 'instance', Tags: tags}, {ResourceType: 'volume', Tags: tags}];
}
// the values of github.context.repo.owner and github.context.repo.repo are taken from
// the environment variable GITHUB_REPOSITORY specified in "owner/repo" format and
// provided by the GitHub Action on the runtime
this.githubContext = {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
};
//
// validate input
//
if (!this.input.mode) {
throw new Error(`The 'mode' input is not specified`);
}
if (!this.input.githubToken) {
throw new Error(`The 'github-token' input is not specified`);
}
if (this.input.mode === 'start') {
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) {
throw new Error(`Not all the required inputs are provided for the 'start' mode`);
}
} else if (this.input.mode === 'stop') {
if (!this.input.label || !this.input.ec2InstanceId) {
throw new Error(`Not all the required inputs are provided for the 'stop' mode`);
}
} else {
throw new Error('Wrong mode. Allowed values: start, stop.');
}
}
generateUniqueLabel() {
return Math.random().toString(36).substr(2, 5);
}
}
try {
module.exports = new Config();
} catch (error) {
core.error(error);
core.setFailed(error.message);
}