Skip to content

Add config input option for timeout #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <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). |
| `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). |
| `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> |
|`timeout` | Optional. Used only with the `start` mode. | Specifies timeout in seconds for attempting to launch an instance. Defaults to 300 seconds (5 minutes).<br><br> |
| `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>
<br><br> |

Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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;
Expand All @@ -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') {
Expand Down
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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`);
Expand Down
6 changes: 3 additions & 3 deletions src/gh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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') {
Expand Down