Bashbashgithub-actionsci-cdautomationproduction-ready

GitHub Actions Matrix CI

A reusable GitHub Actions workflow with matrix builds, caching, conditional jobs, artifact handling, and deployment gates.


title: "GitHub Actions Matrix CI" description: "A reusable GitHub Actions workflow with matrix builds, caching, conditional jobs, artifact handling, and deployment gates." category: "Bash" language: "yaml" tags: ["bash", "github-actions", "ci-cd", "automation", "production-ready"] createdAt: "2025-03-05" updatedAt: "2025-03-25"

Overview

A complete GitHub Actions CI/CD pipeline with matrix testing across Node versions and operating systems, Docker image building with layer caching, and staged deployments with environment protection rules.

Code

strategy:
  matrix:
    node-version: [18, 20, 22]
    os: [ubuntu-latest, macos-latest]

Notes

  • fail-fast: false ensures all matrix combinations run even if one fails
  • include adds specific combinations without generating all permutations
  • GitHub's type=gha cache uses GitHub Actions cache for Docker layer reuse
  • Environment protection rules on production enable manual approval gates
  • Conditional jobs (if: github.ref == 'refs/heads/main') prevent premature deployments
  • Artifact upload preserves coverage reports for PR review