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

fix: Ignore case for runner labels. #2315

Merged
merged 2 commits into from
Aug 4, 2022
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
2 changes: 1 addition & 1 deletion modules/runners/scale-up.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ resource "aws_lambda_function" "scale_up" {
NODE_TLS_REJECT_UNAUTHORIZED = var.ghes_url != null && !var.ghes_ssl_verify ? 0 : 1
PARAMETER_GITHUB_APP_ID_NAME = var.github_app_parameters.id.name
PARAMETER_GITHUB_APP_KEY_BASE64_NAME = var.github_app_parameters.key_base64.name
RUNNER_EXTRA_LABELS = var.runner_extra_labels
RUNNER_EXTRA_LABELS = lower(var.runner_extra_labels)
RUNNER_GROUP_NAME = var.runner_group_name
RUNNERS_MAXIMUM_COUNT = var.runners_maximum_count
SUBNET_IDS = join(",", var.subnet_ids)
Expand Down
4 changes: 2 additions & 2 deletions modules/webhook/lambdas/webhook/src/webhook/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('handler', () => {
...workflowjob_event,
workflow_job: {
...workflowjob_event.workflow_job,
labels: ['self-hosted', 'test'],
labels: ['self-hosted', 'Test'],
},
});
const resp = await handle(
Expand All @@ -141,7 +141,7 @@ describe('handler', () => {
});

it('Check runner labels accept job with mixed order.', async () => {
process.env.RUNNER_LABELS = '["linux", "test", "self-hosted"]';
process.env.RUNNER_LABELS = '["linux", "TEST", "self-hosted"]';
npalm marked this conversation as resolved.
Show resolved Hide resolved
process.env.ENABLE_WORKFLOW_JOB_LABELS_CHECK = 'true';
process.env.WORKFLOW_JOB_LABELS_CHECK_ALL = 'true';
const event = JSON.stringify({
Expand Down
6 changes: 3 additions & 3 deletions modules/webhook/lambdas/webhook/src/webhook/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function readEnvironmentVariables() {
const workflowLabelCheckAll = JSON.parse(workflowLabelCheckAllEnv) as boolean;
const repositoryWhiteListEnv = process.env.REPOSITORY_WHITE_LIST || '[]';
const repositoryWhiteList = JSON.parse(repositoryWhiteListEnv) as Array<string>;
const runnerLabelsEnv = process.env.RUNNER_LABELS || '[]';
const runnerLabelsEnv = (process.env.RUNNER_LABELS || '[]').toLowerCase();
const runnerLabels = JSON.parse(runnerLabelsEnv) as Array<string>;
return { environment, repositoryWhiteList, enableWorkflowLabelCheck, workflowLabelCheckAll, runnerLabels };
}
Expand Down Expand Up @@ -178,8 +178,8 @@ function isRepoNotAllowed(repoFullName: string, repositoryWhiteList: string[]):
function canRunJob(job: WorkflowJobEvent, runnerLabels: string[], workflowLabelCheckAll: boolean): boolean {
const workflowJobLabels = job.workflow_job.labels;
const match = workflowLabelCheckAll
? workflowJobLabels.every((l) => runnerLabels.includes(l))
: workflowJobLabels.some((l) => runnerLabels.includes(l));
? workflowJobLabels.every((l) => runnerLabels.includes(l.toLowerCase()))
: workflowJobLabels.some((l) => runnerLabels.includes(l.toLowerCase()));

logger.debug(
`Received workflow job event with labels: '${JSON.stringify(workflowJobLabels)}'. The event does ${
Expand Down
2 changes: 1 addition & 1 deletion modules/webhook/webhook.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "aws_lambda_function" "webhook" {
LOG_LEVEL = var.log_level
LOG_TYPE = var.log_type
REPOSITORY_WHITE_LIST = jsonencode(var.repository_white_list)
RUNNER_LABELS = jsonencode(split(",", var.runner_labels))
RUNNER_LABELS = jsonencode(split(",", lower(var.runner_labels)))
SQS_URL_WEBHOOK = var.sqs_build_queue.id
SQS_IS_FIFO = var.sqs_build_queue_fifo
}
Expand Down