Skip to content
Latchkey

How to Set Up CI for GitHub Flow

GitHub Flow has one rule: main is always deployable, and every change arrives via a reviewed pull request.

GitHub Flow branches off main, opens a PR, runs checks, merges, and deploys. CI runs the test suite on pull_request and a deploy job on push to main. There are no release or develop branches to manage.

Steps

  • Run tests on every pull_request targeting main.
  • Deploy from a push to main once the PR merges.
  • Gate the deploy job with if: github.ref == 'refs/heads/main'.
  • Require the test check to pass before merge via branch protection.

Workflow

.github/workflows/ci.yml
on:
  pull_request:
    branches: [main]
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test
  deploy:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - run: ./deploy.sh production

Gotchas

  • Every merge to main ships, so keep the deploy step reliable and fast to roll back.
  • GitHub Flow assumes one deploy target; multiple environments push you toward GitLab Flow.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →