Skip to content

Commit

Permalink
Dropped ec2- prefix on inputs and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
erhhung committed Aug 15, 2024
1 parent 23b282e commit d92e65e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 74 deletions.
9 changes: 6 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
INPUT_MODE=
INPUT_GITHUB-TOKEN=
INPUT_EC2-IMAGE-ID=
INPUT_EC2-INSTANCE-TYPE=
INPUT_IMAGE-ID=
INPUT_INSTANCE-TYPE=
INPUT_SUBNET-ID=
INPUT_SECURITY-GROUP-ID=
INPUT_LABELS=
INPUT_EC2-INSTANCE-ID=
INPUT_INSTANCE-ID=
INPUT_IAM-ROLE-NAME=
INPUT_SPOT-INSTANCE=
INPUT_ROOT-VOLUME-DEVICE=
INPUT_ROOT-VOLUME-TYPE=
INPUT_ROOT-VOLUME-SIZE=
INPUT_AWS-RESOURCE-TAGS=
INPUT_RUNNER-HOME-DIR=
INPUT_PRE-RUNNER-SCRIPT=
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ jobs:
mode: start
github-token: ${{ secrets.RUNNER_GITHUB_REPOS_PAT }}
labels: Linux,ARM64,AL2023
ec2-image-id: ${{ vars.RUNNER_ARM64_AMI_ID }}
# runner could lose connection to GitHub Actions
# if using instance type smaller than t4g.xlarge
ec2-instance-type: ${{ vars.RUNNER_ARM64_INSTANCE_TYPE }}
image-id: ${{ vars.RUNNER_ARM64_AMI_ID }}
instance-type: ${{ vars.RUNNER_ARM64_INSTANCE_TYPE }}
spot-instance: 'true'
root-volume-size: '${{ vars.RUNNER_ROOT_VOLUME_SIZE }}'
subnet-id: ${{ vars.RUNNER_SUBNET_ID }}
Expand All @@ -60,10 +58,10 @@ jobs:
labels-json=["${csv//,/\",\"}"]
EOF
outputs:
labels-csv: '${{ steps.output.outputs.labels-csv }}'
runner-name: ${{ steps.runner.outputs.runner-name }}
instance-id: ${{ steps.runner.outputs.instance-id }}
labels-json: '${{ steps.output.outputs.labels-json }}'
instance-id: ${{ steps.runner.outputs.ec2-instance-id }}
runner-name: ${{ steps.start-runner.outputs.runner-name }}
labels-csv: '${{ steps.output.outputs.labels-csv }}'

