Introduction
GitHub Actions is the CI/CD tool most DevOps engineers meet first in 2026, and for good reason: it lives inside GitHub, where the code already is, it is configured in YAML files stored in the repository, and it is free for public repositories and for a generous monthly allowance on private ones. This tutorial builds a real pipeline from scratch — one that tests a Node.js application, builds a Docker image and pushes it to a registry — and explains each concept as it appears, so you can adapt the example to your own stack.
You need a GitHub account and a repository with some code in it. The examples use Node.js, but the structure — triggers, jobs, steps, secrets — is identical for Python, Go, Java or any other language. If you have not containerised an application yet, read our Docker Tutorial for Beginners first; this tutorial builds on it.
Pricing note (26 Nov 2026, re-check at publication): standard GitHub-hosted runners are free on public repositories. On private repositories each account gets a monthly allowance of included compute — $12 on GitHub Free, $18 on Pro and Team, $300 on Enterprise Cloud — after which usage is billed per minute ($0.006 for a standard Linux runner, $0.010 for Windows, $0.062 for macOS). Since 28 October 2026 GitHub expresses that allowance as a dollar amount rather than a minute count, so a $12 allowance is roughly 2,000 standard Linux minutes. Self-hosted runners carry no GitHub per-minute charge, though you still pay for the machine underneath them.
How GitHub Actions Works
Four concepts explain everything:
- Workflow — an automated process, defined by a YAML file in
.github/workflows/. One repository can have many workflows: one for tests, one for deployment, one for scheduled jobs. - Event (trigger) — what starts a workflow: a push, a pull request, a schedule, a manual button, or a release being published.
- Job — a set of steps that run on the same runner (a virtual machine). Jobs run in parallel by default; you make one job depend on another with
needs. - Step — a single task inside a job: either a shell command (
run:) or a reusable action (uses:), such as checking out the code or setting up Node.js. - Runner — the machine a job runs on. GitHub-hosted runners are fresh virtual machines (Ubuntu, Windows or macOS) that are discarded after the job; self-hosted runners are machines you provide.
A workflow file is just YAML, and it lives in your repository, so it is versioned, reviewed in pull requests and visible to the whole team. That is the single biggest advantage over a CI server configured by clicking in a web interface.
Your First Workflow: Test on Every Push
Create .github/workflows/ci.yml in your repository:
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Lint
run: npm run lint
Commit and push. Open the Actions tab in GitHub and watch the run: each step gets a green tick or a red cross, and clicking a step shows its log. Break a test deliberately and push again — seeing a pipeline fail is the fastest way to trust it when it passes.
A few details worth understanding now:
runs-on: ubuntu-latestpicks the newest Ubuntu runner. It is convenient and it moves over time — pinning a specific version (ubuntu-24.04) is safer for a pipeline that must behave identically for months, at the cost of manual upgrades.actions/checkout@v4andactions/setup-node@v4are versioned actions from GitHub’s official marketplace. Pin actions to a major version (@v4), not to a branch, so an upstream change cannot silently alter your pipeline.cache: npmcaches dependencies between runs, which is often the difference between a 30-second pipeline and a 3-minute one.npm ciinstalls exactly whatpackage-lock.jsonspecifies, instead ofnpm install, which can resolve new versions. In CI, reproducibility beats convenience.
Adding a Build Job and a Docker Push
A test job is only half a pipeline. The next step is to build a Docker image and push it to GitHub Container Registry (GHCR), so the tested code becomes a deployable artifact. Add a second job that depends on the test job:
build-and-push:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
needs: test means this job only runs if the tests pass — a failed test never produces an image. GITHUB_TOKEN is a token GitHub creates automatically for each run; you never need to create or store it. The permissions block follows the principle of least privilege: this job can read the repository and write packages, and nothing else.
One warning about the tag above: :latest is convenient for a tutorial and dangerous in production, for the same reason it is dangerous in Docker generally — it moves. Tag images with the commit SHA (ghcr.io/owner/repo:${{ github.sha }}) so every deployment refers to an exact, immutable image, and add a :latest tag only as a convenience alias.
Secrets, Environments and Deploying Safely
Real pipelines need credentials: a cloud provider’s key, a registry password, an API token. GitHub stores them as secrets — encrypted values that are injected into a run as environment variables and are never printed in logs (GitHub masks them if they leak into output). Add one under Settings → Secrets and variables → Actions, then use it:
- name: Deploy to staging
run: ./deploy.sh
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
Two practices separate a hobby pipeline from a production one:
- Environments. Define an environment (for example
production) under Settings → Environments, and require a manual approval before a deployment job can run against it. The workflow then saysenvironment: production, and a human must approve before anything is deployed. This is the cheapest insurance in DevOps. - Never log a secret. GitHub masks known secrets in logs, but a secret transformed — base64-encoded, split across lines — can slip through. Treat secrets as write-only: use them, never print them.
Add a deploy job guarded by both needs and an environment:
deploy:
needs: build-and-push
runs-on: ubuntu-latest
environment: production
steps:
- name: Deploy image
run: echo "Deploying ghcr.io/${{ github.repository }}:${{ github.sha }}"
Replace the echo with your real deployment step — a kubectl apply, a Terraform apply, or a call to your platform’s API. The structure is the same either way.
Reusable Workflows, Matrices and Caching
Three features make larger pipelines manageable:
Matrices run the same job against several versions at once — the standard way to test against multiple Node.js or Python versions:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["20", "22"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
Caching is not just for dependencies. Cache Docker layers between runs with the cache-from / cache-to options of docker/build-push-action, and cache tool installations, so a pipeline that builds an image does not download the world on every commit.
Reusable workflows let one repository’s workflow call another’s (uses: org/repo/.github/workflows/deploy.yml@main), so every service in an organisation shares one reviewed deployment process instead of each team copying YAML. Start with a single workflow; extract a reusable one when you find yourself copying the same file into a third repository.
Common Beginner Mistakes
- Running everything in one job. Split test, build and deploy into separate jobs with
needs, so a failure is easy to locate and a failed test never ships an image. - No pinning. Unpinned runner versions, action versions and dependencies make a pipeline that passes today and fails next month for no reason you can see.
- Secrets in code. If a credential appears in a workflow file, a log or a repository, rotate it immediately — do not just delete the line. Git history keeps it.
- No concurrency control. Two pushes in quick succession can start two deployments that race each other. Add a
concurrencygroup so a new run cancels or queues behind the old one. - Ignoring the bill. A matrix of five versions across three operating systems is fifteen runner-minutes per push. On private repositories that spend comes out of your monthly allowance; keep matrices small and cache aggressively.
- Deploying from a pull request. A workflow triggered by
pull_requestruns code from a fork. Keep deployment jobs onpushto protected branches or on manual triggers only, and never give a pull-request workflow write access to production.
GitHub Actions vs Jenkins
Jenkins is still common in large and older organisations, and the concepts transfer directly: pipelines, stages, agents, triggers. The differences are practical. GitHub Actions needs no server to maintain — runners are provided — and its configuration lives in the repository. Jenkins needs a controller and agents that you patch, back up and secure, but it runs anywhere, including fully on-premises networks, and its plugin ecosystem is enormous. Learn GitHub Actions first in 2026; learn Jenkins’ concepts (pipelines, agents, stages) afterwards, because many employers still run it. Our DevOps Engineer Roadmap 2026 places GitHub Actions first for the same reason. If you are preparing for interviews, work through the DevOps Interview Questions and Answers for 2026.
Frequently Asked Questions
Is GitHub Actions free? For public repositories with standard runners, yes. For private repositories, each account gets a monthly allowance of included compute ($12 on Free, $18 on Pro/Team, $300 on Enterprise Cloud, as of late 2026), then pays per minute. Self-hosted runners carry no GitHub charge.
What is the difference between a workflow, a job and a step? A workflow is a YAML file describing an automated process; a job is a set of steps running on one runner; a step is one command or action inside a job. Jobs run in parallel unless linked with needs.
How do I run a workflow manually? Add workflow_dispatch: to the on: triggers. A “Run workflow” button then appears in the Actions tab, and you can add inputs (such as an environment name) that the workflow reads.
Can GitHub Actions deploy to AWS, Azure or GCP? Yes — by using the cloud provider’s official login action and the credentials stored as GitHub secrets, typically via OpenID Connect (OIDC) so no long-lived cloud key is stored in GitHub at all. OIDC is the recommended setup for production.
Why did my workflow not run? The usual causes are: the YAML file is not on the default branch (workflows only run from the default branch for scheduled and manual triggers), the on: trigger does not match the event, or a YAML syntax error — GitHub shows a warning on the Actions tab when a workflow file is invalid.
Conclusion
A GitHub Actions pipeline is a YAML file, a trigger, jobs that depend on each other, and secrets handled with care. Build the test workflow in this tutorial, add the Docker build job, and gate deployment behind an environment approval — and you have a pipeline that looks like the ones running in production teams. From here, the natural next steps are Terraform for the infrastructure the pipeline deploys to, covered in our Terraform Interview Questions and Answers, and Kubernetes for running the image it produces.
Try it today: create a repository, add the CI workflow above, push a commit, watch it run in the Actions tab, then break a test on purpose and watch the pipeline stop the build job from running.
