From d978d104391692f50034362f33fa33d596661953 Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Sun, 7 Sep 2025 18:31:37 +0100 Subject: [PATCH 1/2] Allow to specify key name --- action.yml | 4 ++++ dist/index.js | 2 ++ src/aws.js | 1 + src/config.js | 1 + 4 files changed, 8 insertions(+) diff --git a/action.yml b/action.yml index 87e15ebd..6ebcbd86 100644 --- a/action.yml +++ b/action.yml @@ -125,6 +125,10 @@ inputs: description: >- EC2 block device type. required: false + key-name: + description: >- + Key to use for the created EC2 instance + required: false outputs: label: diff --git a/dist/index.js b/dist/index.js index 4d59a0f4..e3dfd9aa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -145083,6 +145083,7 @@ async function createEc2InstanceWithParams(imageId, subnetId, securityGroupId, l IamInstanceProfile: config.input.iamRoleName ? { Name: config.input.iamRoleName } : undefined, TagSpecifications: config.tagSpecifications, InstanceMarketOptions: buildMarketOptions(), + KeyName: config.input.keyName, }; if (config.input.ec2VolumeSize !== '' || config.input.ec2VolumeType !== '') { @@ -145235,6 +145236,7 @@ class Config { ec2VolumeType: core.getInput('ec2-volume-type'), blockDeviceMappings: JSON.parse(core.getInput('block-device-mappings') || '[]'), availabilityZonesConfig: core.getInput('availability-zones-config'), + keyName: core.getInput('key-name'), }; // Get the AWS_REGION environment variable diff --git a/src/aws.js b/src/aws.js index a5e309a3..a5ed0e9e 100644 --- a/src/aws.js +++ b/src/aws.js @@ -75,6 +75,7 @@ async function createEc2InstanceWithParams(imageId, subnetId, securityGroupId, l IamInstanceProfile: config.input.iamRoleName ? { Name: config.input.iamRoleName } : undefined, TagSpecifications: config.tagSpecifications, InstanceMarketOptions: buildMarketOptions(), + KeyName: config.input.keyName, }; if (config.input.ec2VolumeSize !== '' || config.input.ec2VolumeType !== '') { diff --git a/src/config.js b/src/config.js index ab2f24fb..493ef9ae 100644 --- a/src/config.js +++ b/src/config.js @@ -26,6 +26,7 @@ class Config { ec2VolumeType: core.getInput('ec2-volume-type'), blockDeviceMappings: JSON.parse(core.getInput('block-device-mappings') || '[]'), availabilityZonesConfig: core.getInput('availability-zones-config'), + keyName: core.getInput('key-name'), }; // Get the AWS_REGION environment variable From 8034bafdf19451028a886dd3279cfac6b703d52c Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Sun, 7 Sep 2025 21:35:19 +0100 Subject: [PATCH 2/2] Use a heredoc to preserve the pre runner script verbatim --- dist/index.js | 8 ++++++-- src/aws.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index e3dfd9aa..9283abdf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -145021,7 +145021,9 @@ function buildUserDataScript(githubRegistrationToken, label) { '#!/bin/bash', 'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1', `cd "${config.input.runnerHomeDir}"`, - `echo "${config.input.preRunnerScript}" > pre-runner-script.sh`, + `cat <<'EOF' > pre-runner-script.sh`, + config.input.preRunnerScript, + `EOF`, 'source pre-runner-script.sh', 'export RUNNER_ALLOW_RUNASROOT=1', `./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`, @@ -145031,7 +145033,9 @@ function buildUserDataScript(githubRegistrationToken, label) { '#!/bin/bash', 'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1', 'mkdir actions-runner && cd actions-runner', - `echo "${config.input.preRunnerScript}" > pre-runner-script.sh`, + `cat <<'EOF' > pre-runner-script.sh`, + config.input.preRunnerScript, + `EOF`, 'source pre-runner-script.sh', 'case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}', 'curl -O -L https://github.com/actions/runner/releases/download/v2.313.0/actions-runner-linux-${RUNNER_ARCH}-2.313.0.tar.gz', diff --git a/src/aws.js b/src/aws.js index a5ed0e9e..fb23db35 100644 --- a/src/aws.js +++ b/src/aws.js @@ -13,7 +13,9 @@ function buildUserDataScript(githubRegistrationToken, label) { '#!/bin/bash', 'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1', `cd "${config.input.runnerHomeDir}"`, - `echo "${config.input.preRunnerScript}" > pre-runner-script.sh`, + `cat <<'EOF' > pre-runner-script.sh`, + config.input.preRunnerScript, + `EOF`, 'source pre-runner-script.sh', 'export RUNNER_ALLOW_RUNASROOT=1', `./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`, @@ -23,7 +25,9 @@ function buildUserDataScript(githubRegistrationToken, label) { '#!/bin/bash', 'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1', 'mkdir actions-runner && cd actions-runner', - `echo "${config.input.preRunnerScript}" > pre-runner-script.sh`, + `cat <<'EOF' > pre-runner-script.sh`, + config.input.preRunnerScript, + `EOF`, 'source pre-runner-script.sh', 'case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}', 'curl -O -L https://github.com/actions/runner/releases/download/v2.313.0/actions-runner-linux-${RUNNER_ARCH}-2.313.0.tar.gz',