Validate bypass_actors actor_type, bypass_mode and actor_id
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful

Allowed values from integrations/github 6.13.0 github_repository_ruleset:
actor_id is required for RepositoryRole, Integration and User and rejected
for Team (resolved from team), OrganizationAdmin, EnterpriseOwner and
DeployKey.
This commit is contained in:
2026-11-17 23:49:50 +11:00
parent 6ab490c23c
commit 04bc546e15
2 changed files with 86 additions and 1 deletions
+66 -1
View File
@@ -297,7 +297,72 @@ run "bypass_team_without_slug_rejected" {
variables {
ruleset = {
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "Team", actor_id = 1 }] }
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "Team" }] }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "bypass_unknown_actor_type_rejected" {
command = plan
variables {
ruleset = {
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "Bot" }] }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "bypass_unknown_mode_rejected" {
command = plan
variables {
ruleset = {
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "OrganizationAdmin", bypass_mode = "sometimes" }] }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "bypass_actor_id_missing_rejected" {
command = plan
variables {
ruleset = {
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "User" }] }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "bypass_actor_id_on_idless_actor_rejected" {
command = plan
variables {
ruleset = {
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "DeployKey", actor_id = 1 }] }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "bypass_team_with_actor_id_rejected" {
command = plan
variables {
ruleset = {
guarded = { name = "guarded", rules = {}, bypass_actors = [{ actor_type = "Team", team = "maintainers", actor_id = 1 }] }
}
repository = {}
}
+20
View File
@@ -59,6 +59,26 @@ variable "ruleset" {
error_message = "pull_request and required_status_checks are branch-only rules, not allowed on tag rulesets: ${join(", ", [for k, rs in var.ruleset : k if rs.target != "branch" && (rs.rules.pull_request != null || rs.rules.required_status_checks != null)])}."
}
validation {
condition = alltrue(flatten([for rs in var.ruleset : [for a in rs.bypass_actors : contains(["RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey", "EnterpriseOwner", "User"], a.actor_type)]]))
error_message = "bypass_actors actor_type must be RepositoryRole, Team, Integration, OrganizationAdmin, DeployKey, EnterpriseOwner or User: ${join(", ", flatten([for k, rs in var.ruleset : [for a in rs.bypass_actors : "${k}/${a.actor_type}" if !contains(["RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey", "EnterpriseOwner", "User"], a.actor_type)]]))}."
}
validation {
condition = alltrue(flatten([for rs in var.ruleset : [for a in rs.bypass_actors : contains(["always", "pull_request", "exempt"], a.bypass_mode)]]))
error_message = "bypass_actors bypass_mode must be always, pull_request or exempt: ${join(", ", flatten([for k, rs in var.ruleset : [for a in rs.bypass_actors : "${k}/${a.actor_type}/${a.bypass_mode}" if !contains(["always", "pull_request", "exempt"], a.bypass_mode)]]))}."
}
validation {
condition = alltrue(flatten([for rs in var.ruleset : [for a in rs.bypass_actors : a.actor_id != null if contains(["RepositoryRole", "Integration", "User"], a.actor_type)]]))
error_message = "bypass_actors actor_id is required for RepositoryRole, Integration and User: ${join(", ", flatten([for k, rs in var.ruleset : [for a in rs.bypass_actors : "${k}/${a.actor_type}" if contains(["RepositoryRole", "Integration", "User"], a.actor_type) && a.actor_id == null]]))}."
}
validation {
condition = alltrue(flatten([for rs in var.ruleset : [for a in rs.bypass_actors : a.actor_id == null if !contains(["RepositoryRole", "Integration", "User"], a.actor_type)]]))
error_message = "bypass_actors actor_id must not be set for Team (use team), OrganizationAdmin, EnterpriseOwner or DeployKey: ${join(", ", flatten([for k, rs in var.ruleset : [for a in rs.bypass_actors : "${k}/${a.actor_type}" if !contains(["RepositoryRole", "Integration", "User"], a.actor_type) && a.actor_id != null]]))}."
}
validation {
condition = alltrue(flatten([for rs in var.ruleset : [for a in rs.bypass_actors : (a.actor_type == "Team") == (a.team != null)]]))
error_message = "bypass_actors team must be set exactly when actor_type is Team: ${join(", ", flatten([for k, rs in var.ruleset : [for a in rs.bypass_actors : "${k}/${a.actor_type}" if(a.actor_type == "Team") != (a.team != null)]]))}."