Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add github_branch_protection for next-* #31

Merged
merged 10 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions terraform/github/repository.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
module "github_repository" {
source = "../modules/github_repository"
for_each = var.repositories
name = each.key
description = each.value.description
topics = each.value.topics
homepage_url = each.value.homepage_url
visibility = each.value.visibility
collaborators = each.value.collaborators
pages = each.value.pages
has_discussions = each.value.has_discussions
is_archived = each.value.is_archived
allow_squash_merge = each.value.allow_squash_merge
allow_rebase_merge = each.value.allow_rebase_merge
source = "../modules/github_repository"
for_each = var.repositories
name = each.key
description = each.value.description
topics = each.value.topics
homepage_url = each.value.homepage_url
visibility = each.value.visibility
collaborators = each.value.collaborators
pages = each.value.pages
has_discussions = each.value.has_discussions
is_archived = each.value.is_archived
allow_squash_merge = each.value.allow_squash_merge
allow_rebase_merge = each.value.allow_rebase_merge
has_release_branches = each.value.has_release_branches
}
7 changes: 4 additions & 3 deletions terraform/github/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ repositories = {
{ username = "remiguittaut", permission = "push" },
{ username = "rzeigler", permission = "push" },
]
pages = { build_type = "workflow" }
homepage_url = "https://www.effect.website"
topics = ["effect-system", "fp", "framework", "stack-safe", "typescript", "zio"]
pages = { build_type = "workflow" }
homepage_url = "https://www.effect.website"
topics = ["effect-system", "fp", "framework", "stack-safe", "typescript", "zio"]
has_release_branches = true
}
eslint-plugin = {
description = "A set of ESlint and TypeScript rules to work with Effect"
Expand Down
19 changes: 10 additions & 9 deletions terraform/github/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ variable "default_branch" {
variable "repositories" {
description = "The Effect-TS organization repositories whose configuration should be managed"
type = map(object({
description = optional(string, "")
topics = optional(set(string), [])
homepage_url = optional(string, "")
visibility = optional(string, "public")
is_archived = optional(bool, false)
has_discussions = optional(bool, false)
enable_changesets = optional(bool, true)
allow_squash_merge = optional(bool, true)
allow_rebase_merge = optional(bool, false)
description = optional(string, "")
topics = optional(set(string), [])
homepage_url = optional(string, "")
visibility = optional(string, "public")
is_archived = optional(bool, false)
has_discussions = optional(bool, false)
enable_changesets = optional(bool, true)
allow_squash_merge = optional(bool, true)
allow_rebase_merge = optional(bool, false)
has_release_branches = optional(bool, false)
collaborators = optional(list(object({
username = string,
permission = string
Expand Down
24 changes: 24 additions & 0 deletions terraform/modules/github_repository/branch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ resource "github_branch_protection" "main" {
required_approving_review_count = 0
}
}


resource "github_branch_protection" "next-release" {
# Branch protection can only be enabled on private repositories if using a
# paid GitHub plan
count = var.visibility == "public" && var.has_release_branches ? 1 : 0

repository_id = github_repository.repository.node_id
pattern = "next-*"
enforce_admins = true
required_linear_history = false
allows_deletions = false
allows_force_pushes = true
blocks_creations = false

required_status_checks {
strict = true
contexts = null
}

required_pull_request_reviews {
required_approving_review_count = 0
}
}
6 changes: 6 additions & 0 deletions terraform/modules/github_repository/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ variable "delete_branch_on_merge" {
description = "Automatically delete head branch after a pull request is merged. Defaults to 'true'."
default = true
}

variable "has_release_branches" {
type = bool
description = "Has next-* branches for releases"
default = false
}
Loading