CI/CD using GitHub Actions

Gunnala SreekanthReddy3 min read

Why GitHub Actions for CI/CD?

GitHub Actions brings CI/CD directly into your repository — no external service, no context switching. Every push, pull request, or tag can trigger automated workflows that build, test, and deploy your application. For teams already on GitHub, it eliminates the overhead of maintaining Jenkins, CircleCI, or Travis CI as separate infrastructure.

Core concepts

Workflows are YAML files in .github/workflows/ that define automated processes. Each workflow contains one or more jobs, and each job runs on a fresh virtual machine (runner). Jobs can run in parallel or sequentially with dependencies.

Actions are reusable units — either from the GitHub Marketplace or custom-built. They handle common tasks like checking out code, setting up Node.js, caching dependencies, or deploying to AWS.

Setting up a basic CI pipeline

A minimal CI workflow for a Node.js project triggers on every push to main and on pull requests. It checks out the code, installs dependencies, runs linting, and executes tests:

The on block defines triggers. The jobs block defines what runs. Each step either uses a pre-built action (like actions/checkout@v4) or runs a shell command.

Caching for faster builds

Without caching, every workflow run downloads all dependencies from scratch. The actions/cache action stores node_modules between runs, keyed by the lockfile hash. This can cut CI time by 40-60% on dependency-heavy projects.

Adding deployment (CD)

Continuous deployment extends the pipeline to push artifacts to production after tests pass. Common patterns include deploying to AWS (S3, ECS, Lambda), Google Cloud Run, Vercel, or a self-hosted server via SSH.

For AWS deployments, use aws-actions/configure-aws-credentials to authenticate, then run your deploy commands. Store AWS keys as GitHub Secrets — never hardcode credentials in workflow files.

Environment protection rules

GitHub Environments add approval gates before deployment. You can require manual approval from specific reviewers, restrict which branches can deploy to production, and add wait timers. This prevents accidental deployments from feature branches.

Matrix builds for cross-platform testing

Matrix strategies run the same job across multiple configurations — different Node.js versions, operating systems, or database versions. This catches compatibility issues early without maintaining separate workflow files for each configuration.

Best practices

  • Pin action versions — use @v4 or a commit SHA, never @main. Unpinned actions are a supply chain risk.
  • Use secrets for credentials — never hardcode API keys, tokens, or passwords in YAML files.
  • Cache aggressively — dependencies, build artifacts, and Docker layers. Cache misses are the primary cause of slow CI.
  • Fail fast — run linting and type checks before expensive integration tests. Cancel in-progress runs on new pushes.
  • Keep workflows DRY — extract shared steps into reusable workflows or composite actions.
  • Monitor run times — GitHub Actions minutes are free for public repos but metered for private. Optimize long-running workflows.

Conclusion

GitHub Actions removes the friction between writing code and shipping it. For most teams, the combination of native GitHub integration, a rich marketplace of pre-built actions, and zero infrastructure overhead makes it the practical default for CI/CD in 2024 and beyond.

Ready to build something that matters?

We solve problems that don't have Stack Overflow answers. Let's talk.

Book a Discovery Call