Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit a74e10b

Browse files
committed
feat: Adding support for new workflow_job event. (#1019)
Added support for new workflow_job event, the check_run event will remain for backwards compatibility
1 parent fab09aa commit a74e10b

File tree

22 files changed

+2113
-2039
lines changed

22 files changed

+2113
-2039
lines changed

Diff for: README.md

+120-90
Large diffs are not rendered by default.

Diff for: examples/default/main.tf

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ resource "random_password" "random" {
77
length = 28
88
}
99

10-
module "runners" {
11-
source = "../../"
1210

13-
aws_region = local.aws_region
14-
vpc_id = module.vpc.vpc_id
15-
subnet_ids = module.vpc.private_subnets
11+
################################################################################
12+
### Hybrid acccount
13+
################################################################################
14+
15+
module "runners" {
16+
source = "../../"
17+
create_service_linked_role_spot = true
18+
aws_region = local.aws_region
19+
vpc_id = module.vpc.vpc_id
20+
subnet_ids = module.vpc.private_subnets
1621

1722
environment = local.environment
1823
tags = {

Diff for: main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module "webhook" {
5959
lambda_zip = var.webhook_lambda_zip
6060
lambda_timeout = var.webhook_lambda_timeout
6161
logging_retention_in_days = var.logging_retention_in_days
62+
runner_extra_labels = var.runner_extra_labels
6263

6364
role_path = var.role_path
6465
role_permissions_boundary = var.role_permissions_boundary

Diff for: modules/runner-binaries-syncer/lambdas/runner-binaries-syncer/yarn.lock

+308-523
Large diffs are not rendered by default.

Diff for: modules/runners/lambdas/runners/src/local-down.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { scaleDown } from './scale-runners/scale-down';
22

3-
43
export function run(): void {
5-
scaleDown();
4+
scaleDown();
65
}
76

87
run();

Diff for: modules/runners/lambdas/runners/src/local.ts

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
1-
import { scaleUp } from './scale-runners/scale-up';
1+
import { scaleUp, ActionRequestMessage } from './scale-runners/scale-up';
22

33
const sqsEvent = {
4-
Records: [
5-
{
6-
messageId: 'e8d74d08-644e-42ca-bf82-a67daa6c4dad',
7-
// eslint-disable-next-line max-len
8-
receiptHandle: 'AQEBCpLYzDEKq4aKSJyFQCkJduSKZef8SJVOperbYyNhXqqnpFG5k74WygVAJ4O0+9nybRyeOFThvITOaS21/jeHiI5fgaM9YKuI0oGYeWCIzPQsluW5CMDmtvqv1aA8sXQ5n2x0L9MJkzgdIHTC3YWBFLQ2AxSveOyIHwW+cHLIFCAcZlOaaf0YtaLfGHGkAC4IfycmaijV8NSlzYgDuxrC9sIsWJ0bSvk5iT4ru/R4+0cjm7qZtGlc04k9xk5Fu6A+wRxMaIyiFRY+Ya19ykcevQldidmEjEWvN6CRToLgclk=',
9-
// eslint-disable-next-line max-len
10-
body: { "id": 19072, "repositoryName": "ErrBud", "repositoryOwner": "ActionsTest", "eventType": "check_run", "installationId": 5 },
11-
attributes: {
12-
ApproximateReceiveCount: '1',
13-
SentTimestamp: '1626450047230',
14-
SequenceNumber: '18863115285800432640',
15-
MessageGroupId: '19072',
16-
SenderId: 'AROA5KW7SQ6TTB3PW6WPH:cicddev-webhook',
17-
MessageDeduplicationId: '0c458eeb87b7f6d2607301268fd3bf33dd898a49ebd888754ff7db510c4bff1e',
18-
ApproximateFirstReceiveTimestamp: '1626450077251'
19-
},
20-
messageAttributes: {},
21-
md5OfBody: '4aef3bd70526e152e86426a0938cbec6',
22-
eventSource: 'aws:sqs',
23-
eventSourceARN: 'arn:aws:sqs:us-west-2:916370655143:cicddev-queued-builds.fifo',
24-
awsRegion: 'us-west-2'
25-
}
26-
]
4+
Records: [
5+
{
6+
messageId: 'e8d74d08-644e-42ca-bf82-a67daa6c4dad',
7+
receiptHandle:
8+
// eslint-disable-next-line max-len
9+
'AQEBCpLYzDEKq4aKSJyFQCkJduSKZef8SJVOperbYyNhXqqnpFG5k74WygVAJ4O0+9nybRyeOFThvITOaS21/jeHiI5fgaM9YKuI0oGYeWCIzPQsluW5CMDmtvqv1aA8sXQ5n2x0L9MJkzgdIHTC3YWBFLQ2AxSveOyIHwW+cHLIFCAcZlOaaf0YtaLfGHGkAC4IfycmaijV8NSlzYgDuxrC9sIsWJ0bSvk5iT4ru/R4+0cjm7qZtGlc04k9xk5Fu6A+wRxMaIyiFRY+Ya19ykcevQldidmEjEWvN6CRToLgclk=',
10+
body: {
11+
id: 19072,
12+
repositoryName: 'ErrBud',
13+
repositoryOwner: 'ActionsTest',
14+
eventType: 'check_run',
15+
installationId: 5,
16+
},
17+
attributes: {
18+
ApproximateReceiveCount: '1',
19+
SentTimestamp: '1626450047230',
20+
SequenceNumber: '18863115285800432640',
21+
MessageGroupId: '19072',
22+
SenderId: 'AROA5KW7SQ6TTB3PW6WPH:cicddev-webhook',
23+
MessageDeduplicationId: '0c458eeb87b7f6d2607301268fd3bf33dd898a49ebd888754ff7db510c4bff1e',
24+
ApproximateFirstReceiveTimestamp: '1626450077251',
25+
},
26+
messageAttributes: {},
27+
md5OfBody: '4aef3bd70526e152e86426a0938cbec6',
28+
eventSource: 'aws:sqs',
29+
eventSourceARN: 'arn:aws:sqs:us-west-2:916370655143:cicddev-queued-builds.fifo',
30+
awsRegion: 'us-west-2',
31+
},
32+
],
2733
};
2834
export function run(): void {
29-
scaleUp(sqsEvent.Records[0].eventSource, sqsEvent.Records[0].body);
35+
scaleUp(sqsEvent.Records[0].eventSource, sqsEvent.Records[0].body as ActionRequestMessage);
3036
}
3137

3238
run();

Diff for: modules/runners/lambdas/runners/src/scale-runners/gh-auth.test.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { createOctoClient, createGithubAuth } from './gh-auth';
22
import nock from 'nock';
33
import { createAppAuth } from '@octokit/auth-app';
4+
45
import { StrategyOptions } from '@octokit/auth-app/dist-types/types';
56
import { getParameterValue } from './ssm';
7+
68
import { RequestInterface } from '@octokit/types';
79
import { mock, MockProxy } from 'jest-mock-extended';
810
import { request } from '@octokit/request';
@@ -23,7 +25,6 @@ const PARAMETER_GITHUB_APP_CLIENT_SECRET_NAME = `/actions-runner/${ENVIRONMENT}/
2325

2426
const mockedGet = mocked(getParameterValue);
2527

26-
2728
beforeEach(() => {
2829
jest.resetModules();
2930
jest.clearAllMocks();
@@ -93,8 +94,7 @@ describe('Test createGithubAuth', () => {
9394

9495
const mockedAuth = jest.fn();
9596
mockedAuth.mockResolvedValue({ token });
96-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
97-
mockedCreatAppAuth.mockImplementation((authOptions: StrategyOptions) => {
97+
mockedCreatAppAuth.mockImplementation(() => {
9898
return mockedAuth;
9999
});
100100

@@ -184,8 +184,7 @@ describe('Test createGithubAuth', () => {
184184
.mockResolvedValueOnce(GITHUB_APP_CLIENT_SECRET);
185185
const mockedAuth = jest.fn();
186186
mockedAuth.mockResolvedValue({ token });
187-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
188-
mockedCreatAppAuth.mockImplementation((authOptions: StrategyOptions) => {
187+
mockedCreatAppAuth.mockImplementation(() => {
189188
return mockedAuth;
190189
});
191190

Diff for: modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ export async function createGithubAuth(
2121
authType: 'app' | 'installation',
2222
ghesApiUrl = '',
2323
): Promise<AppAuthentication> {
24-
2524
let authOptions: StrategyOptions = {
2625
appId: parseInt(await getParameterValue(process.env.PARAMETER_GITHUB_APP_ID_NAME)),
2726
privateKey: Buffer.from(
2827
await getParameterValue(process.env.PARAMETER_GITHUB_APP_KEY_BASE64_NAME),
29-
'base64')
30-
.toString(),
28+
'base64',
29+
).toString(),
3130
clientId: await getParameterValue(process.env.PARAMETER_GITHUB_APP_CLIENT_ID_NAME),
3231
clientSecret: await getParameterValue(process.env.PARAMETER_GITHUB_APP_CLIENT_SECRET_NAME),
3332
};
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
declare namespace NodeJS {
2-
export interface ProcessEnv {
3-
ENVIRONMENT: string
4-
SUBNET_IDS: string
5-
GHES_URL: string
6-
SCALE_DOWN_CONFIG: string
7-
MINIMUM_RUNNING_TIME_IN_MINUTES: string
8-
LAUNCH_TEMPLATE_NAME: string
9-
AWS_REGION: string
10-
PARAMETER_GITHUB_APP_CLIENT_ID_NAME: string
11-
PARAMETER_GITHUB_APP_CLIENT_SECRET_NAME: string
12-
PARAMETER_GITHUB_APP_ID_NAME: string
13-
PARAMETER_GITHUB_APP_KEY_BASE64_NAME: string
14-
}
2+
export interface ProcessEnv {
3+
ENVIRONMENT: string;
4+
SUBNET_IDS: string;
5+
GHES_URL: string;
6+
SCALE_DOWN_CONFIG: string;
7+
MINIMUM_RUNNING_TIME_IN_MINUTES: string;
8+
LAUNCH_TEMPLATE_NAME: string;
9+
AWS_REGION: string;
10+
PARAMETER_GITHUB_APP_CLIENT_ID_NAME: string;
11+
PARAMETER_GITHUB_APP_CLIENT_SECRET_NAME: string;
12+
PARAMETER_GITHUB_APP_ID_NAME: string;
13+
PARAMETER_GITHUB_APP_KEY_BASE64_NAME: string;
14+
}
1515
}

Diff for: modules/runners/lambdas/runners/src/scale-runners/runners.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ function getInstanceParams(
110110
}
111111

112112
function getSubnet(): string {
113-
const subnets = (process.env.SUBNET_IDS).split(',');
113+
const subnets = process.env.SUBNET_IDS.split(',');
114114
return subnets[Math.floor(Math.random() * subnets.length)];
115115
}

Diff for: modules/runners/lambdas/runners/src/scale-runners/scale-down.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ function createGitHubClientForRunnerFactory(): (runner: RunnerInfo, orgLevel: bo
3939
console.debug(`[createGitHubClientForRunner] Cache miss for ${key}`);
4040
const installationId = orgLevel
4141
? (
42-
await githubClient.apps.getOrgInstallation({
43-
org: repo.repoOwner,
44-
})
45-
).data.id
42+
await githubClient.apps.getOrgInstallation({
43+
org: repo.repoOwner,
44+
})
45+
).data.id
4646
: (
47-
await githubClient.apps.getRepoInstallation({
48-
owner: repo.repoOwner,
49-
repo: repo.repoName,
50-
})
51-
).data.id;
47+
await githubClient.apps.getRepoInstallation({
48+
owner: repo.repoOwner,
49+
repo: repo.repoName,
50+
})
51+
).data.id;
5252
const ghAuth2 = await createGithubAuth(installationId, 'installation', ghesApiUrl);
5353
const octokit = await createOctoClient(ghAuth2.token, ghesApiUrl);
5454
cache.set(key, octokit);
@@ -82,12 +82,12 @@ function listGithubRunnersFactory(): (
8282
console.debug(`[listGithubRunners] Cache miss for ${key}`);
8383
const runners = enableOrgLevel
8484
? await client.paginate(client.actions.listSelfHostedRunnersForOrg, {
85-
org: repo.repoOwner,
86-
})
85+
org: repo.repoOwner,
86+
})
8787
: await client.paginate(client.actions.listSelfHostedRunnersForRepo, {
88-
owner: repo.repoOwner,
89-
repo: repo.repoName,
90-
});
88+
owner: repo.repoOwner,
89+
repo: repo.repoName,
90+
});
9191
cache.set(key, runners);
9292

9393
return runners;
@@ -110,14 +110,14 @@ async function removeRunner(
110110
try {
111111
const result = enableOrgLevel
112112
? await githubAppClient.actions.deleteSelfHostedRunnerFromOrg({
113-
runner_id: ghRunnerId,
114-
org: repo.repoOwner,
115-
})
113+
runner_id: ghRunnerId,
114+
org: repo.repoOwner,
115+
})
116116
: await githubAppClient.actions.deleteSelfHostedRunnerFromRepo({
117-
runner_id: ghRunnerId,
118-
owner: repo.repoOwner,
119-
repo: repo.repoName,
120-
});
117+
runner_id: ghRunnerId,
118+
owner: repo.repoOwner,
119+
repo: repo.repoName,
120+
});
121121

122122
if (result.status == 204) {
123123
await terminateRunner(ec2runner);

0 commit comments

Comments
 (0)