Skip to content

Commit

Permalink
Update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Jun 5, 2024
1 parent d833296 commit a62ccaf
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159730,16 +159730,18 @@ function buildUserDataScript(githubRegistrationToken, label) {
}
}

async function startEc2Instance(label, githubRegistrationToken) {
async function startEc2Instances(label, githubRegistrationToken) {
const client = new EC2Client();

const userData = buildUserDataScript(githubRegistrationToken, label);

const numberOfInstances = config.input.numberOfInstances || 1;

const params = {
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
MinCount: numberOfInstances,
MaxCount: numberOfInstances,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
SubnetId: config.input.subnetId,
SecurityGroupIds: [config.input.securityGroupId],
Expand All @@ -159751,54 +159753,54 @@ async function startEc2Instance(label, githubRegistrationToken) {

try {
const result = await client.send(command);
const ec2InstanceId = result.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} is started`);
return ec2InstanceId;
const ec2InstanceIds = result.Instances.map(instance => instance.InstanceId);
core.info(`AWS EC2 instance ${ec2InstanceIds} is started`);
return ec2InstanceIds;
} catch (error) {
core.error('AWS EC2 instance starting error');
throw error;
}
}

async function terminateEc2Instance() {
async function terminateEc2Instances() {
const client = new EC2Client();

const params = {
InstanceIds: [config.input.ec2InstanceId],
InstanceIds: config.input.ec2InstanceIds,
};

const command = new TerminateInstancesCommand(params);

try {
await client.send(command);
core.info(`AWS EC2 instance ${config.input.ec2InstanceId} is terminated`);
core.info(`AWS EC2 instance ${config.input.ec2InstanceIds} is terminated`);

} catch (error) {
core.error(`AWS EC2 instance ${config.input.ec2InstanceId} termination error`);
core.error(`AWS EC2 instance ${config.input.ec2InstanceIds} termination error`);
throw error;
}
}

async function waitForInstanceRunning(ec2InstanceId) {
async function waitForInstancesRunning(ec2InstanceIds) {
const client = new EC2Client();

const params = {
InstanceIds: [ec2InstanceId],
InstanceIds: ec2InstanceIds,
};

try {
await waitUntilInstanceRunning({client, maxWaitTime: 30, minDelay: 3}, params);
core.info(`AWS EC2 instance ${ec2InstanceId} is up and running`);
core.info(`AWS EC2 instance ${ec2InstanceIds} is up and running`);
} catch (error) {
core.error(`AWS EC2 instance ${ec2InstanceId} initialization error`);
core.error(`AWS EC2 instance ${ec2InstanceIds} initialization error`);
throw error;
}
}

module.exports = {
startEc2Instance,
terminateEc2Instance,
waitForInstanceRunning,
startEc2Instances,
terminateEc2Instances,
waitForInstancesRunning,
};


Expand All @@ -159820,7 +159822,8 @@ class Config {
subnetId: core.getInput('subnet-id'),
securityGroupId: core.getInput('security-group-id'),
label: core.getInput('label'),
ec2InstanceId: core.getInput('ec2-instance-id'),
numberOfInstances: core.getInput('number-of-instances'),
ec2InstanceIds: core.getInput('ec2-instance-ids'),
ec2Os: core.getInput('ec2-os'),
iamRoleName: core.getInput('iam-role-name'),
runnerHomeDir: core.getInput('runner-home-dir'),
Expand Down Expand Up @@ -159862,7 +159865,7 @@ class Config {
throw new Error(`Wrong ec2-os. Allowed values: windows or linux.`);
}
} else if (this.input.mode === 'stop') {
if (!this.input.label || !this.input.ec2InstanceId) {
if (!this.input.label || !this.input.ec2InstanceIds) {
throw new Error(`Not all the required inputs are provided for the 'stop' mode`);
}
} else {
Expand Down Expand Up @@ -159989,22 +159992,22 @@ const gh = __webpack_require__(56989);
const config = __webpack_require__(34570);
const core = __webpack_require__(42186);

function setOutput(label, ec2InstanceId) {
function setOutput(label, ec2InstanceIds) {
core.setOutput('label', label);
core.setOutput('ec2-instance-id', ec2InstanceId);
core.setOutput('ec2-instance-ids', ec2InstanceIds);
}

async function start() {
const label = config.generateUniqueLabel();
const githubRegistrationToken = await gh.getRegistrationToken();
const ec2InstanceId = await aws.startEc2Instance(label, githubRegistrationToken);
setOutput(label, ec2InstanceId);
await aws.waitForInstanceRunning(ec2InstanceId);
const ec2InstanceIds = await aws.startEc2Instances(label, githubRegistrationToken);
setOutput(label, ec2InstanceIds);
await aws.waitForInstancesRunning(ec2InstanceIds);
await gh.waitForRunnerRegistered(label);
}

async function stop() {
await aws.terminateEc2Instance();
await aws.terminateEc2Instances();
await gh.removeRunner();
}

Expand Down

0 comments on commit a62ccaf

Please sign in to comment.