reject private on forks and document fork_from public-upstream constraint
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful

This commit is contained in:
2026-11-19 22:28:01 +11:00
parent 361f34d820
commit bab6233613
3 changed files with 19 additions and 5 deletions
+12 -1
View File
@@ -119,7 +119,6 @@ run "fork_from_source" {
autocraft = { name = "autocraft", fork_from = "storytold/autocraft", maintainers = ["@maintainers"] }
plain = { name = "plain" }
secret = { name = "secret", maintainers = ["@maintainers"] }
public = { name = "public", private = false, fork_from = "storytold/public" }
}
}
@@ -176,6 +175,18 @@ run "private_fork_rejected" {
expect_failures = [var.repository]
}
run "public_fork_rejected" {
command = plan
variables {
repository = {
bad = { name = "bad", fork_from = "storytold/autocraft", private = false }
}
}
expect_failures = [var.repository]
}
run "invalid_fork_from_rejected" {
command = plan
+4 -4
View File
@@ -96,7 +96,7 @@ variable "ruleset" {
}
variable "repository" {
description = "Map of repositories to create, keyed by name"
description = "Map of repositories to create, keyed by name; fork_from (owner/repo) forks a public upstream and requires private to be omitted"
type = map(object({
name = string
description = optional(string, "")
@@ -114,12 +114,12 @@ variable "repository" {
validation {
condition = alltrue([for repo in var.repository : repo.fork_from == null || can(regex("^[^/]+/[^/]+$", repo.fork_from))])
error_message = "fork_from must be \"<owner>/<repo>\": ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && !can(regex("^[^/]+/[^/]+$", coalesce(repo.fork_from, "-")))])}."
error_message = "fork_from must be \"<owner>/<repo>\" of a public upstream: ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && !can(regex("^[^/]+/[^/]+$", coalesce(repo.fork_from, "-")))])}."
}
validation {
condition = alltrue([for repo in var.repository : !(repo.fork_from != null && repo.private == true)])
error_message = "private cannot be set on a fork, its visibility follows the source: ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && repo.private == true])}."
condition = alltrue([for repo in var.repository : repo.fork_from == null || repo.private == null])
error_message = "private cannot be set on a fork, its visibility follows the source and only public upstreams can be forked: ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && repo.private != null])}."
}
validation {