Skip to content
Merged
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
22 changes: 13 additions & 9 deletions .github/spot-runner-action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ function start() {
}
else if (config.subaction === "start") {
// We need to terminate
yield terminate("stopped");
yield terminate("stopped", false);
}
else {
throw new Error("Unexpected subaction: " + config.subaction);
Expand Down Expand Up @@ -759,7 +759,7 @@ function start() {
}
});
}
function terminate(instanceStatus) {
function terminate(instanceStatus, cleanupRunners = true) {
return __awaiter(this, void 0, void 0, function* () {
try {
core.info("Starting instance cleanup");
Expand All @@ -768,13 +768,17 @@ function terminate(instanceStatus) {
const ghClient = new github_1.GithubClient(config);
const instances = yield ec2Client.getInstancesForTags(instanceStatus);
yield ec2Client.terminateInstances(instances.map((i) => i.InstanceId));
core.info("Clearing previously installed runners");
const result = yield ghClient.removeRunnersWithLabels([config.githubJobId]);
if (result) {
core.info("Finished runner cleanup");
}
else {
throw Error("Failed to cleanup runners. Continuing, but failure expected!");
if (cleanupRunners) {
core.info("Clearing previously installed runners");
const result = yield ghClient.removeRunnersWithLabels([
config.githubJobId,
]);
if (result) {
core.info("Finished runner cleanup");
}
else {
throw Error("Failed to cleanup runners. Continuing, but failure expected!");
}
}
}
catch (error) {
Expand Down
24 changes: 14 additions & 10 deletions .github/spot-runner-action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function start() {
// then we make a fresh instance
} else if (config.subaction === "start") {
// We need to terminate
await terminate("stopped");
await terminate("stopped", false);
} else {
throw new Error("Unexpected subaction: " + config.subaction);
}
Expand Down Expand Up @@ -139,22 +139,26 @@ async function start() {
}
}

async function terminate(instanceStatus?: string) {
async function terminate(instanceStatus?: string, cleanupRunners = true) {
try {
core.info("Starting instance cleanup");
const config = new ActionConfig();
const ec2Client = new Ec2Instance(config);
const ghClient = new GithubClient(config);
const instances = await ec2Client.getInstancesForTags(instanceStatus);
await ec2Client.terminateInstances(instances.map((i) => i.InstanceId!));
core.info("Clearing previously installed runners");
const result = await ghClient.removeRunnersWithLabels([config.githubJobId]);
if (result) {
core.info("Finished runner cleanup");
} else {
throw Error(
"Failed to cleanup runners. Continuing, but failure expected!"
);
if (cleanupRunners) {
core.info("Clearing previously installed runners");
const result = await ghClient.removeRunnersWithLabels([
config.githubJobId,
]);
if (result) {
core.info("Finished runner cleanup");
} else {
throw Error(
"Failed to cleanup runners. Continuing, but failure expected!"
);
}
}
} catch (error) {
core.info(error);
Expand Down