Skip to content

Commit 729c020

Browse files
committed
add config option for timeout
1 parent 2c4d1dc commit 729c020

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,21 @@ Now you're ready to go!
192192

193193
### Inputs
194194

195-
|               Name               | Required | Description |
196-
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
197-
| `mode` | Always required. | Specify here which mode you want to use: <br> - `start` - to start a new runner; <br> - `stop` - to stop the previously created runner. |
198-
| `github-token` | Always required. | GitHub Personal Access Token with the `repo` scope assigned. |
199-
| `ec2-image-id` | Required if you use the `start` mode. | EC2 Image Id (AMI). <br><br> The new runner will be launched from this image. <br><br> The action is compatible with Amazon Linux 2 images. |
200-
| `ec2-instance-type` | Required if you use the `start` mode. | EC2 Instance Type. |
201-
| `subnet-id` | Required if you use the `start` mode. | VPC Subnet Id. <br><br> The subnet should belong to the same VPC as the specified security group. |
202-
| `security-group-id` | Required if you use the `start` mode. | EC2 Security Group Id. <br><br> The security group should belong to the same VPC as the specified subnet. <br><br> Only the outbound traffic for port 443 should be allowed. No inbound traffic is required. |
203-
| `label` | Required if you use the `stop` mode. | Name of the unique label assigned to the runner. <br><br> The label is provided by the output of the action in the `start` mode. <br><br> The label is used to remove the runner from GitHub when the runner is not needed anymore. |
204-
| `ec2-instance-id` | Required if you use the `stop` mode. | EC2 Instance Id of the created runner. <br><br> The id is provided by the output of the action in the `start` mode. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
205-
| `iam-role-name` | Optional. Used only with the `start` mode. | IAM role name to attach to the created EC2 runner. <br><br> This allows the runner to have permissions to run additional actions within the AWS account, without having to manage additional GitHub secrets and AWS users. <br><br> Setting this requires additional AWS permissions for the role launching the instance (see above). |
206-
| `aws-resource-tags` | Optional. Used only with the `start` mode. | Specifies tags to add to the EC2 instance and any attached storage. <br><br> This field is a stringified JSON array of tag objects, each containing a `Key` and `Value` field (see example below). <br><br> Setting this requires additional AWS permissions for the role launching the instance (see above). |
207-
| `runner-home-dir` | Optional. Used only with the `start` mode. | Specifies a directory where pre-installed actions-runner software and scripts are located.<br><br> |
208-
| `pre-runner-script` | Optional. Used only with the `start` mode. | Specifies bash commands to run before the runner starts. It's useful for installing dependencies with apt-get, yum, dnf, etc. For example:<pre> - name: Start EC2 runner<br> with:<br> mode: start<br> ...<br> pre-runner-script: \|<br> sudo yum update -y && \ <br> sudo yum install docker git libicu -y<br> sudo systemctl enable docker</pre>
209-
<br><br> |
195+
| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Required | Description |
196+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
197+
| `mode` | Always required. | Specify here which mode you want to use: <br> - `start` - to start a new runner; <br> - `stop` - to stop the previously created runner. |
198+
| `github-token` | Always required. | GitHub Personal Access Token with the `repo` scope assigned. |
199+
| `ec2-image-id` | Required if you use the `start` mode. | EC2 Image Id (AMI). <br><br> The new runner will be launched from this image. <br><br> The action is compatible with Amazon Linux 2 images. |
200+
| `ec2-instance-type` | Required if you use the `start` mode. | EC2 Instance Type. |
201+
| `subnet-id` | Required if you use the `start` mode. | VPC Subnet Id. <br><br> The subnet should belong to the same VPC as the specified security group. |
202+
| `security-group-id` | Required if you use the `start` mode. | EC2 Security Group Id. <br><br> The security group should belong to the same VPC as the specified subnet. <br><br> Only the outbound traffic for port 443 should be allowed. No inbound traffic is required. |
203+
| `label` | Required if you use the `stop` mode. | Name of the unique label assigned to the runner. <br><br> The label is provided by the output of the action in the `start` mode. <br><br> The label is used to remove the runner from GitHub when the runner is not needed anymore. |
204+
| `ec2-instance-id` | Required if you use the `stop` mode. | EC2 Instance Id of the created runner. <br><br> The id is provided by the output of the action in the `start` mode. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
205+
| `iam-role-name` | Optional. Used only with the `start` mode. | IAM role name to attach to the created EC2 runner. <br><br> This allows the runner to have permissions to run additional actions within the AWS account, without having to manage additional GitHub secrets and AWS users. <br><br> Setting this requires additional AWS permissions for the role launching the instance (see above). |
206+
| `aws-resource-tags` | Optional. Used only with the `start` mode. | Specifies tags to add to the EC2 instance and any attached storage. <br><br> This field is a stringified JSON array of tag objects, each containing a `Key` and `Value` field (see example below). <br><br> Setting this requires additional AWS permissions for the role launching the instance (see above). |
207+
| `runner-home-dir` | Optional. Used only with the `start` mode. | Specifies a directory where pre-installed actions-runner software and scripts are located.<br><br> |
208+
| `pre-runner-script` | Optional. Used only with the `start` mode. | Specifies bash commands to run before the runner starts. It's useful for installing dependencies with apt-get, yum, dnf, etc. For example:<pre> - name: Start EC2 runner<br> with:<br> mode: start<br> ...<br> pre-runner-script: \|<br> sudo yum update -y && \ <br> sudo yum install docker git libicu -y<br> sudo systemctl enable docker</pre> |
209+
| <br><br> | `timeout` | Optional. Used only with the `start` mode. | Specifies timeout in seconds to wait while attempting to launch an instance. |
210210

