GitHub Actions: Testing, Build, Release, and Deploy Pipelines

Practical CI/CD recipes for testing, build matrices, release creation, package publishing, and environment-based deployments in GitHub Actions.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Testing and build pipelines

Common patterns for CI on application repositories.

Node.js CI workflow

Install dependencies, lint, test, and build a Node project.

yamlANYnodecitestbuild
yaml
name: Node CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npm test -- --ci
      - run: npm run build
Notes

This is a solid baseline CI workflow for Node-based apps and libraries.

Python CI workflow

Set up Python, install dependencies, and run tests.

yamlANYpythonpytest
yaml
- uses: actions/setup-python@v5
  with:
    python-version: "3.12"

- run: pip install -r requirements.txt
- run: pytest -q
Notes

Language setup actions and minimal test commands make portable CI easy to maintain.

Build a Docker image

Use Buildx for modern Docker builds.

yamlANYdockerbuildximages
yaml
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
  with:
    context: .
    push: false
    tags: my-app:ci
Notes

This is a common building block for containerized apps and release pipelines.

Release and deployment workflows

Tag-based releases, package publishing, and deploy gating.

Create a GitHub release on tag push

Publish a release whenever a version tag is pushed.

yamlANYreleasetagsgithub-release
yaml
on:
  push:
    tags:
      - "v*"

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true
Notes

This pattern automates GitHub Releases for semantic version tags.

Publish an npm package

Publish to npm from GitHub Actions.

yamlANYnpmpublish
yaml
- uses: actions/setup-node@v4
  with:
    node-version: 20
    registry-url: https://registry.npmjs.org

- run: npm ci
- run: npm publish
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Notes

Keep package publishing in a protected branch or tag workflow with tightly scoped permissions.

Deploy only from main after tests

Gate deployments on successful CI from the main branch.

yamlANYdeploymainneeds
yaml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo "run tests here"

  deploy:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    steps:
      - run: ./scripts/deploy.sh
Notes

This pattern keeps deployment logic explicit and easy to reason about.

Recommended next

No recommendations yet.