manual-approval:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -111,4 +109,4 @@ jobs:
mode: stop
github-token: ${{ secrets.RUNNER_GITHUB_REPOS_PAT }}
labels: ${{ needs.launch-runner.outputs.labels-csv }}
ec2-instance-id: ${{ needs.launch-runner.outputs.instance-id }}
instance-id: ${{ needs.launch-runner.outputs.instance-id }}
48 changes: 25 additions & 23 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ inputs:
description: >-
GitHub Personal Access Token with the 'repo' scope assigned.
required: true
ec2-image-id:
image-id:
description: >-
EC2 Image ID (AMI). The new runner will be launched from this image.
This action is compatible with Amazon Linux 2023 images.
This input is required if you use the 'start' mode.
required: false
ec2-instance-type:
instance-type:
description: >-
EC2 Instance Type.
This input is required if you use the 'start' mode.
Expand All @@ -46,7 +46,7 @@ inputs:
Use these labels to remove the runner from GitHub when the runner is no longer needed.
This input is required if you use the 'stop' mode.
required: false
ec2-instance-id:
instance-id:
description: >-
EC2 Instance ID of the created runner.
This ID is provided by the output of the action in 'start' mode.
Expand Down Expand Up @@ -106,7 +106,7 @@ outputs:
These labels are used in two cases:
- to use as the 'runs-on' property value of subsequent jobs;
- to remove the runner from GitHub when it is no longer needed.
ec2-instance-id:
instance-id:
description: >-
EC2 Instance ID of the created runner.
This ID is used to terminate the EC2 instance when the runner is no longer needed.
Expand Down
36 changes: 18 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143746,8 +143746,8 @@ async function startEc2Instance(labels, githubRegistrationToken) {
const input = {
MinCount: 1,
MaxCount: 1,
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
ImageId: config.input.imageId,
InstanceType: config.input.instanceType,
InstanceMarketOptions: config.input.spotInstance ? { MarketType: 'spot' } : undefined,
EbsOptimized: true,
BlockDeviceMappings: [
Expand All @@ -143772,48 +143772,48 @@ async function startEc2Instance(labels, githubRegistrationToken) {
try {
const command = new RunInstancesCommand(input);
const response = await client.send(command);
const ec2InstanceId = response.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} has started`);
return ec2InstanceId;
const instanceId = response.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${instanceId} has started`);
return instanceId;
} catch (error) {
core.error('AWS EC2 instance launch error');
throw error;
}
}

async function waitForInstanceRunning(ec2InstanceId) {
async function waitForInstanceRunning(instanceId) {
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ec2/Variable/waitUntilInstanceRunning
const params = {
client: client,
maxWaitTime: 60 * 5,
};
const input = {
InstanceIds: [ec2InstanceId],
InstanceIds: [instanceId],
};

try {
await waitUntilInstanceRunning(params, input);
core.info(`AWS EC2 instance ${ec2InstanceId} is up and running`);
core.info(`AWS EC2 instance ${instanceId} is up and running`);
return;
} catch (error) {
core.error(`AWS EC2 instance ${ec2InstanceId} initialization error`);
core.error(`AWS EC2 instance ${instanceId} initialization error`);
throw error;
}
}

async function terminateEc2Instance() {
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/TerminateInstancesCommand
const input = {
InstanceIds: [config.input.ec2InstanceId],
InstanceIds: [config.input.instanceId],
};

try {
const command = new TerminateInstancesCommand(input);
await client.send(command);
core.info(`AWS EC2 instance ${config.input.ec2InstanceId} has terminated`);
core.info(`AWS EC2 instance ${config.input.instanceId} has terminated`);
return;
} catch (error) {
core.error(`AWS EC2 instance ${config.input.ec2InstanceId} termination error`);
core.error(`AWS EC2 instance ${config.input.instanceId} termination error`);
throw error;
}
}
Expand All @@ -143838,12 +143838,12 @@ class Config {
this.input = {
mode: core.getInput('mode'),
githubToken: core.getInput('github-token'),
ec2ImageId: core.getInput('ec2-image-id'),
ec2InstanceType: core.getInput('ec2-instance-type'),
imageId: core.getInput('image-id'),
instanceType: core.getInput('instance-type'),
subnetId: core.getInput('subnet-id'),
securityGroupId: core.getInput('security-group-id'),
labels: core.getInput('labels'),
ec2InstanceId: core.getInput('ec2-instance-id'),
instanceId: core.getInput('instance-id'),
iamRoleName: core.getInput('iam-role-name'),
spotInstance: core.getBooleanInput('spot-instance'),
rootVolumeDevice: core.getInput('root-volume-device'),
Expand Down Expand Up @@ -143886,11 +143886,11 @@ class Config {
}

if (this.input.mode === 'start') {
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) {
if (!this.input.imageId || !this.input.instanceType || !this.input.subnetId || !this.input.securityGroupId) {
throw new Error(`Not all the required inputs are provided for the 'start' mode`);
}
} else if (this.input.mode === 'stop') {
if (!this.input.labels || !this.input.ec2InstanceId) {
if (!this.input.labels || !this.input.instanceId) {
throw new Error(`Not all the required inputs are provided for the 'stop' mode`);
}
} else {
Expand Down Expand Up @@ -145979,7 +145979,7 @@ const gh = __nccwpck_require__(6989);

function setOutput(labels, instanceId, runnerName) {
core.setOutput('labels', labels);
core.setOutput('ec2-instance-id', instanceId);
core.setOutput('instance-id', instanceId);
core.setOutput('runner-name', runnerName);
}

Expand Down
24 changes: 12 additions & 12 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async function startEc2Instance(labels, githubRegistrationToken) {
const input = {
MinCount: 1,
MaxCount: 1,
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
ImageId: config.input.imageId,
InstanceType: config.input.instanceType,
InstanceMarketOptions: config.input.spotInstance ? { MarketType: 'spot' } : undefined,
EbsOptimized: true,
BlockDeviceMappings: [
Expand All @@ -77,48 +77,48 @@ async function startEc2Instance(labels, githubRegistrationToken) {
try {
const command = new RunInstancesCommand(input);
const response = await client.send(command);
const ec2InstanceId = response.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} has started`);
return ec2InstanceId;
const instanceId = response.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${instanceId} has started`);
return instanceId;
} catch (error) {
core.error('AWS EC2 instance launch error');
throw error;
}
}

async function waitForInstanceRunning(ec2InstanceId) {
async function waitForInstanceRunning(instanceId) {
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ec2/Variable/waitUntilInstanceRunning
const params = {
client: client,
maxWaitTime: 60 * 5,
};
const input = {
InstanceIds: [ec2InstanceId],
InstanceIds: [instanceId],
};

try {
await waitUntilInstanceRunning(params, input);
core.info(`AWS EC2 instance ${ec2InstanceId} is up and running`);
core.info(`AWS EC2 instance ${instanceId} is up and running`);
return;
} catch (error) {
core.error(`AWS EC2 instance ${ec2InstanceId} initialization error`);
core.error(`AWS EC2 instance ${instanceId} initialization error`);
throw error;
}
}

async function terminateEc2Instance() {
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/TerminateInstancesCommand
const input = {
InstanceIds: [config.input.ec2InstanceId],
InstanceIds: [config.input.instanceId],
};

try {
const command = new TerminateInstancesCommand(input);
await client.send(command);
core.info(`AWS EC2 instance ${config.input.ec2InstanceId} has terminated`);
core.info(`AWS EC2 instance ${config.input.instanceId} has terminated`);
return;
} catch (error) {
core.error(`AWS EC2 instance ${config.input.ec2InstanceId} termination error`);
core.error(`AWS EC2 instance ${config.input.instanceId} termination error`);
throw error;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class Config {
this.input = {
mode: core.getInput('mode'),
githubToken: core.getInput('github-token'),
ec2ImageId: core.getInput('ec2-image-id'),
ec2InstanceType: core.getInput('ec2-instance-type'),
imageId: core.getInput('image-id'),
instanceType: core.getInput('instance-type'),
subnetId: core.getInput('subnet-id'),
securityGroupId: core.getInput('security-group-id'),
labels: core.getInput('labels'),
ec2InstanceId: core.getInput('ec2-instance-id'),
instanceId: core.getInput('instance-id'),
iamRoleName: core.getInput('iam-role-name'),
spotInstance: core.getBooleanInput('spot-instance'),
rootVolumeDevice: core.getInput('root-volume-device'),
Expand Down Expand Up @@ -54,11 +54,11 @@ class Config {
}

if (this.input.mode === 'start') {
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) {
if (!this.input.imageId || !this.input.instanceType || !this.input.subnetId || !this.input.securityGroupId) {
throw new Error(`Not all the required inputs are provided for the 'start' mode`);
}
} else if (this.input.mode === 'stop') {
if (!this.input.labels || !this.input.ec2InstanceId) {
if (!this.input.labels || !this.input.instanceId) {
throw new Error(`Not all the required inputs are provided for the 'stop' mode`);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const gh = require('./gh');

function setOutput(labels, instanceId, runnerName) {
core.setOutput('labels', labels);
core.setOutput('ec2-instance-id', instanceId);
core.setOutput('instance-id', instanceId);
core.setOutput('runner-name', runnerName);
}

Expand Down

0 comments on commit d92e65e

Please sign in to comment.