Skip to content

Commit

Permalink
Merge pull request #13 from LorenzoDrudi/feature/refactor
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
drudilorenzo authored Sep 9, 2022
2 parents 65c8e79 + 1701142 commit 1e5418c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
JavaScript Github Action to clean up AWS running instances (in a specified AWS region) without a Github Runner linked to them. \
To identify the instances are used two [tags](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html):

1. Key: `Name`, Value: `<REPO_NAME> Github Runner'` (insert the name of your repo).
2. Key: `Runner`, Value: `<Name of the runner linked to the instance` (it's the value used to understand if its linked runner is online, it must be unique!).
1. Key: `Name`, Value: `<REPO_NAME> Github Runner` (insert the name of your repo).
2. Key: `Runner`, Value: `<Name of the runner linked to the instance>` (it's the value used to understand if its linked runner is online, it must be unique!).

It works perfectly with the runners deployed using [ephemeral-github-runner](https://github.com/pavlovic-ivan/ephemeral-github-runner) (see also the related [github action](https://github.com/LorenzoDrudi/ephemeral-github-runner-action)).

Expand Down
28 changes: 14 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ async function run() {
try {
const REPO_NAME = core.getInput('repo-name');
const REPO_OWNER = core.getInput('repo-owner');
const NAME_TAG = `${REPO_NAME} Github Runner`;
const ROGUE_INSTANCE = 2;
const PARAMS = { InstanceIds: []};
const PARAMS = { InstanceIds: [] };
// Get all the infos about the instances in the specified aws region.
const DATA = await ec2Client.send(new DescribeInstancesCommand({}));
// Get all the runners linked to the repo
const RUNNERS_NAME = await getRepoRunningRunnersName(REPO_NAME, REPO_OWNER);

// Iterate over the instances.
for (const reservation of DATA.Reservations) {
for (const instance of reservation.Instances) {
if (instance.State.Name === 'running') {
const NAME_TAG = `${REPO_NAME} Github Runner`;
const CHECK = instance.Tags
.filter(tag => (tag.Key === 'Name' && tag.Value === NAME_TAG)
|| (tag.Key === 'Runner' && !RUNNERS_NAME.includes(tag.Value)))
.length;
if (CHECK === ROGUE_INSTANCE) {
const ID = instance.InstanceId;
PARAMS.InstanceIds.push(ID);
}
}
const RUNNING_INSTANCES = DATA.Reservations
.flatMap(reservation => reservation.Instances)
.filter(instance => instance.State.Name === 'running');
for (const instance of RUNNING_INSTANCES) {
const CHECK = instance.Tags
.filter(tag => (tag.Key === 'Name' && tag.Value === NAME_TAG)
|| (tag.Key === 'Runner' && !RUNNERS_NAME.includes(tag.Value)))
.length;
if (CHECK === ROGUE_INSTANCE) {
const ID = instance.InstanceId;
PARAMS.InstanceIds.push(ID);
}
}

Expand All @@ -43,3 +42,4 @@ async function run() {
}

run();

0 comments on commit 1e5418c

Please sign in to comment.