forked from machulav/ec2-github-runner
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.js
More file actions
82 lines (72 loc) · 2.81 KB
/
config.js
File metadata and controls
82 lines (72 loc) · 2.81 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
const core = require('@actions/core');
const github = require('@actions/github');
class Config {
constructor() {
this.input = {
ec2ImageId: core.getInput('ec2-image-id'),
ec2InstanceId: core.getInput('ec2-instance-id'),
ec2InstanceType: core.getInput('ec2-instance-type'),
githubToken: core.getInput('github-token'),
iamRoleName: core.getInput('iam-role-name'),
label: core.getInput('label'),
marketType: core.getInput('market-type'),
mode: core.getInput('mode'),
preRunnerScript: core.getInput('pre-runner-script'),
runnerHomeDir: core.getInput('runner-home-dir'),
securityGroupId: core.getInput('security-group-id'),
startupQuietPeriodSeconds: core.getInput('startup-quiet-period-seconds'),
startupRetryIntervalSeconds: core.getInput('startup-retry-interval-seconds'),
startupTimeoutMinutes: core.getInput('startup-timeout-minutes'),
subnetId: core.getInput('subnet-id'),
runAsService: core.getInput('run-runner-as-service') === 'true',
runAsUser: core.getInput('run-runner-as-user')
};
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`);
}
if (this.marketType?.length > 0 && this.input.marketType !== 'spot') {
throw new Error('Invalid `market-type` input. Allowed values: spot.');
}
} 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);
}