Skip to content

Commit

Permalink
fix: Ignore case for runner labels. (#2315)
Browse files Browse the repository at this point in the history
* fix: Ignore case for runner labels.

* format code
  • Loading branch information
npalm authored Aug 4, 2022
1 parent 6d9116f commit 014985a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
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"]';
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

0 comments on commit 014985a

Please sign in to comment.