Web Development

GitHub Actions for Beginners: CI/CD Pipeline Setup Step by Step (2027)

Minahil Rathor
Technical Content Writer
November 20, 2026
Blog Main Image

Table of Content

The modern software development process requires more than just writing code. It helps deliver a tested, reliable, and production-ready application. Developers also have to verify their code, fix bugs, and ensure that new changes will not affect the existing features.

Performing these tasks can be time-consuming and challenging because developers make updates constantly. This is where Continuous Integration and Continuous Delivery (CI/CD) come in.

The most important tool that developers use is GitHub Actions. It allows developers to deploy applications straight from GitHub repositories. In this article, you will learn every detail of GitHub Actions, workflows, and how to start building your CI/CD pipelines.  

What is GitHub Actions, And How Does CI/CD Work?

GitHub Actions CI/CD is an automated platform built into GitHub. It allows developers to automate the entire software development process.

These tasks can include:

  • Running the task when code is done
  • Building the application once changes are done
  • Checking the quality of code
  • Installing new project dependencies
  • Running security checks

At its core, GitHub Actions allows developers to create YAML files. It includes various steps such as installing dependencies, running tests, building artifacts, and deploying them. These tasks are initiated by specific GitHub events such as pull requests, pushes, releases, and manual execution.

Understanding the 5 Core Building Blocks

For proper understanding, it is important to learn its main blocks:

Term What it means Real example
Workflow One automated process, saved as a YAML file ci.yml that tests and deploys your app
Event
(trigger)
The thing that starts the workflow A push to main, a pull request, a schedule
Job A group of steps that run on one machine test, build, deploy
Step One single task inside a job npm test
Runner The machine that runs the job ubuntu-latest (GitHub's server) or your own server

An event starts a workflow. A workflow has one or more tasks. Each job runs on a runner and does its work in steps. Jobs run side by side by default. If one job must wait for another (deploy should wait for tests), you link them with needs:. We'll do that in Part 3.

What Makes It “CI/CD”?

GitHub Actions is considered a CI/CD solution when you utilize it to automate both processes, such as integration and delivery pipelines.

Continuous Integration (CI)

The main objective of CI is to validate the changes in code. With a GitHub Actions CI workflow, you can:

  • Run tests
  • Validate code
  • Install dependencies
  • New code doesn’t break the features

Example flow:

  • Developer creates a new pull request
  • Automatic workflow
  • Execution within a minute
  • Merge if it pass

This makes sure that your branch has production-ready code.  

Continuous Delivery (CD)

To extend CI, CD automates the release task. By using GitHub Actions CD pipelines, you can:

  • Generate Docker images
  • Push artifacts to Docker Hub
  • Deploy the app to staging or production
  • Trigger releases based on version tags

Example flow:

  • Code is merged into the master branch
  • Workflow builds a Docker image
  • Image is pushed to Docker Hub
  • Application is deployed to production

Requirements Before Building Your First CI/CD Pipeline

Before starting the process, make sure you have the following things with you:

1. A GitHub Account

First, you should have a GitHub account to create repositories and have proper access to Actions.

2. Git Installed on Your Computer

Install Git on your system to track changes, create branches, and manage source code.

3. A Code Editor

You can use Visual Studio Code or some other editor to manage and create files.  

4. Node.js and npm

For this beginner exercise, we will use a small JavaScript project.

Node.js lets JavaScript run outside the browser, while npm manages dependencies and scripts. Install it on your system.

GitHub Actions for Beginners

Have questions or need help putting this into practice? Our engineers can help you plan the right approach and get it done the right way. Let's talk on a quick call.

Part 1: Set up a Node.js project for GitHub Actions

Step 1: Create The Project

You’ll need a GitHub account, Git, and Node.js 24 with npm. Create an empty public repository for this exercise so you can use GitHub Pages on GitHub Free.

mkdir ci-cd-demo && cd ci-cd-demo
npm init -y
npm install --save-dev eslint @eslint/js

Your folder will end up looking like this:

ci-cd-demo/
├── .github/
│   └── workflows/
│       └── ci.yml
├── src/
│   ├── math.js
│   └── server.js
├── test/
│   └── math.test.js
├── Dockerfile
├── eslint.config.js
├── package.json
└── package-lock.json

Step 2: Write a Small App

// src/math.js — holds the logic we'll test
export function add(a, b) {
  return a + b;
}

// src/server.js — a tiny web server, so we have something to deploy later
import http from 'node:http';
import { add } from './math.js';

const port = process.env.PORT || 3000;

http.createServer((req, res) => {
  res.end(`2 + 3 = ${add(2, 3)}`);
}).listen(port, () => console.log(`Running on port ${port}`));

Step 3: Add a Test

Then use Node's built-in test runner, so there is no left in a plate to install. Create test/math.test.js:

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { add } from '../src/math.js';

test('adds two numbers', () => {
  assert.equal(add(2, 3), 5);
});

Step 4: Add a Linter

This test check the accuracy of your code and how cleaner it is. Create eslint.config.js:

import js from '@eslint/js';

export default [
  js.configs.recommended,
  {
    languageOptions: {
      globals: { process: 'readonly', console: 'readonly' },
    },
  },
];

Step 5: Wire it Up in package.json

This is an important step that most developers ignore, and it's why their npm test fails on the first try. Your package.json needs these lines:

{
  "name": "ci-cd-demo",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "start": "node src/server.js",
    "lint": "eslint .",
    "test": "node --test"
  }
}

