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

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:
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.
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.
Your folder will end up looking like this:
Step 2: Write a Small App
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:
Step 4: Add a Linter
This test check the accuracy of your code and how cleaner it is. Create eslint.config.js:
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:
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:
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:
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
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:
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.
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.
Here's how you pass a secret to a step:
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:
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:
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:
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:
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:
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:
- In IAM → Identity providers, add an OpenID Connect provider:
- Provider URL: https://token.actions.githubusercontent.com
- Audience: sts.amazonaws.com
- 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.
- Edit the role's trust policy so only your repo's production environment can use it:
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:
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.
After the allowance runs out, these are the per-minute rates for standard 2-core runners:
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.
GitHub Actions vs Jenkins vs GitLab CI
If you're choosing a CI/CD tool, here's an honest, short comparison.
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.


.png)






.png)
.png)
