From 1c365ae376cf1d7a374690d6f750c1fd47b3996c Mon Sep 17 00:00:00 2001 From: Joshua Booth Date: Thu, 24 Aug 2023 09:42:53 -0700 Subject: [PATCH] add config option for timeout --- README.md | 1 + action.yml | 9 +++++++-- dist/index.js | 11 ++++++++--- src/config.js | 5 +++++ src/gh.js | 6 +++--- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e3b4e890..0edea0d8 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,7 @@ Now you're ready to go! | `iam-role-name` | Optional. Used only with the `start` mode. | IAM role name to attach to the created EC2 runner.

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.

Setting this requires additional AWS permissions for the role launching the instance (see above). | | `aws-resource-tags` | Optional. Used only with the `start` mode. | Specifies tags to add to the EC2 instance and any attached storage.

This field is a stringified JSON array of tag objects, each containing a `Key` and `Value` field (see example below).

Setting this requires additional AWS permissions for the role launching the instance (see above). | | `runner-home-dir` | Optional. Used only with the `start` mode. | Specifies a directory where pre-installed actions-runner software and scripts are located.

| +|`timeout` | Optional. Used only with the `start` mode. | Specifies timeout in seconds for attempting to launch an instance. Defaults to 300 seconds (5 minutes).

| | `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:
          - name: Start EC2 runner
with:
mode: start
...
pre-runner-script: \|
sudo yum update -y && \
sudo yum install docker git libicu -y
sudo systemctl enable docker


| diff --git a/action.yml b/action.yml index 09fa9591..88d256cc 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ inputs: required: false ec2-instance-type: description: >- - EC2 Instance Type. + EC2 Instance Type. This input is required if you use the 'start' mode. required: false subnet-id: @@ -32,7 +32,7 @@ inputs: required: false security-group-id: description: >- - EC2 Security Group Id. + EC2 Security Group Id. The security group should belong to the same VPC as the specified subnet. The runner doesn't require any inbound traffic. However, outbound traffic should be allowed. This input is required if you use the 'start' mode. @@ -69,6 +69,11 @@ inputs: description: >- Specifies bash commands to run before the runner starts. It's useful for installing dependencies with apt-get, yum, dnf, etc. required: false + timeout: + description: >- + Timeout in seconds for launching an instance. + default: '300' + required: false outputs: label: diff --git a/dist/index.js b/dist/index.js index 409180d4..14ce7745 100644 --- a/dist/index.js +++ b/dist/index.js @@ -62923,6 +62923,7 @@ class Config { iamRoleName: core.getInput('iam-role-name'), runnerHomeDir: core.getInput('runner-home-dir'), preRunnerScript: core.getInput('pre-runner-script'), + timeout: Number(core.getInput('timeout')), }; const tags = JSON.parse(core.getInput('aws-resource-tags')); @@ -62951,6 +62952,10 @@ class Config { throw new Error(`The 'github-token' input is not specified`); } + if (Number.isNaN(this.input.timeout)) { + throw new Error(`Timeout must be a number`); + } + 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`); @@ -63036,7 +63041,7 @@ async function removeRunner() { } async function waitForRunnerRegistered(label) { - const timeoutMinutes = 5; + const timeoutSeconds = config.input.timeout; const retryIntervalSeconds = 10; const quietPeriodSeconds = 30; let waitSeconds = 0; @@ -63049,10 +63054,10 @@ async function waitForRunnerRegistered(label) { const interval = setInterval(async () => { const runner = await getRunner(label); - if (waitSeconds > timeoutMinutes * 60) { + if (waitSeconds > timeoutSeconds) { core.error('GitHub self-hosted runner registration error'); clearInterval(interval); - 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.`); + 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.`); } if (runner && runner.status === 'online') { diff --git a/src/config.js b/src/config.js index 1100f51e..18c37dba 100644 --- a/src/config.js +++ b/src/config.js @@ -15,6 +15,7 @@ class Config { iamRoleName: core.getInput('iam-role-name'), runnerHomeDir: core.getInput('runner-home-dir'), preRunnerScript: core.getInput('pre-runner-script'), + timeout: Number(core.getInput('timeout')), }; const tags = JSON.parse(core.getInput('aws-resource-tags')); @@ -43,6 +44,10 @@ class Config { throw new Error(`The 'github-token' input is not specified`); } + if (Number.isNaN(this.input.timeout)) { + throw new Error(`Timeout must be a number`); + } + 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`); diff --git a/src/gh.js b/src/gh.js index abf9af94..8a5ebd34 100644 --- a/src/gh.js +++ b/src/gh.js @@ -52,7 +52,7 @@ async function removeRunner() { } async function waitForRunnerRegistered(label) { - const timeoutMinutes = 5; + const timeoutSeconds = config.input.timeout; const retryIntervalSeconds = 10; const quietPeriodSeconds = 30; let waitSeconds = 0; @@ -65,10 +65,10 @@ async function waitForRunnerRegistered(label) { const interval = setInterval(async () => { const runner = await getRunner(label); - if (waitSeconds > timeoutMinutes * 60) { + if (waitSeconds > timeoutSeconds) { core.error('GitHub self-hosted runner registration error'); clearInterval(interval); - 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.`); + 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.`); } if (runner && runner.status === 'online') {