Keep the devDependencies block that npm added for you. Run npm run lint and npm test on your computer. Both should pass before you go on.

Step 6: Push to GitHub

Create an empty repo on GitHub, then:

git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/YOUR-NAME/ci-cd-demo.git
git push -u origin main

Make sure package-lock.json is committed. The pipeline needs it, and forgetting it is the number one cause of a red build on day one.

Part 2: Your First Github Actions Workflow for Node.js

Step 7: Create the Workflow File

Create .github/workflows/ci.yml and paste this in:

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read   # The workflow can read code, nothing more

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v7

      - name: Set up Node.js
        uses: actions/setup-node@v7
        with:
          node-version: 26
          cache: npm   # Reuses downloaded packages between runs

      - name: Install dependencies
        run: npm ci   # Clean install from package-lock.json

      - name: Lint
        run: npm run lint

      - name: Run tests
        run: npm test

Here are two choices:

  • npm ci instead of npm install. npm ci installs exactly what's in your lock file. It is faster and will not change your dependencies behind your back.  
  • permissions: contents: read. By default the workflow's token can do more than it needs. This line limits it to reading code. It's one line, and it closes a whole class of security problems.

Step 8: Push and Watch it Run

git add .github/workflows/ci.yml
git commit -m "Add CI workflow"
git push

Open your repo on GitHub and click the Actions tab. You'll see your workflow running. Click on it, then on the test job, to watch each step live. After about 30 seconds you should see a green tick.

Step 9: Break It on Purpose

A pipeline is only useful if it catches mistakes. So let's make one. Create a branch and add a bug to src/math.js:

git checkout -b broken-math

export function add(a, b) {
  return a - b;   // Oops
}

Push the branch and open a pull request into main. Within a minute, the PR shows a red cross and a failed check.

[Screenshot: pull request with a failed "CI / test" check]

Click Details next to the failed check. Open the Run tests step and you'll see something like this:

✖ adds two numbers

  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

  -1 !== 5

Error: Process completed with exit code 1.

Part 3: Environment Variables, Secrets and Faster Builds

Your pipeline works. Now let's make it useful for a real project: settings that change per environment, passwords kept safe, and builds that don't waste your time.

GitHub Actions Environment Variables

GitHub Actions environment variables can be set at three levels. The closer to the step, the higher the priority.

env:            # 1. Workflow level: every job sees it
  NODE_ENV: test

