This document describes how to configure branch protection rules in GitHub to enforce testing requirements and code review before merging pull requests.
Branch protection rules ensure that:
- All tests pass before code can be merged
- At least one code review approval is obtained
- Code quality standards are maintained
The .github/workflows/pr-tests.yml workflow automatically:
- ✅ Runs unit tests on every PR commit
- ✅ Runs E2E tests on every PR commit
- ✅ Reports results as status checks
- ✅ Cancels outdated test runs when new commits are pushed
GitHub branch protection rules must be configured manually in the repository settings. Follow these steps:
- Go to your repository on GitHub
- Click Settings → Branches
- Under "Branch protection rules", click Add rule
- In "Branch name pattern", enter:
main
Enable the following options:
- ✅ Require a pull request before merging
- ✅ Require approvals: Set to 1 (at least one approval required)
- ✅ Dismiss stale pull request approvals when new commits are pushed
- ✅ Require review from Code Owners (optional, if you have a CODEOWNERS file)
- ✅ Require status checks to pass before merging
- ✅ Require branches to be up to date before merging
- Add required status checks:
- ✅
Unit Tests(from pr-tests.yml workflow) - ✅
E2E Tests(from pr-tests.yml workflow)
- ✅
- ✅ Require conversation resolution before merging
- ✅ Do not allow bypassing the above settings
⚠️ Allow force pushes: Leave disabled (recommended)⚠️ Allow deletions: Leave disabled (recommended)
Click Create or Save changes at the bottom of the page.
After configuration, test the protection rules:
- Create a test branch and make a change
- Open a pull request to
main - Verify that:
- ✅ Tests run automatically
- ✅ Status checks appear on the PR
- ✅ "Merge" button is blocked until tests pass
- ✅ "Merge" button is blocked until approval is given
- ✅ After approval and passing tests, merge is allowed
- Job Name:
Unit Tests - Runs: Vitest test suite
- Duration: ~30-60 seconds
- When it fails: Component or utility function tests failed
- How to debug: Check workflow logs for test output
- Job Name:
E2E Tests - Runs: Playwright browser tests
- Duration: ~2-5 minutes
- When it fails: Critical user workflows are broken
- How to debug: Download Playwright report artifact from failed workflow
The PR tests workflow runs when:
- A pull request is opened
- New commits are pushed to the PR branch
- A pull request is reopened
The workflow does NOT run on:
- Draft pull requests (they run like normal PRs)
- Commits directly to
main(protected by branch rules) - Pushes to other branches without PRs
- Verify the workflow file exists:
.github/workflows/pr-tests.yml - Check that the PR targets the
mainbranch - Ensure GitHub Actions are enabled in repository settings
- Check if approval requirement is met (at least 1 approval)
- Verify all required status checks are green
- Ensure branch is up to date with
main
- Check for environment-specific issues
- Verify all dependencies are correctly specified in
package.json - Review workflow logs for specific error messages
- Verify
cancel-in-progress: trueis set in the workflow - Check that the concurrency group is correctly configured
To update branch protection rules:
- Go to Settings → Branches
- Click Edit next to the
mainbranch rule - Make your changes
- Click Save changes
To temporarily disable (not recommended):
- Go to Settings → Branches
- Click Edit next to the
mainbranch rule - Uncheck the settings you want to disable
- Click Save changes
To permanently delete:
- Go to Settings → Branches
- Click Delete next to the
mainbranch rule - Confirm deletion