Skip to content

Commit 03f829b

Browse files
authored
ci: add repository rules as code (#60)
* chore: add terraform reposity rules * chore: apply terraform * chore: add GitHub Actions workflow for Terraform repository management * chore: add CODEOWNERS file and require code owner reviews for changes in Terraform repository * chore: update .gitignore to include Terraform files and Docker configuration * chore: remove Terraform state and backup files along with associated provider and module configurations * chore: update repository module to require branches to be up to date before merging, removing hardcoded check names
1 parent f040b99 commit 03f829b

6 files changed

Lines changed: 183 additions & 1 deletion

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/terraform/repository/ @wiktoriavh
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Terraform Repository
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- terraform/repository/**
8+
9+
concurrency:
10+
group: terraform-repository-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
apply:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: terraform/repository
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Terraform
25+
uses: hashicorp/setup-terraform@v3
26+
with:
27+
terraform_version: 1.5.0
28+
29+
- name: Terraform Init
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: terraform init
33+
34+
- name: Terraform Apply
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: terraform apply -auto-approve

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ guides-tracker.json
2525
advent-of-code-tracker.json
2626

2727
# Docker
28-
docker-compose.yml
28+
docker-compose.yml
29+
30+
# terraform
31+
**/.terraform/
32+
*.tfstate
33+
*.tfstate.*

terraform/repository/.terraform.lock.hcl

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/repository/main.tf

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
module "repository" {
2+
source = "git::https://github.com/r-webdev/terraform-module-github-repository.git//modules/service?ref=v1.0.0"
3+
4+
# Repository name on GitHub (must match the remote, e.g. r-webdev/website).
5+
name = "webdev-bot"
6+
7+
# Short summary shown on the repo homepage and in search results.
8+
description = "Discord communitybot for the Web Dev & Design Discord server."
9+
10+
# Link shown in the GitHub sidebar
11+
# homepage_url = "https://example.com"
12+
13+
# Who can see the repo: public, private, or internal (org members only).
14+
# Public is required on GitHub Free for branch protection rules to apply.
15+
visibility = "public"
16+
17+
# Tags used for discovery and filtering on GitHub.
18+
topics = ["discord", "bot"]
19+
20+
# Default branch for new PRs and clones; must already exist on GitHub before protection rules apply.
21+
default_branch = "main"
22+
23+
# --- Merge settings ---
24+
25+
# Disallow standard merge commits (only squash merges allowed).
26+
allow_merge_commit = false
27+
28+
# Allow squash merges — combines all commits into one on merge.
29+
allow_squash_merge = true
30+
31+
# Disallow rebase merges onto the base branch.
32+
allow_rebase_merge = false
33+
34+
# Use the PR title as the squash commit subject line.
35+
squash_merge_commit_title = "PR_TITLE"
36+
37+
# Include individual commit messages in the squash commit body.
38+
squash_merge_commit_message = "COMMIT_MESSAGES"
39+
40+
# Remove the feature branch from GitHub after the PR is merged.
41+
delete_branch_on_merge = true
42+
43+
# Do not allow merging automatically once checks and reviews pass (manual merge required).
44+
allow_auto_merge = false
45+
46+
# --- Repository features ---
47+
48+
# Enable GitHub Issues for bugs and feature requests.
49+
has_issues = true
50+
51+
# Disable GitHub Projects (Kanban-style boards tied to the repo).
52+
has_projects = false
53+
54+
# Disable the repo wiki.
55+
has_wiki = false
56+
57+
# Disable GitHub Discussions.
58+
has_discussions = false
59+
60+
# Send Dependabot security alerts for vulnerable dependencies (relevant for private repos).
61+
vulnerability_alerts = true
62+
63+
# If Terraform destroys this resource, archive the repo instead of deleting it permanently.
64+
archive_on_destroy = true
65+
66+
# --- Access control ---
67+
68+
# Map of org team slug → permission level (pull, triage, push, maintain, admin).
69+
team_permissions = {
70+
# Full admin access: settings, branch protection, team management.
71+
admins = "admin"
72+
# Write access: push to branches and open/merge PRs (subject to branch protection).
73+
moderators = "push"
74+
}
75+
76+
# --- Branch protection (main) ---
77+
78+
branch_protection = {
79+
main = {
80+
# Require all conversations on a PR to be resolved before merge.
81+
required_conversation_resolution = true
82+
83+
# Pull request review requirements before merge.
84+
required_pull_request_reviews = {
85+
# New commits dismiss previous approvals so reviewers re-check changes.
86+
dismiss_stale_reviews = true
87+
# Require approval from CODEOWNERS when changed files match .github/CODEOWNERS.
88+
require_code_owner_reviews = true
89+
# At least one approving review from someone other than the author.
90+
required_approving_review_count = 1
91+
}
92+
93+
# Require branches to be up to date before merging; no hardcoded check names.
94+
required_status_checks = {
95+
strict = true
96+
}
97+
}
98+
}
99+
}

terraform/repository/versions.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
# Minimum Terraform version required by the GitHub repository module.
3+
required_version = ">= 1.5.0"
4+
5+
required_providers {
6+
github = {
7+
source = "integrations/github"
8+
version = "~> 6.0"
9+
}
10+
}
11+
}
12+
13+
provider "github" {
14+
# GitHub organization that owns this repository.
15+
owner = "r-webdev"
16+
}

0 commit comments

Comments
 (0)