jobs:
  test:
    runs-on: ubuntu-latest
    env:        # 2. Job level: only this job
      LOG_LEVEL: debug
    steps:
      - name: Print info
        env:    # 3. Step level: only this step
          GREETING: hello
        run: echo "$GREETING, commit $GITHUB_SHA on branch $GITHUB_REF_NAME"

Variables Vs Secrets: Which One to Use?

GitHub gives you two places to store settings outside your code. Both live in Settings → Secrets and variables → Actions.

Variables Secrets
Use for Non-sensitive settings: region, app name, URLs Passwords, API keys, tokens
Visible in logs? Yes No, GitHub masks them as ***
Can you read it after saving? Yes No, only update or delete
How to use in YAML ${{ vars.AWS_REGION }} ${{ secrets.API_KEY }}

Here's how you pass a secret to a step:

- name: Call an API
  env:
    API_KEY: ${{ secrets.API_KEY }}
  run: node scripts/notify.js

A simple rule: if it would hurt to see it in a screenshot, it's a secret. Never write a key straight into a workflow file, even in a private repo. Git history keeps it forever.

Run Tests on Several Node.Js Versions

If you publish a package, or you're planning a Node.js upgrade, test on more than one version. A matrix runs the same job several times in parallel:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false   # Let all versions finish, even if one fails
      matrix:
        node: [22, 24, 26]
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: ${{ matrix.node }}
          cache: npm

      - run: npm ci

      - run: npm test

This creates three jobs: test (22), test (24) and test (26). They run at the same time, so the whole thing takes about as long as one.

Caching: Stop Downloading the Internet Every Run

You already turned on caching with cache: npm in setup-node. On the first run, GitHub saves your npm download cache. On later runs, it restores it, as long as package-lock.json hasn't changed.

On a small app the saving is a few seconds. On a big app with hundreds of packages, it can save minutes on every single run. If you use pnpm or Yarn, change the value to pnpm or yarn.

Chain Jobs with Needs and Share Files with Artifacts

Real pipelines have stages. You don't want to build a Docker image if the tests failed. Use needs: to make one job wait for another:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo "testing..."

  build:
    needs: test   # Only starts if "test" passed
    runs-on: ubuntu-latest
    steps:
      - run: echo "building..."

Each job runs on a fresh machine, so files don't carry over between jobs. To pass a file (say, a test coverage report or a build folder) from one job to the next, use artifacts:

# In the first job
- uses: actions/upload-artifact@v7
  with:
    name: coverage
    path: coverage/

# In a later job
- uses: actions/download-artifact@v7
  with:
    name: coverage

Part 4: Github Actions Docker Build And Push

This is where most tutorials say "and now you can deploy!" and then stop. We won't. First, we package the app in a Docker image, so it runs the same way on every server.

Step 10: Add a Dockerfile

Create a Dockerfile in the root of your project:

FROM node:26-alpine
WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev

COPY src ./src
ENV PORT=3000
EXPOSE 3000

USER node
CMD ["node", "src/server.js"]

Copying package*.json first is a small trick. Docker caches each layer, so if only your code changed, it skips the slow npm ci step on the next build. USER node runs the app as a normal user instead of root, which is safer.

Push to Docker Hub

If you just want your image in a registry, Docker Hub is the quickest route. Add two secrets, DOCKERHUB_USERNAME and DOCKERHUB_TOKEN (an access token, not your password), then add this job:

docker:
  needs: test
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v7

    - uses: docker/setup-buildx-action@v4

    - uses: docker/login-action@v4
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}

    - uses: docker/build-push-action@v7
      with:
        push: true
        tags: ${{ secrets.DOCKERHUB_USERNAME }}/ci-cd-demo:${{ github.sha }}
        cache-from: type=gha
        cache-to: type=gha,mode=max

The cache-from and cache-to lines store Docker layers in GitHub's cache. Rebuilds that only change your code finish much faster.

Part 5: Github Actions Deploy to AWS

Now the fun part: getting your app live on AWS from GitHub Actions, with no passwords stored in GitHub at all.

