rename auto-init main to default_branch and reject invalid ruleset shapes
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful

This commit is contained in:
2026-11-10 22:01:33 +11:00
parent d7359d1fc7
commit 23c315a49a
3 changed files with 76 additions and 0 deletions
+3
View File
@@ -117,6 +117,9 @@ resource "github_branch_default" "this" {
repository = github_repository.this[each.key].name
branch = each.value.default_branch
# auto_init only creates main; rename it instead of pointing at a missing branch
rename = true
wait_for_rename = true
}
resource "github_repository_collaborators" "this" {
@@ -230,3 +230,66 @@ run "unknown_ruleset_rejected" {
expect_failures = [var.repository]
}
run "non_main_default_branch_renamed" {
command = plan
variables {
repository = {
legacy = { name = "legacy", default_branch = "master", maintainers = ["carol"] }
}
}
assert {
condition = (
github_branch_default.this["legacy"].branch == "master" &&
github_branch_default.this["legacy"].rename &&
github_branch_default.this["legacy"].wait_for_rename
)
error_message = "default_branch must rename the auto-init main and wait for it to propagate"
}
assert {
condition = github_repository_file.codeowners["legacy"].branch == "master"
error_message = "CODEOWNERS must be committed to the renamed default branch"
}
}
run "tag_ruleset_pull_request_rejected" {
command = plan
variables {
ruleset = {
tagpr = { name = "tagpr", target = "tag", rules = { pull_request = {} } }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "tag_ruleset_status_checks_rejected" {
command = plan
variables {
ruleset = {
tagci = { name = "tagci", target = "tag", rules = { required_status_checks = { contexts = ["ci"] } } }
}
repository = {}
}
expect_failures = [var.ruleset]
}
run "empty_status_check_contexts_rejected" {
command = plan
variables {
ruleset = {
noci = { name = "noci", rules = { required_status_checks = { contexts = [] } } }
}
repository = {}
}
expect_failures = [var.ruleset]
}
+10
View File
@@ -49,6 +49,16 @@ variable "ruleset" {
condition = length(setintersection(keys(var.ruleset), ["branch-protection", "required-checks", "tag-protection"])) == 0
error_message = "Ruleset names branch-protection, required-checks and tag-protection are reserved for generated rulesets."
}
validation {
condition = alltrue([for rs in var.ruleset : rs.target == "branch" || (rs.rules.pull_request == null && rs.rules.required_status_checks == null)])
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([for rs in var.ruleset : rs.rules.required_status_checks == null || length(rs.rules.required_status_checks.contexts) > 0])
error_message = "required_status_checks.contexts must not be empty: ${join(", ", [for k, rs in var.ruleset : k if rs.rules.required_status_checks != null && length(rs.rules.required_status_checks.contexts) == 0])}."
}
}
variable "repository" {