Design a repository ruleset: protections, required checks, and exceptions.
- User
Design a repository ruleset: protections, required checks, and exceptions.
- Assistant
Repository Ruleset Design
This ruleset is designed for a standard software repository (e.g., on GitHub) following GitOps best practices. It enforces security, quality, and collaboration standards while allowing flexibility for emergencies.
The ruleset targets key branches:
main,develop, andrelease/*. It uses GitHub's Rulesets feature (repository > Settings > Rules > Rulesets) for enforcement.1. Ruleset Overview
Property Value Name core-protectionsEnforcement Active Target Branch: main,develop,release/*Creation Individual ruleset (not template) Bypass Actors See Exceptions section 2. Protections (Branch Protection Rules)
These rules prevent direct pushes, enforce PR workflows, and ensure code quality.
Protection Enabled Configuration Applies To Require a pull request before merging Yes - Base branch must match target- Dismiss stale reviews on push All targets Require approvals Yes - Minimum 2 approvals- From code owners (if CODEOWNERSfile exists)- Dismiss on new commitsAll targets Require status checks to pass before merging Yes See "Required Checks" section below All targets Require conversation resolution before merging Yes All PR comments must be resolved All targets Require linear history Yes Merge method: Rebase and merge (no squash/merge commits) All targets Require signed commits Yes GPG or SSH signed commits only All targets Restrict who can push to matching branches Yes - Only via PRs- Admins cannot push directly (except bypass) All targets Restrict pushes that modify force pushes Yes Block history rewrites All targets Require review from Code Owners Yes If CODEOWNERSfile is presentAll targets Do not allow bypassing the above settings Yes Locked for non-bypass actors All targets 3. Required Checks (Status Checks)
These CI/CD checks must pass before merging. Configure your workflows (e.g., GitHub Actions) to report these exact check names.
Check Name Description Required Rationale lintCode linting (e.g., ESLint, Prettier) Always Enforce style consistency test-unitUnit tests (e.g., Jest, pytest) Always Core functionality test-integrationIntegration/E2E tests Always System behavior buildBuild artifact generation Always Compilation/deployability security-scanSAST/Dependency scan (e.g., CodeQL, Snyk) Always Vulnerability detection coverageTest coverage threshold (>80%) Always Code quality metric docker-buildContainer build & scan (if applicable) On main,release/*Deployment readiness deploy-previewPreview deployment (e.g., Vercel/Netlify) On developEarly feedback Setup Tip: In GitHub Actions, use
needs: [lint, test-unit, ...]and setpermissions: { checks: write }to post statuses.4. Exceptions (Bypasses and Relaxed Rules)
Exceptions allow critical paths (e.g., hotfixes) without full ceremony, but log all bypasses for audit.
Bypass Permissions (Actors who can bypass rules)
Actor Type Permissions Who Use Case Apps Bypass all protections dependabot[bot],release-please[bot]Automated dependency updates/releases Teams Bypass required checks & reviews @org/security-teamEmergency security patches Users Bypass required checks only @org/admins(specific users)Hotfixes on release/*Existing Pull Requests None N/A Legacy PRs unaffected Branch-Specific Relaxations
Branch Pattern Relaxed Rules Conditions hotfix/*1 approval requiredRequired checks: lint,test-unit,security-scanonlyLabel: hotfix+ Bypass actorrelease/*1 approval from release manager Required checks include docker-builddevelopOptional: 1 approval Full checks for faster iteration Emergency Override
- Admin Webhook: Create a GitHub App or Action that allows
org:writeadmins to add abypass-approvedlabel (expires in 24h). - Audit Logging: All bypasses trigger a Slack/Teams notification with PR link and actor.
Implementation Steps
- GitHub Setup:
- Go to Repo > Settings > Rules > New ruleset.
- Paste the above config (GitHub UI mirrors this).
- CODEOWNERS File: Add
.github/CODEOWNERSfor auto-review assignments. - Actions Workflows: Ensure
.github/workflows/posts the exact check names. - Test: Create a test PR to
mainand verify enforcement. - Monitor: Use GitHub Insights > Rules for compliance reports.
This ruleset balances security (e.g., signed commits, scans) with developer velocity. Customize check names based on your stack (e.g., add
terraform-planfor IaC). For multi-repo, convert to an organization ruleset template.Questions? Provide your tech stack for refinements!
- Admin Webhook: Create a GitHub App or Action that allows
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.