CI/CD Pipelines: Stages and Deployment Patterns/Multi-stage GitHub Actions workflow

Separate lint, test, build, and deploy into distinct jobs.

Section: Core stage patterns

Multi-stage GitHub Actions workflow

yaml
yaml
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

  build:
    needs: [lint, test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run build

  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/deploy.sh
Explanation

Split work into jobs so failures are obvious and deploys cannot proceed before verification passes.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Core stage patterns
GitLab stage ordering
Use explicit stages for predictable progression.
OpenIn sheetyamlsame section
Always archive reports and clean up
Preserve artifacts even when the pipeline fails.
OpenIn sheetgroovysame section
Staging then production promotion
Require staging verification before production deploy.
Manual production gate in GitLab
Add a human approval step before production deployment.
Blue/green deploy flow
Switch traffic after health checks pass on the new environment.