Skip to content
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
28 changes: 28 additions & 0 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check infrastructure formatting

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

jobs:
validate:
runs-on: ubuntu-24.04
timeout-minutes: 5
defaults:
run:
working-directory: infrastructure
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: opentofu/setup-opentofu@a1320f892987e89d278cc92dc5adc984fb93aca4 # v2.0.2
with:
tofu_version: '1.13.1'
tofu_wrapper: false
- name: Check formatting
run: tofu fmt -check -recursive
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.terraform/
*.tfstate.*
*.tfvars
*.tfvars.json
*.tfplan
.env
.env.*
!.env.example
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# .github

Tuxcrate organization profile and shared GitHub configuration.

The [`infrastructure/`](infrastructure/) directory contains OpenTofu configuration for GitHub repository metadata and branch protection across the organization.
58 changes: 58 additions & 0 deletions infrastructure/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
terraform {
required_version = "~> 1.13"
encryption {
key_provider "pbkdf2" "my_key_provider_name" {
passphrase = var.state_passphrase
}
method "aes_gcm" "my_method_name" {
keys = key_provider.pbkdf2.my_key_provider_name
}
state {
method = method.aes_gcm.my_method_name
enforced = true
}
plan {
method = method.aes_gcm.my_method_name
enforced = true
}
}

required_providers {
github = {
source = "integrations/github"
version = "~> 6.13.0"
}
}
}

provider "github" {
owner = "tuxcrate"
}
46 changes: 46 additions & 0 deletions infrastructure/modules/repository/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
resource "github_repository" "this" {
name = var.name
description = var.description
homepage_url = var.homepage_url
topics = var.topics
visibility = "public"

has_issues = true
has_projects = false
has_wiki = false

allow_merge_commit = true
allow_squash_merge = true
allow_rebase_merge = true
allow_auto_merge = true
delete_branch_on_merge = true
archive_on_destroy = true
}

resource "github_branch_default" "this" {
repository = github_repository.this.name
branch = "main"
}

resource "github_branch_protection_v3" "this" {
repository = github_repository.this.name
branch = github_branch_default.this.branch
enforce_admins = true
require_conversation_resolution = true

dynamic "required_status_checks" {
for_each = length(var.required_checks) > 0 ? [var.required_checks] : []
content {
strict = true
# 15368 is GitHub Actions' app ID on github.com. No spoofable any-app checks.
checks = [for context in required_status_checks.value : "${context}:15368"]
}
}

required_pull_request_reviews {
required_approving_review_count = 0
dismiss_stale_reviews = true
require_code_owner_reviews = false
require_last_push_approval = false
}
}
18 changes: 18 additions & 0 deletions infrastructure/modules/repository/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
output "repository" {
description = "Managed GitHub repository URL and About settings."
value = {
name = github_repository.this.name
html_url = github_repository.this.html_url
description = github_repository.this.description
homepage_url = github_repository.this.homepage_url
topics = github_repository.this.topics
}
}

output "required_status_checks" {
description = "Required default-branch checks and their strictness."
value = [for status_checks in github_branch_protection_v3.this.required_status_checks : {
checks = status_checks.checks
strict = status_checks.strict
}]
}
27 changes: 27 additions & 0 deletions infrastructure/modules/repository/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "name" {
description = "GitHub repository name."
type = string
}

variable "description" {
description = "GitHub repository description."
type = string
}

variable "homepage_url" {
description = "GitHub repository homepage URL."
type = string
default = "https://tuxcrate.com"
}

variable "topics" {
description = "GitHub repository topics, in addition to tuxcrate."
type = set(string)
default = []
}

variable "required_checks" {
description = "Required GitHub Actions checks for the default branch."
type = set(string)
default = []
}
8 changes: 8 additions & 0 deletions infrastructure/modules/repository/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
github = {
source = "integrations/github"
version = ">= 6.13.0"
}
}
}
6 changes: 6 additions & 0 deletions infrastructure/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
output "repositories" {
description = "Repositories managed by this stack."
value = {
for name, repo in module.repository : name => repo.repository.html_url
}
}
59 changes: 59 additions & 0 deletions infrastructure/repositories.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
locals {
base_repos = {
".github" = {
description = "Tuxcrate organization profile and shared GitHub configuration."
required_checks = toset(["validate"])
}
"docs" = {
description = "The Tuxcrate website. Open source apps, ready to run."
required_checks = toset(["build", "test"])
}
"github-actions" = {
description = "Shared GitHub Actions workflows for Tuxcrate container images"
homepage_url = "https://tuxcrate.com/maintainers/container-releases/"
required_checks = toset(["test"])
}
}
container_repos = toset([
"gallery-dl",
"prowlarr",
"radarr",
"sonarr",
"zrepl",
])
container_release_metadata = {
for repo in local.container_repos :
repo => yamldecode(file("${path.module}/../../${repo}/meta.yaml"))
}
container_metadata = {
for repo in local.container_repos :
repo => yamldecode(regex(
"(?s)^---\\r?\\n(.*?)\\r?\\n---(?:\\r?\\n|$)",
file("${path.module}/../../docs/docs/containers/${repo}.md")
)[0]).container
}
repositories = merge(local.base_repos, {
for repo in local.container_repos :
repo => {
homepage_url = "https://tuxcrate.com/containers/${repo}/"
description = local.container_metadata[repo].description
topics = concat(local.container_metadata[repo].topics, ["tuxcrate"])
# Match the shared workflow's check names for every declared track.
required_checks = setunion(toset(["container / plan"]), toset([
for track in local.container_release_metadata[repo].tracks :
"container / pull-request (${track.name})"
]))
}
})
}

module "repository" {
source = "./modules/repository"
for_each = local.repositories

name = each.key
description = each.value.description
homepage_url = try(each.value.homepage_url, "https://tuxcrate.com")
topics = try(each.value.topics, [])
required_checks = each.value.required_checks
}
1 change: 1 addition & 0 deletions infrastructure/terraform.tfstate

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions infrastructure/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "state_passphrase" {
sensitive = true
}