Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert multiple runner groups #1

Merged
merged 3 commits into from
Sep 1, 2023
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
25 changes: 0 additions & 25 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"dependencies": {
"@octokit/auth-app": "^4.0.9",
"@octokit/plugin-retry": "^4.1.3",
"@octokit/plugin-throttling": "^6.0.0",
"@octokit/rest": "^19.0.7",
"webhook-authorizer": "github:nv-gha-runners/webhook-authorizer#9c0ca21ff4517d712e1ab3e25f7ff807d0f519da"
},
Expand Down
32 changes: 9 additions & 23 deletions src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import { Octokit } from "@octokit/rest";
import { createAppAuth } from "@octokit/auth-app";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";

const makeLogger = (obj: any) => (msg: string) => {
console.log(
Expand All @@ -19,22 +18,14 @@ const makeOctokit = (payload: any) => {
throw new Error("No private key found in environment");
}

const MyOctokit = Octokit.plugin(retry, throttling);
const MyOctokit = Octokit.plugin(retry);
return new MyOctokit({
authStrategy: createAppAuth,
auth: {
appId: payload.installation.app_id,
privateKey: Buffer.from(privateKey, "base64").toString(),
installationId,
},
throttle: {
onRateLimit: (retryAfter, options, octokit, retryCount) => {
return true;
},
onSecondaryRateLimit: (retryAfter, options, octokit) => {
return true;
},
},
log: console,
});
};
Expand All @@ -46,8 +37,7 @@ export const handler = async (
const ghEvent = event.headers["X-GitHub-Event"] as string;
const lambdaEvent = { "@gh_event": ghEvent, ...payload };
const logger = makeLogger(lambdaEvent);
// TODO: inform necessary organizations once `rapids-runners` group is removed
const runnerGroups = ["rapids-runners", "nvidia-runners"];
const runnerGroupName = "rapids-runners";
logger("start");

if (ghEvent === "installation" && payload.action === "created") {
Expand Down Expand Up @@ -76,19 +66,15 @@ export const handler = async (
const octokit = makeOctokit(payload);
logger("creating runner group");

await Promise.all(
runnerGroups.map((runnerGroupName) =>
octokit.request("POST /orgs/{org}/actions/runner-groups", {
org: payload.installation.account.login,
name: runnerGroupName,
visibility: "selected",
allows_public_repositories: true,
})
)
);
await octokit.request("POST /orgs/{org}/actions/runner-groups", {
org: payload.installation.account.login,
name: runnerGroupName,
visibility: "selected",
allows_public_repositories: true,
});

return {
body: `New installation detected. Runner groups created.`,
body: `New installation detected. '${runnerGroupName}' group created.`,
statusCode: 200,
};
}
Expand Down
11 changes: 2 additions & 9 deletions tests/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,15 @@ describe("default", () => {
})
);

expect(mockRequest).toHaveBeenCalledTimes(2);
expect(mockRequest).toHaveBeenCalledTimes(1);
expect(mockRequest.mock.calls[0][1]).toStrictEqual({
org: "rapidsai",
name: "rapids-runners",
visibility: "selected",
allows_public_repositories: true,
});

expect(mockRequest.mock.calls[1][1]).toStrictEqual({
org: "rapidsai",
name: "nvidia-runners",
visibility: "selected",
allows_public_repositories: true,
});
expect(result).toStrictEqual({
body: "New installation detected. Runner groups created.",
body: "New installation detected. 'rapids-runners' group created.",
statusCode: 200,
});
});
Expand Down