Skip to content

Commit d4f0d50

Browse files
committed
# This is a combination of 6 commits.
# This is the 1st commit message: Rebase # This is the commit message #2: fix: terraform error # This is the commit message #3: fix: terraform error # This is the commit message #4: fix: test and linter # This is the commit message #5: runner labels can be a subset # This is the commit message #6: runner labels can be a subset
1 parent 105624e commit d4f0d50

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

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

Lines changed: 4 additions & 5 deletions
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

modules/webhook/lambdas/webhook/src/webhook/handler.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ describe('handler', () => {
139139
expect(sendActionRequest).toBeCalled();
140140
});
141141

142+
it('Check runner a runner with multiple labels accept a job with a subset of labels.', async () => {
143+
process.env.RUNNER_LABELS = '["test", "linux"]';
144+
const event = JSON.stringify({
145+
...workflowjob_event,
146+
workflow_job: {
147+
...workflowjob_event.workflow_job,
148+
labels: ['self-hosted'],
149+
},
150+
});
151+
const resp = await handle(
152+
{ 'X-Hub-Signature': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' },
153+
event,
154+
);
155+
expect(resp).toBe(200);
156+
expect(sendActionRequest).toBeCalled();
157+
});
158+
142159
it('Check runner labels in mixed order', async () => {
143160
process.env.RUNNER_LABELS = '["test", "linux"]';
144161
const event = JSON.stringify({

modules/webhook/lambdas/webhook/src/webhook/handler.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,12 @@ function isRunnerNotAllowed(job: WorkflowJob): boolean {
127127

128128
// ensure the self-hosted label is in the list.
129129
runnerLabels.add('self-hosted');
130-
const sortedRunnerLabels = Array.from(runnerLabels.values()).sort();
131-
const sortedWorkflowLabels = job.workflow_job.labels.slice().sort();
130+
const runnerMatch = job.workflow_job.labels.every((l) => runnerLabels.has(l));
132131

133-
const notMatched = sortedWorkflowLabels.toString() !== sortedRunnerLabels.toString();
134132
console.debug(
135-
`Received runner job labels: '${sortedWorkflowLabels}' do ${
136-
notMatched ? 'NOT' : ''
137-
} match the configured labels '${sortedRunnerLabels}'`,
133+
`Received runner job labels: '${JSON.stringify(job.workflow_job.labels)}' do ${
134+
runnerMatch ? '' : 'NOT'
135+
} match the configured labels '${JSON.stringify(runnerLabels)}'`,
138136
);
139-
return notMatched;
137+
return !runnerMatch;
140138
}

0 commit comments

Comments
 (0)