Every push to your main branch should end the same way: tests run, the code builds, and the new version ships without anyone touching a server. This guide shows you how to build a CI/CD pipeline with GitHub Actions in 2026, using a realistic Node.js project as the example. You will write one workflow file that lints the code, runs the test suite, builds a Docker image, and deploys it through staging to production with a manual approval gate. You do not need prior DevOps experience, just a GitHub repository and a project with tests.
What a CI/CD Pipeline Actually Does
CI, continuous integration, means every change gets merged often and checked automatically. Each pull request triggers the same set of checks, so broken code gets caught before it reaches the main branch. CD covers two related ideas: continuous delivery, where every passing build is ready to deploy, and continuous deployment, where passing builds deploy on their own. A pipeline strings these stages together: lint, test, build, then deploy. When one stage fails, the pipeline stops and tells you exactly where, which beats discovering the problem from an angry user. The platform matters as well: Jenkins, GitLab CI, and GitHub Actions each model these stages differently, with different costs and maintenance burdens.
Anatomy of a CI/CD Pipeline with GitHub Actions
GitHub Actions runs your pipeline on hosted runners, virtual machines that GitHub provides. A workflow is a YAML file in .github/workflows/ that describes the whole pipeline. Inside it, jobs are units of work that run on a runner, and each job contains steps, individual commands or reusable actions. Workflows start on events: pushes, pull requests, schedules, or manual triggers. Jobs can depend on each other with needs, so the deploy job only runs after the test job passes. This small vocabulary, workflows, jobs, steps, and events, covers almost everything you will ever configure.
The Complete Workflow File
This CI/CD pipeline tutorial assumes a Node.js app with a Dockerfile at the repo root. The GitHub Actions workflow YAML below does four jobs: test, build, deploy to staging, and deploy to production. Read it top to bottom once before copying it, then adapt the commands to your own stack.
name: CI/CD
on:
push:
branches: [main]
pull_request:
env:
NODE_VERSION: "22"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test -- --coverage
build:
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v5
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
deploy-staging:
needs: build
runs-on: ubuntu-latest
environment: staging
steps:
- run: |
echo "Deploying ${{ github.sha }} to staging"
# call your staging deploy script or API here
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment: production
steps:
- run: |
echo "Deploying ${{ github.sha }} to production"
# call your production deploy script or API here
What Each Job Does
The test job runs on every push and pull request. It installs dependencies with npm ci, runs the linter, then the test suite with coverage. The build job only runs on pushes to main, after tests pass, and pushes a Docker image to the GitHub Container Registry tagged with the commit SHA. The two deploy jobs reference named environments, staging and production, which you create in the repository settings. The production environment can require a manual approval, so nothing ships to real users without a human saying yes.
Caching and Matrix Builds
Dependency installation is usually the slowest part of a pipeline. The setup-node action caches node_modules automatically when you pass cache: npm, so repeat runs skip the download. If you support several Node versions, a matrix strategy runs the test job once per version in parallel. One caution: cache only what is deterministic. Caching build artifacts across branches can hide real failures, so keep caches scoped to lockfiles and dependency folders.
Add Tests, Linting, and Security Scans
A pipeline is only as trustworthy as its checks. Keep three layers. First, the linter enforces style and catches obvious mistakes. Second, the test suite verifies behavior; if you have no tests yet, start with a smoke test that boots the app and hits the health endpoint. Third, add a dependency scan. A step running npm audit --audit-level=high fails the build when a known high-severity vulnerability appears in your dependencies. For a fuller picture, enable Dependabot alerts and code scanning in the repository security settings, which run outside the workflow but feed the same goal: nothing known-bad reaches production.
Deploy Safely with Environments and Secrets
Secrets never belong in the workflow file. Store tokens and API keys as environment secrets in the repository settings, then reference them as ${{ secrets.NAME }}. Environments add a second layer: you can require specific reviewers before the production job runs, and restrict which branches may deploy there. A common setup deploys every green main-branch build to staging automatically, then waits for one approval before production. That approval gate is what turns a script into an automated deployment pipeline you can trust on a Friday afternoon.
Keep the Pipeline Fast and Healthy
Slow pipelines get ignored, so protect the feedback loop. Use concurrency groups to cancel outdated runs when a branch gets new pushes; there is no point testing a commit that has already been replaced. Limit expensive jobs with path filters so docs-only changes skip the Docker build. Pin third-party actions to full commit SHAs or at least major versions, because a surprise update to an action can break every repo that uses it. Finally, watch the Actions tab for a week after launch and delete steps that never catch anything; a lean pipeline is easier to debug than a thorough one.
Frequently Asked Questions
How much does GitHub Actions cost?
GitHub includes a monthly allowance of Actions minutes on every plan, and public repositories get generous free usage. Private repositories draw from the allowance based on the runner type. Check the official GitHub pricing page for current limits, since these change over time.
Does this work for projects that are not Node.js?
Yes. Replace the setup and test steps with the equivalent for your stack: setup-python, setup-java, setup-go, and so on. The structure, test, build, staged deploy, stays the same. Projects without Docker can deploy with rsync, SSH, or a platform-specific action instead.
How do I roll back a bad deploy?
Tag every image with the commit SHA and keep older tags around. Rolling back means redeploying the previous known-good SHA through the same production job, which keeps the process identical to a normal release instead of a panicked manual fix.
Do I need Docker at all?
No. Docker makes the build artifact portable, but the pipeline pattern works fine if you deploy code directly. Swap the build job for one that uploads a zip or runs your platform’s deploy command.
Start with the test job on your own repository today. Once green builds feel routine, add the build and staging jobs, then the production gate. A pipeline you trust changes how you work: smaller commits, faster reviews, and releases that stop feeling like events. That is the whole point of a CI/CD pipeline with GitHub Actions, boring deploys, every time.