211211
### Environment variables
212212

action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inputs:
2222
required: false
2323
ec2-instance-type:
2424
description: >-
25-
EC2 Instance Type.
25+
EC2 Instance Type.
2626
This input is required if you use the 'start' mode.
2727
required: false
2828
subnet-id:
@@ -32,7 +32,7 @@ inputs:
3232
required: false
3333
security-group-id:
3434
description: >-
35-
EC2 Security Group Id.
35+
EC2 Security Group Id.
3636
The security group should belong to the same VPC as the specified subnet.
3737
The runner doesn't require any inbound traffic. However, outbound traffic should be allowed.
3838
This input is required if you use the 'start' mode.
@@ -69,6 +69,11 @@ inputs:
6969
description: >-
7070
Specifies bash commands to run before the runner starts. It's useful for installing dependencies with apt-get, yum, dnf, etc.
7171
required: false
72+
timeout:
73+
description: >-
74+
Timeout in seconds for launching an instance.
75+
default: '300'
76+
required: false
7277

7378
outputs:
7479
label:

dist/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62923,6 +62923,7 @@ class Config {
6292362923
iamRoleName: core.getInput('iam-role-name'),
6292462924
runnerHomeDir: core.getInput('runner-home-dir'),
6292562925
preRunnerScript: core.getInput('pre-runner-script'),
62926+
timeout: Number(core.getInput('timeout')),
6292662927
};
6292762928

6292862929
const tags = JSON.parse(core.getInput('aws-resource-tags'));
@@ -62951,6 +62952,10 @@ class Config {
6295162952
throw new Error(`The 'github-token' input is not specified`);
6295262953
}
6295362954

62955+
if (Number.isNaN(this.input.timeout)) {
62956+
throw new Error(`Timeout must be a number`);
62957+
}
62958+
6295462959
if (this.input.mode === 'start') {
6295562960
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) {
6295662961
throw new Error(`Not all the required inputs are provided for the 'start' mode`);
@@ -63036,7 +63041,7 @@ async function removeRunner() {
6303663041
}
6303763042

6303863043
async function waitForRunnerRegistered(label) {
63039-
const timeoutMinutes = 5;
63044+
const timeoutSeconds = config.input.timeout;
6304063045
const retryIntervalSeconds = 10;
6304163046
const quietPeriodSeconds = 30;
6304263047
let waitSeconds = 0;
@@ -63049,10 +63054,10 @@ async function waitForRunnerRegistered(label) {
6304963054
const interval = setInterval(async () => {
6305063055
const runner = await getRunner(label);
6305163056

63052-
if (waitSeconds > timeoutMinutes * 60) {
63057+
if (waitSeconds > timeoutSeconds) {
6305363058
core.error('GitHub self-hosted runner registration error');
6305463059
clearInterval(interval);
63055-
reject(`A timeout of ${timeoutMinutes} minutes is exceeded. Your AWS EC2 instance was not able to register itself in GitHub as a new self-hosted runner.`);
63060+
reject(`A timeout of ${timeoutSeconds} seconds is exceeded. Your AWS EC2 instance was not able to register itself in GitHub as a new self-hosted runner.`);
6305663061
}
6305763062

6305863063
if (runner && runner.status === 'online') {

src/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Config {
1515
iamRoleName: core.getInput('iam-role-name'),
1616
runnerHomeDir: core.getInput('runner-home-dir'),
1717
preRunnerScript: core.getInput('pre-runner-script'),
18+
timeout: Number(core.getInput('timeout')),
1819
};
1920

2021
const tags = JSON.parse(core.getInput('aws-resource-tags'));
@@ -43,6 +44,10 @@ class Config {
4344
throw new Error(`The 'github-token' input is not specified`);
4445
}
4546

47+
if (Number.isNaN(this.input.timeout)) {
48+
throw new Error(`Timeout must be a number`);
49+
}
50+
4651
if (this.input.mode === 'start') {
4752
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) {
4853
throw new Error(`Not all the required inputs are provided for the 'start' mode`);

0 commit comments

Comments
 (0)