We'll deploy to Amazon ECS (Elastic Container Service), which runs Docker containers for you. This guide assumes you already have an ECR repository and an ECS cluster and service. If you don't, the AWS console's "Get started" wizard for ECS sets them up in a few minutes. For production setups with load balancers, autoscaling and networking, that's where an AWS cloud setup partner or Terraform earns its keep.

Step 11: Connect GitHub to AWS with OIDC

The old way was to create an AWS access key and paste it into GitHub secrets. It works, but those keys never expire. If they leak, an attacker has your AWS account until someone notices.

The better way is OpenID Connect (OIDC). GitHub proves to AWS who it is, and AWS hands it a short-lived token that expires in about an hour. Nothing long-lived is stored anywhere.

Set it up once in AWS:

  1. In IAM → Identity providers, add an OpenID Connect provider:
    • Provider URL: https://token.actions.githubusercontent.com
    • Audience: sts.amazonaws.com
  2. In IAM → Roles, create a role called github-actions-deploy. Give it only the permissions it needs: push to your ECR repo and update your ECS service.
  3. Edit the role's trust policy so only your repo's production environment can use it:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
          "token.actions.githubusercontent.com:sub": "repo:YOUR-NAME/ci-cd-demo:environment:production"
        }
      }
    }
  ]
}

Step 12: Add a Production Environment with Approval

In your GitHub repo, go to Settings → Environments → New environment and name it production. Then:

  • Tick Required reviewers and add yourself (or your team lead).
  • Under Deployment branches, allow only main.
  • Add these environment variables: AWS_REGION, AWS_ROLE_ARN, ECR_REPOSITORY, ECS_CLUSTER, ECS_SERVICE.

Step 13: Add the Deploy Job

Add this job under your test job in ci.yml:

