diff --git a/.github/workflows/lambda-webhook.yml b/.github/workflows/lambda-webhook.yml index e4989fb79e..fa254f0c5c 100644 --- a/.github/workflows/lambda-webhook.yml +++ b/.github/workflows/lambda-webhook.yml @@ -3,6 +3,7 @@ on: push: branches: - develop + - next pull_request: paths: - .github/workflows/lambda-webhook.yml diff --git a/examples/multi-runner/README.md b/examples/multi-runner/README.md index 1f7e8eb40e..23c4d8916f 100644 --- a/examples/multi-runner/README.md +++ b/examples/multi-runner/README.md @@ -3,7 +3,7 @@ This module shows how to create GitHub action runners with multiple runner configuration together in one deployment. This example has the configurations for the following runner types with the relevant labels supported by them as matchers: - Linux ARM64 `["self-hosted", "linux", "arm64", "amazon"]` -- Linux Ubuntu `["self-hosted", "linux", "x64", "ubuntu"]` +- Linux Ubuntu `["self-hosted", "linux", "x64", "ubuntu-latest"]` or `["self-hosted", "linux", "x64", "ubuntu-2204"]`` - Linux X64 `["self-hosted", "linux", "x64", "amazon"]` - Windows X64 `["self-hosted", "windows", "x64", "servercore-2022"]` diff --git a/examples/multi-runner/main.tf b/examples/multi-runner/main.tf index 08da758363..708529fdb7 100644 --- a/examples/multi-runner/main.tf +++ b/examples/multi-runner/main.tf @@ -12,7 +12,7 @@ module "multi-runner" { multi_runner_config = { "linux-arm64" = { matcherConfig : { - labelMatchers = ["self-hosted", "linux", "arm64", "amazon"] + labelMatchers = [["self-hosted", "linux", "arm64", "amazon"]] exactMatch = true } fifo = true @@ -33,7 +33,7 @@ module "multi-runner" { }, "linux-ubuntu" = { matcherConfig : { - labelMatchers = ["self-hosted", "linux", "x64", "ubuntu"] + labelMatchers = [["self-hosted", "linux", "x64", "ubuntu-latest"], ["self-hosted", "linux", "x64", "ubuntu-2204"]] exactMatch = true } fifo = true @@ -45,12 +45,12 @@ module "multi-runner" { runner_config = { runner_os = "linux" runner_architecture = "x64" - runner_extra_labels = "ubuntu" + runner_extra_labels = "ubuntu-latest,ubuntu-2204" + runner_run_as = "ubuntu" enable_ssm_on_runners = true instance_types = ["m5ad.large", "m5a.large"] runners_maximum_count = 1 scale_down_schedule_expression = "cron(* * * * ? *)" - runner_run_as = "ubuntu" userdata_template = "./templates/user-data.sh" ami_owners = ["099720109477"] # Canonical's Amazon account ID @@ -93,7 +93,7 @@ module "multi-runner" { }, "windows-x64" = { matcherConfig : { - labelMatchers = ["self-hosted", "windows", "x64", "servercore-2022"] + labelMatchers = [["self-hosted", "windows", "x64", "servercore-2022"]] exactMatch = true } fifo = true @@ -114,7 +114,7 @@ module "multi-runner" { }, "linux-x64" = { matcherConfig : { - labelMatchers = ["self-hosted", "linux", "x64", "amazon"] + labelMatchers = [["self-hosted", "linux", "x64", "amazon"]] exactMatch = false } fifo = true diff --git a/modules/multi-runner/README.md b/modules/multi-runner/README.md index 47c3e25c79..58529e237d 100644 --- a/modules/multi-runner/README.md +++ b/modules/multi-runner/README.md @@ -42,7 +42,7 @@ module "multi-runner" { multi_runner_config = { "linux-arm" = { matcherConfig : { - labelMatchers = ["self-hosted", "linux", "arm64", "arm"] + labelMatchers = [["self-hosted", "linux", "arm64", "arm"]] exactMatch = true } runner_config = { @@ -57,7 +57,7 @@ module "multi-runner" { }, "linux-x64" = { matcherConfig : { - labelMatchers = ["self-hosted", "linux", "x64"] + labelMatchers = [["self-hosted", "linux", "x64"]] exactMatch = false } runner_config = { @@ -138,7 +138,7 @@ module "multi-runner" { | [log\_type](#input\_log\_type) | Logging format for lambda logging. Valid values are 'json', 'pretty', 'hidden'. | `string` | `"pretty"` | no | | [logging\_kms\_key\_id](#input\_logging\_kms\_key\_id) | Specifies the kms key id to encrypt the logs with | `string` | `null` | no | | [logging\_retention\_in\_days](#input\_logging\_retention\_in\_days) | Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `7` | no | -| [multi\_runner\_config](#input\_multi\_runner\_config) | multi\_runner\_config = {
runner\_config: {
runner\_os: "The EC2 Operating System type to use for action runner instances (linux,windows)."
runner\_architecture: "The platform architecture of the runner instance\_type."
runner\_metadata\_options: "(Optional) Metadata options for the ec2 runner instances."
ami\_filter: "(Optional) List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used."
ami\_owners: "(Optional) The list of owners used to select the AMI of action runner instances."
create\_service\_linked\_role\_spot: (Optional) create the serviced linked role for spot instances that is required by the scale-up lambda.
delay\_webhook\_event: "The number of seconds the event accepted by the webhook is invisible on the queue before the scale up lambda will receive the event."
disable\_runner\_autoupdate: "Disable the auto update of the github runner agent. Be-aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/)"
enable\_ephemeral\_runners: "Enable ephemeral runners, runners will only be used once."
enable\_job\_queued\_check: "Only scale if the job event received by the scale up lambda is is in the state queued. By default enabled for non ephemeral runners and disabled for ephemeral. Set this variable to overwrite the default behavior." = optional(bool, null)
enable\_organization\_runners: "Register runners to organization, instead of repo level"
enable\_runner\_binaries\_syncer: "Option to disable the lambda to sync GitHub runner distribution, useful when using a pre-build AMI."
enable\_ssm\_on\_runners: "Enable to allow access the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances."
enabled\_userdata: "Should the userdata script be enabled for the runner. Set this to false if you are using your own prebuilt AMI."
instance\_allocation\_strategy: "The allocation strategy for spot instances. AWS recommends to use `capacity-optimized` however the AWS default is `lowest-price`."
instance\_max\_spot\_price: "Max price price for spot intances per hour. This variable will be passed to the create fleet as max spot price for the fleet."
instance\_target\_capacity\_type: "Default lifecycle used for runner instances, can be either `spot` or `on-demand`."
instance\_types: "List of instance types for the action runner. Defaults are based on runner\_os (amzn2 for linux and Windows Server Core for win)."
job\_queue\_retention\_in\_seconds: "The number of seconds the job is held in the queue before it is purged"
minimum\_running\_time\_in\_minutes: "The time an ec2 action runner should be running at minimum before terminated if not busy."
pool\_runner\_owner: "The pool will deploy runners to the GitHub org ID, set this value to the org to which you want the runners deployed. Repo level is not supported."
runner\_as\_root: "Run the action runner under the root user. Variable `runner_run_as` will be ignored."
runner\_boot\_time\_in\_minutes: "The minimum time for an EC2 runner to boot and register as a runner."
runner\_extra\_labels: "Extra (custom) labels for the runners (GitHub). Separate each label by a comma. Labels checks on the webhook can be enforced by setting `enable_workflow_job_labels_check`. GitHub read-only labels should not be provided."
runner\_group\_name: "Name of the runner group."
runner\_run\_as: "Run the GitHub actions agent as user."
runners\_maximum\_count: "The maximum number of runners that will be created."
scale\_down\_schedule\_expression: "Scheduler expression to check every x for scale down."
scale\_up\_reserved\_concurrent\_executions: "Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations."
userdata\_template: "Alternative user-data template, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored."
enable\_runner\_detailed\_monitoring: "Should detailed monitoring be enabled for the runner. Set this to true if you want to use detailed monitoring. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html for details."
enable\_cloudwatch\_agent: "Enabling the cloudwatch agent on the ec2 runner instances, the runner contains default config. Configuration can be overridden via `cloudwatch_config`."
userdata\_pre\_install: "Script to be ran before the GitHub Actions runner is installed on the EC2 instances"
userdata\_post\_install: "Script to be ran after the GitHub Actions runner is installed on the EC2 instances"
runner\_ec2\_tags: "Map of tags that will be added to the launch template instance tag specifications."
runner\_iam\_role\_managed\_policy\_arns: "Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role"
idle\_config: "List of time period that can be defined as cron expression to keep a minimum amount of runners active instead of scaling down to 0. By defining this list you can ensure that in time periods that match the cron expression within 5 seconds a runner is kept idle."
runner\_log\_files: "(optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details."
block\_device\_mappings: "The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id`, `snapshot_id`."
pool\_config: "The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for week days to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1."
}
matcherConfig: {
labelMatchers: "The list of labels supported by the runner configuration."
exactMatch: "If set to true all labels in the workflow job must match the GitHub labels (os, architecture and `self-hosted`). When false if __any__ workflow label matches it will trigger the webhook."
}
fifo: "Enable a FIFO queue to remain the order of events received by the webhook. Suggest to set to true for repo level runners."
redrive\_build\_queue: "Set options to attach (optional) a dead letter queue to the build queue, the queue between the webhook and the scale up lambda. You have the following options. 1. Disable by setting `enabled` to false. 2. Enable by setting `enabled` to `true`, `maxReceiveCount` to a number of max retries."
} |
map(object({
runner_config = object({
runner_os = string
runner_architecture = string
runner_metadata_options = optional(map(any), {
instance_metadata_tags = "enabled"
http_endpoint = "enabled"
http_tokens = "optional"
http_put_response_hop_limit = 1
})
ami_filter = optional(map(list(string)), null)
ami_owners = optional(list(string), ["amazon"])
create_service_linked_role_spot = optional(bool, false)
delay_webhook_event = optional(number, 30)
disable_runner_autoupdate = optional(bool, false)
enable_ephemeral_runners = optional(bool, false)
enable_job_queued_check = optional(bool, null)
enable_organization_runners = optional(bool, false)
enable_runner_binaries_syncer = optional(bool, true)
enable_ssm_on_runners = optional(bool, false)
enabled_userdata = optional(bool, true)
instance_allocation_strategy = optional(string, "lowest-price")
instance_max_spot_price = optional(string, null)
instance_target_capacity_type = optional(string, "spot")
instance_types = list(string)
job_queue_retention_in_seconds = optional(number, 86400)
minimum_running_time_in_minutes = optional(number, null)
pool_runner_owner = optional(string, null)
runner_as_root = optional(bool, false)
runner_boot_time_in_minutes = optional(number, 5)
runner_extra_labels = string
runner_group_name = optional(string, "Default")
runner_run_as = optional(string, "ec2-user")
runners_maximum_count = number
scale_down_schedule_expression = optional(string, "cron(*/5 * * * ? *)")
scale_up_reserved_concurrent_executions = optional(number, 1)
userdata_template = optional(string, null)
enable_runner_detailed_monitoring = optional(bool, false)
enable_cloudwatch_agent = optional(bool, true)
userdata_pre_install = optional(string, "")
userdata_post_install = optional(string, "")
runner_ec2_tags = optional(map(string), {})
runner_iam_role_managed_policy_arns = optional(list(string), [])
idle_config = optional(list(object({
cron = string
timeZone = string
idleCount = number
})), [])
runner_log_files = optional(list(object({
log_group_name = string
prefix_log_group = bool
file_path = string
log_stream_name = string
})), null)
block_device_mappings = optional(list(object({
delete_on_termination = bool
device_name = string
encrypted = bool
iops = number
kms_key_id = string
snapshot_id = string
throughput = number
volume_size = number
volume_type = string
})), [{
delete_on_termination = true
device_name = "/dev/xvda"
encrypted = true
iops = null
kms_key_id = null
snapshot_id = null
throughput = null
volume_size = 30
volume_type = "gp3"
}])
pool_config = optional(list(object({
schedule_expression = string
size = number
})), [])
})

matcherConfig = object({
labelMatchers = list(string)
exactMatch = optional(bool, false)
})
fifo = optional(bool, false)
redrive_build_queue = optional(object({
enabled = bool
maxReceiveCount = number
}), {
enabled = false
maxReceiveCount = null
})
}))
| n/a | yes | +| [multi\_runner\_config](#input\_multi\_runner\_config) | multi\_runner\_config = {
runner\_config: {
runner\_os: "The EC2 Operating System type to use for action runner instances (linux,windows)."
runner\_architecture: "The platform architecture of the runner instance\_type."
runner\_metadata\_options: "(Optional) Metadata options for the ec2 runner instances."
ami\_filter: "(Optional) List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used."
ami\_owners: "(Optional) The list of owners used to select the AMI of action runner instances."
create\_service\_linked\_role\_spot: (Optional) create the serviced linked role for spot instances that is required by the scale-up lambda.
delay\_webhook\_event: "The number of seconds the event accepted by the webhook is invisible on the queue before the scale up lambda will receive the event."
disable\_runner\_autoupdate: "Disable the auto update of the github runner agent. Be-aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/)"
enable\_ephemeral\_runners: "Enable ephemeral runners, runners will only be used once."
enable\_job\_queued\_check: "Only scale if the job event received by the scale up lambda is is in the state queued. By default enabled for non ephemeral runners and disabled for ephemeral. Set this variable to overwrite the default behavior." = optional(bool, null)
enable\_organization\_runners: "Register runners to organization, instead of repo level"
enable\_runner\_binaries\_syncer: "Option to disable the lambda to sync GitHub runner distribution, useful when using a pre-build AMI."
enable\_ssm\_on\_runners: "Enable to allow access the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances."
enabled\_userdata: "Should the userdata script be enabled for the runner. Set this to false if you are using your own prebuilt AMI."
instance\_allocation\_strategy: "The allocation strategy for spot instances. AWS recommends to use `capacity-optimized` however the AWS default is `lowest-price`."
instance\_max\_spot\_price: "Max price price for spot intances per hour. This variable will be passed to the create fleet as max spot price for the fleet."
instance\_target\_capacity\_type: "Default lifecycle used for runner instances, can be either `spot` or `on-demand`."
instance\_types: "List of instance types for the action runner. Defaults are based on runner\_os (amzn2 for linux and Windows Server Core for win)."
job\_queue\_retention\_in\_seconds: "The number of seconds the job is held in the queue before it is purged"
minimum\_running\_time\_in\_minutes: "The time an ec2 action runner should be running at minimum before terminated if not busy."
pool\_runner\_owner: "The pool will deploy runners to the GitHub org ID, set this value to the org to which you want the runners deployed. Repo level is not supported."
runner\_as\_root: "Run the action runner under the root user. Variable `runner_run_as` will be ignored."
runner\_boot\_time\_in\_minutes: "The minimum time for an EC2 runner to boot and register as a runner."
runner\_extra\_labels: "Extra (custom) labels for the runners (GitHub). Separate each label by a comma. Labels checks on the webhook can be enforced by setting `enable_workflow_job_labels_check`. GitHub read-only labels should not be provided."
runner\_group\_name: "Name of the runner group."
runner\_run\_as: "Run the GitHub actions agent as user."
runners\_maximum\_count: "The maximum number of runners that will be created."
scale\_down\_schedule\_expression: "Scheduler expression to check every x for scale down."
scale\_up\_reserved\_concurrent\_executions: "Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations."
userdata\_template: "Alternative user-data template, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored."
enable\_runner\_detailed\_monitoring: "Should detailed monitoring be enabled for the runner. Set this to true if you want to use detailed monitoring. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html for details."
enable\_cloudwatch\_agent: "Enabling the cloudwatch agent on the ec2 runner instances, the runner contains default config. Configuration can be overridden via `cloudwatch_config`."
userdata\_pre\_install: "Script to be ran before the GitHub Actions runner is installed on the EC2 instances"
userdata\_post\_install: "Script to be ran after the GitHub Actions runner is installed on the EC2 instances"
runner\_ec2\_tags: "Map of tags that will be added to the launch template instance tag specifications."
runner\_iam\_role\_managed\_policy\_arns: "Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role"
idle\_config: "List of time period that can be defined as cron expression to keep a minimum amount of runners active instead of scaling down to 0. By defining this list you can ensure that in time periods that match the cron expression within 5 seconds a runner is kept idle."
runner\_log\_files: "(optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details."
block\_device\_mappings: "The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id`, `snapshot_id`."
pool\_config: "The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for week days to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1."
}
matcherConfig: {
labelMatchers: "The list of list of labels supported by the runner configuration. `[[self-hosted, linux, x64, example]]`"
exactMatch: "If set to true all labels in the workflow job must match the GitHub labels (os, architecture and `self-hosted`). When false if __any__ workflow label matches it will trigger the webhook."
}
fifo: "Enable a FIFO queue to remain the order of events received by the webhook. Suggest to set to true for repo level runners."
redrive\_build\_queue: "Set options to attach (optional) a dead letter queue to the build queue, the queue between the webhook and the scale up lambda. You have the following options. 1. Disable by setting `enabled` to false. 2. Enable by setting `enabled` to `true`, `maxReceiveCount` to a number of max retries."
} |
map(object({
runner_config = object({
runner_os = string
runner_architecture = string
runner_metadata_options = optional(map(any), {
instance_metadata_tags = "enabled"
http_endpoint = "enabled"
http_tokens = "optional"
http_put_response_hop_limit = 1
})
ami_filter = optional(map(list(string)), null)
ami_owners = optional(list(string), ["amazon"])
create_service_linked_role_spot = optional(bool, false)
delay_webhook_event = optional(number, 30)
disable_runner_autoupdate = optional(bool, false)
enable_ephemeral_runners = optional(bool, false)
enable_job_queued_check = optional(bool, null)
enable_organization_runners = optional(bool, false)
enable_runner_binaries_syncer = optional(bool, true)
enable_ssm_on_runners = optional(bool, false)
enabled_userdata = optional(bool, true)
instance_allocation_strategy = optional(string, "lowest-price")
instance_max_spot_price = optional(string, null)
instance_target_capacity_type = optional(string, "spot")
instance_types = list(string)
job_queue_retention_in_seconds = optional(number, 86400)
minimum_running_time_in_minutes = optional(number, null)
pool_runner_owner = optional(string, null)
runner_as_root = optional(bool, false)
runner_boot_time_in_minutes = optional(number, 5)
runner_extra_labels = string
runner_group_name = optional(string, "Default")
runner_run_as = optional(string, "ec2-user")
runners_maximum_count = number
scale_down_schedule_expression = optional(string, "cron(*/5 * * * ? *)")
scale_up_reserved_concurrent_executions = optional(number, 1)
userdata_template = optional(string, null)
enable_runner_detailed_monitoring = optional(bool, false)
enable_cloudwatch_agent = optional(bool, true)
userdata_pre_install = optional(string, "")
userdata_post_install = optional(string, "")
runner_ec2_tags = optional(map(string), {})
runner_iam_role_managed_policy_arns = optional(list(string), [])
idle_config = optional(list(object({
cron = string
timeZone = string
idleCount = number
})), [])
runner_log_files = optional(list(object({
log_group_name = string
prefix_log_group = bool
file_path = string
log_stream_name = string
})), null)
block_device_mappings = optional(list(object({
delete_on_termination = bool
device_name = string
encrypted = bool
iops = number
kms_key_id = string
snapshot_id = string
throughput = number
volume_size = number
volume_type = string
})), [{
delete_on_termination = true
device_name = "/dev/xvda"
encrypted = true
iops = null
kms_key_id = null
snapshot_id = null
throughput = null
volume_size = 30
volume_type = "gp3"
}])
pool_config = optional(list(object({
schedule_expression = string
size = number
})), [])
})

matcherConfig = object({
labelMatchers = list(list(string))
exactMatch = optional(bool, false)
})
fifo = optional(bool, false)
redrive_build_queue = optional(object({
enabled = bool
maxReceiveCount = number
}), {
enabled = false
maxReceiveCount = null
})
}))
| n/a | yes | | [pool\_lambda\_reserved\_concurrent\_executions](#input\_pool\_lambda\_reserved\_concurrent\_executions) | Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `number` | `1` | no | | [pool\_lambda\_timeout](#input\_pool\_lambda\_timeout) | Time out for the pool lambda in seconds. | `number` | `60` | no | | [prefix](#input\_prefix) | The prefix used for naming resources | `string` | `"github-actions"` | no | diff --git a/modules/multi-runner/variables.tf b/modules/multi-runner/variables.tf index a4c2db890a..f371f366f7 100644 --- a/modules/multi-runner/variables.tf +++ b/modules/multi-runner/variables.tf @@ -108,7 +108,7 @@ variable "multi_runner_config" { }) matcherConfig = object({ - labelMatchers = list(string) + labelMatchers = list(list(string)) exactMatch = optional(bool, false) }) fifo = optional(bool, false) @@ -165,7 +165,7 @@ variable "multi_runner_config" { pool_config: "The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for week days to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1." } matcherConfig: { - labelMatchers: "The list of labels supported by the runner configuration." + labelMatchers: "The list of list of labels supported by the runner configuration. `[[self-hosted, linux, x64, example]]`" exactMatch: "If set to true all labels in the workflow job must match the GitHub labels (os, architecture and `self-hosted`). When false if __any__ workflow label matches it will trigger the webhook." } fifo: "Enable a FIFO queue to remain the order of events received by the webhook. Suggest to set to true for repo level runners." diff --git a/modules/webhook/lambdas/webhook/src/sqs/index.ts b/modules/webhook/lambdas/webhook/src/sqs/index.ts index 024b04062b..e3481513d1 100644 --- a/modules/webhook/lambdas/webhook/src/sqs/index.ts +++ b/modules/webhook/lambdas/webhook/src/sqs/index.ts @@ -15,9 +15,10 @@ export interface ActionRequestMessage { } export interface MatcherConfig { - labelMatchers: string[]; + labelMatchers: string[][]; exactMatch: bool; } + export interface QueueConfig { matcherConfig: MatcherConfig; id: string; diff --git a/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts b/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts index e79a7068e8..85265bd335 100644 --- a/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts +++ b/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts @@ -148,14 +148,14 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted', 'test'], + labelMatchers: [['self-hosted', 'test']], exactMatch: true, }, }, { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted', 'test1'], + labelMatchers: [['self-hosted', 'test1']], exactMatch: true, }, }, @@ -180,14 +180,14 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['linux', 'TEST', 'self-hosted'], + labelMatchers: [['linux', 'TEST', 'self-hosted']], exactMatch: true, }, }, { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted', 'test1'], + labelMatchers: [['self-hosted', 'test1']], exactMatch: true, }, }, @@ -212,14 +212,14 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted', 'test', 'test2'], + labelMatchers: [['self-hosted', 'test', 'test2']], exactMatch: true, }, }, { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted', 'test1'], + labelMatchers: [['self-hosted', 'test1']], exactMatch: true, }, }, @@ -244,14 +244,14 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted', 'x64', 'linux', 'test'], + labelMatchers: [['self-hosted', 'x64', 'linux', 'test']], exactMatch: true, }, }, { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted', 'x64', 'linux', 'test1'], + labelMatchers: [['self-hosted', 'x64', 'linux', 'test1']], exactMatch: true, }, }, @@ -276,14 +276,14 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted', 'test', 'test2'], + labelMatchers: [['self-hosted', 'test', 'test2']], exactMatch: true, }, }, { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted', 'x64'], + labelMatchers: [['self-hosted', 'x64']], exactMatch: false, }, }, @@ -308,14 +308,14 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted', 'x64', 'linux', 'test'], + labelMatchers: [['self-hosted', 'x64', 'linux', 'test']], exactMatch: false, }, }, { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted', 'x64', 'linux', 'test1'], + labelMatchers: [['self-hosted', 'x64', 'linux', 'test1']], exactMatch: false, }, }, @@ -339,7 +339,7 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted'], + labelMatchers: [['self-hosted']], exactMatch: false, }, id: 'ubuntu-queue-id', @@ -347,7 +347,7 @@ describe('handler', () => { { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted'], + labelMatchers: [['self-hosted']], exactMatch: false, }, id: 'default-queue-id', @@ -380,7 +380,7 @@ describe('handler', () => { { ...queuesConfig[0], matcherConfig: { - labelMatchers: ['self-hosted'], + labelMatchers: [['self-hosted']], exactMatch: false, }, id: 'ubuntu-queue-id', @@ -388,7 +388,7 @@ describe('handler', () => { { ...queuesConfig[1], matcherConfig: { - labelMatchers: ['self-hosted'], + labelMatchers: [['self-hosted']], exactMatch: false, }, id: 'default-queue-id', @@ -418,6 +418,43 @@ describe('handler', () => { }); }); + it('Check webhook will accept jobs when matchers accepts multiple labels.', async () => { + process.env.RUNNER_CONFIG = JSON.stringify([ + { + ...queuesConfig[0], + matcherConfig: { + labelMatchers: [ + ['self-hosted', 'arm64', 'linux', 'ubuntu-latest'], + ['self-hosted', 'arm64', 'linux', 'ubuntu-2204'], + ], + exactMatch: false, + }, + id: 'ubuntu-queue-id', + }, + ]); + const event = JSON.stringify({ + ...workflowjob_event, + workflow_job: { + ...workflowjob_event.workflow_job, + labels: ['self-hosted', 'linux', 'arm64', 'ubuntu-latest'], + }, + }); + const resp = await handle( + { 'X-Hub-Signature': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' }, + event, + ); + expect(resp.statusCode).toBe(201); + expect(sendActionRequest).toBeCalledWith({ + id: workflowjob_event.workflow_job.id, + repositoryName: workflowjob_event.repository.name, + repositoryOwner: workflowjob_event.repository.owner.login, + eventType: 'workflow_job', + installationId: 0, + queueId: 'ubuntu-queue-id', + queueFifo: false, + }); + }); + describe('Test for check_run is ignored.', () => { it('handles check_run events', async () => { const event = JSON.stringify(checkrun_event); diff --git a/modules/webhook/lambdas/webhook/src/webhook/handler.ts b/modules/webhook/lambdas/webhook/src/webhook/handler.ts index ce11cf6535..7f0e233ee7 100644 --- a/modules/webhook/lambdas/webhook/src/webhook/handler.ts +++ b/modules/webhook/lambdas/webhook/src/webhook/handler.ts @@ -161,18 +161,22 @@ function isRepoNotAllowed(repoFullName: string, repositoryWhiteList: string[]): return repositoryWhiteList.length > 0 && !repositoryWhiteList.includes(repoFullName); } -function canRunJob(workflowJobLabels: string[], runnerLabels: string[], workflowLabelCheckAll: boolean): boolean { - runnerLabels = runnerLabels.map((element) => { - return element.toLowerCase(); +function canRunJob( + workflowJobLabels: string[], + runnerLabelsMatchers: string[][], + workflowLabelCheckAll: boolean, +): boolean { + runnerLabelsMatchers = runnerLabelsMatchers.map((runnerLabel) => { + return runnerLabel.map((label) => label.toLowerCase()); }); const match = workflowLabelCheckAll - ? workflowJobLabels.every((l) => runnerLabels.includes(l.toLowerCase())) - : workflowJobLabels.some((l) => runnerLabels.includes(l.toLowerCase())); + ? workflowJobLabels.every((wl) => runnerLabelsMatchers.some((rl) => rl.includes(wl.toLowerCase()))) + : workflowJobLabels.some((wl) => runnerLabelsMatchers.some((rl) => rl.includes(wl.toLowerCase()))); logger.debug( `Received workflow job event with labels: '${JSON.stringify(workflowJobLabels)}'. The event does ${ match ? '' : 'NOT ' - }match the runner labels: '${Array.from(runnerLabels).join(',')}'`, + }match the runner labels: '${Array.from(runnerLabelsMatchers).join(',')}'`, LogFields.print(), ); return match; diff --git a/modules/webhook/lambdas/webhook/test/resources/multi_runner_configurations.json b/modules/webhook/lambdas/webhook/test/resources/multi_runner_configurations.json index de0ed6945c..a40eefd084 100644 --- a/modules/webhook/lambdas/webhook/test/resources/multi_runner_configurations.json +++ b/modules/webhook/lambdas/webhook/test/resources/multi_runner_configurations.json @@ -4,12 +4,12 @@ "arn": "queueARN", "fifo": false, "matcherConfig": { - "labelMatchers": [ + "labelMatchers": [[ "self-hosted", "linux", "x64", "ubuntu" - ], + ]], "exactMatch": true } }, @@ -18,12 +18,12 @@ "arn": "queueARN", "fifo": false, "matcherConfig": { - "labelMatchers": [ + "labelMatchers": [[ "self-hosted", "linux", "x64", "latest" - ], + ]], "exactMatch": false } } diff --git a/modules/webhook/variables.tf b/modules/webhook/variables.tf index cce2b13da9..8b086ad663 100644 --- a/modules/webhook/variables.tf +++ b/modules/webhook/variables.tf @@ -28,7 +28,7 @@ variable "runner_config" { id = string fifo = bool matcherConfig = object({ - labelMatchers = list(string) + labelMatchers = list(list(string)) exactMatch = bool }) }))