Maven / GitHub Actions Interview Questions
How do you implement branch protection rules with required GitHub Actions status checks?
Branch protection rules enforce that certain GitHub Actions jobs must pass before a pull request can be merged into a protected branch. This creates a hard gate preventing broken code from landing on main.
Step 1 — Name your status check in the workflow. Each job name becomes a status check. Name jobs descriptively:
jobs:
unit-tests: # this becomes the status check name
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm test
lint:
runs-on: ubuntu-latest
steps:
- run: npm run lint
Step 2 — Configure the branch protection rule. In GitHub: repository Settings → Branches → Add rule → enter the branch name pattern (e.g. main). Then enable:
- ☑ Require status checks to pass before merging
- ☑ Require branches to be up to date before merging (prevents races)
- Search for and add the exact job names:
unit-testsandlint
Matrix builds create status checks with names like unit-tests (ubuntu-latest, 18) for each combination. You can require all matrix jobs or use a "summary" job pattern — a final job that declares needs: [unit-tests] and always reports success only if all matrix jobs passed — and require only that one summary check.
all-tests-pass:
if: always()
needs: [unit-tests, lint]
runs-on: ubuntu-latest
steps:
- name: Check all jobs
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
Requiring the summary job (all-tests-pass) in the branch protection rule gives you a single, stable required check regardless of how many matrix cells exist.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