deploy:
  needs: test
  if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  runs-on: ubuntu-latest
  environment: production
  permissions:
    contents: read
    id-token: write   # Needed for OIDC
  steps:
    - uses: actions/checkout@v7

    - name: Log in to AWS
      uses: aws-actions/configure-aws-credentials@v6
      with:
        role-to-assume: ${{ vars.AWS_ROLE_ARN }}
        aws-region: ${{ vars.AWS_REGION }}

    - name: Log in to Amazon ECR
      id: ecr
      uses: aws-actions/amazon-ecr-login@v2

    - uses: docker/setup-buildx-action@v4

    - name: Build and push image
      uses: docker/build-push-action@v7
      with:
        push: true
        tags: |
          ${{ steps.ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
          ${{ steps.ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:latest
        cache-from: type=gha
        cache-to: type=gha,mode=max

    - name: Deploy to ECS
      run: |
        aws ecs update-service \
          --cluster ${{ vars.ECS_CLUSTER }} \
          --service ${{ vars.ECS_SERVICE }} \
          --force-new-deployment
        aws ecs wait services-stable \
          --cluster ${{ vars.ECS_CLUSTER }} \
          --services ${{ vars.ECS_SERVICE }}

GitHub Actions Pricing for Private Repos (2026)

GitHub Actions is free for public repos on standard GitHub-hosted runners. For private repos, every plan includes a monthly allowance, and you pay per minute after that.

GitHub plan Included minutes per month (private repos) Included artifact storage
Free 2,000 500 MB
Pro 3,000 1 GB
Team 3,000 2 GB
Enterprise Cloud 50,000 50 GB

After the allowance runs out, these are the per-minute rates for standard 2-core runners:

Runner Price per minute
Linux $0.006
Windows $0.010
macOS $0.062

Common Github Actions Errors and How to Fix Them

Every pipeline goes red sometimes. Here are the errors we see most often, with the message you'll actually see in the logs.

What you see Why it happens How to fix it
Invalid workflow file with a line number Bad YAML indentation, often a tab or a missing space Use 2 spaces per level. Paste the file into a YAML checker, or use the GitHub Actions extension in VS Code
The workflow never runs at all File is in the wrong folder, or the branch name doesn't match File must be in .github/workflows/. Check main vs master in your on: block
npm ci can only install packages when your package.json and package-lock.json are in sync Lock file missing or outdated Run npm install on your computer and commit package-lock.json
Error: Process completed with exit code 1. A command in that step failed Scroll up in the step's log. The real error is a few lines above this one
Missing script: "test" No test script in package.json Add "test": "node --test" (or your test runner) to scripts
Resource not accessible by integration The workflow token lacks a permission Add the needed permission to the job, such as pull-requests: write
Could not assume role with OIDC AWS trust policy doesn't match the repo, branch or environment Check the sub value in the trust policy and confirm id-token: write is set
A secret shows up empty PR comes from a fork, or the secret is stored in a different environment Fork PRs don't get secrets. Check the secret is in the repo or in the production environment
Job stuck on Waiting for a runner to pick up this job No runner matches the labels, or your self-hosted runner is offline Check the runs-on labels and the runner status under Settings → Actions → Runners

GitHub Actions vs Jenkins vs GitLab CI

If you're choosing a CI/CD tool, here's an honest, short comparison.

GitHub Actions Jenkins GitLab CI/CD
Setup Nothing to install; add a YAML file Install and run your own server Built in if your code is on GitLab
Hosting GitHub-hosted or self-hosted runners Self-hosted only GitLab-hosted or self-hosted runners
Config YAML in the repo Groovy (Jenkinsfile) or web UI YAML in the repo
Ecosystem Thousands of shared actions in the Marketplace Huge plugin library, some of it aging Strong built-in features, smaller sharing ecosystem
Best for Teams whose code already lives on GitHub Large, custom, on-premise setups Teams using GitLab end to end

Conclusion

You started with an empty folder. You now have a CI/CD pipeline with GitHub Actions that lints and tests every change on three Node.js versions, builds a Docker image, waits for your approval, and deploys to AWS without a single stored password.

That's more than a tutorial project. It's the same shape of pipeline we set up for client apps at Amrood Labs, just smaller.

Start with Part 2 if you're short on time. Even a simple test-on-every-push workflow will save you from your next Friday-evening incident. Add the rest as your project grows.

Want a hand setting this up for a real product, or fixing a pipeline that keeps going red? Our DevOps and cloud support team does this every week. Book a free call and tell us what you're building.

Frequently asked questions

What is a CI/CD pipeline in GitHub Actions?

It's a YAML workflow file in .github/workflows/ that runs automatic jobs, like tests, builds and deployments, whenever something happens in your repo. GitHub runs these jobs on its servers and reports a pass or fail for each one.

Is GitHub Actions free?

Yes for public repos on standard GitHub-hosted runners. Private repos get a monthly allowance (2,000 minutes on the Free plan, 3,000 on Pro and Team) and then pay per minute.

How do I learn GitHub Actions as a beginner?

Start with one small workflow that runs your tests on every push, like Part 2 of this guide. Once that's green, add one feature at a time: caching, a matrix, then deployment. Reading the logs of your own failed runs teaches you more than any course.

How do I trigger a GitHub Actions workflow on push?

Add on: push to your workflow file. To limit it to one branch, use on: push: branches: [main]. You can also add pull_request, schedule or workflow_dispatch for a manual button.

How do I deploy to AWS with GitHub Actions?

Connect GitHub to AWS with OIDC, use aws-actions/configure-aws-credentials to log in, push your Docker image to Amazon ECR, then update your ECS service. Part 5 of this guide has the full YAML.

How do I use environment variables in GitHub Actions?

Set them with env: at the workflow, job or step level. Store non-secret settings as repository variables (${{ vars.NAME }}) and sensitive values as secrets (${{ secrets.NAME }}).

How do I build and push a Docker image with GitHub Actions?

Use docker/login-action to sign in to your registry, then docker/build-push-action with push: true and your image tags. Add cache-from: type=gha to speed up rebuilds.

Join a fostering company which is big enough to support, small enough to care.

LET'S CHAT

Get in Touch

Copyright © 2026 Amrood Labs. All rights reserved.
Scroll to Top Icon