
Complete CI/CD pipeline automation starting with GitHub Actions
- DevOps, Development
- Exien
- · Updated
CI/CD replaces error-prone manual deployment with automated builds, tests, and releases, and GitHub Actions is one of the easiest ways to set it up because it runs directly inside your GitHub repository. A single YAML file in .github/workflows/ is enough to test every push automatically.
Why is manual deployment a problem?
"Okay, the coding is done! Let's connect to the server, run git pull, reinstall dependencies, build, kill the existing process, and launch a new one."
In the early stages of a project, this manual process may not be much of a hassle. But what if code needs to be integrated and deployed dozens of times a day as the service and team grow? Having a person test manually, connect to the server, and run scripts every time inevitably causes human error (mistakes) and keeps developers from focusing on development.
The practical methodology that solves these problems and automates the development cycle is CI/CD (Continuous Integration / Continuous Deployment), and one of the easiest and most powerful tools for building it is GitHub Actions.
What is CI/CD?
CI (Continuous Integration)
CI means regularly and frequently merging code written by multiple developers into a central repository (e.g. the main branch on GitHub). The key to successful CI is that automated builds and tests run whenever code is merged, immediately verifying that the new code does not break (regress) the existing system.
CD (Continuous Delivery/Deployment)
CD is the process of automatically releasing (deploying) code that has passed CI verification to the production environment (server) or a staging environment. Users can get the latest features developers push in near real time, without long waits.
Why use GitHub Actions for CI/CD?
In the past, building CI/CD meant linking separate external services such as Jenkins, Travis CI, or CircleCI and going through complicated server setup. GitHub Actions changed that significantly.
- Perfect integration: It runs directly within the GitHub repository where the code is stored, so no separate service sign-up or integration is needed.
- Event-based operation: Workflows can be triggered by almost any GitHub event, such as
push, opening apull request, merging a specific branch, or a schedule (Cron). - Various open source actions: Even without writing your own scripts, many tasks such as AWS connection, Docker builds, and Slack notifications are available as 'actions' in the GitHub Marketplace, so you can assemble them like blocks.
- Generous free quota: It is free without limits in public repositories, and private repositories also get a generous amount of execution time (2,000 minutes) free each month.
What are the key concepts of GitHub Actions?
There are four main components to know before writing a configuration file.
- Workflow: The entire automated process, written as a YAML file (
.yml) in the.github/workflows/directory. - Event: The trigger that runs the workflow. (e.g. when code is
pushedto themainbranch) - Job: An independent unit of work within a workflow. One workflow can have multiple Jobs, which run in parallel by default. (e.g.
test-job,deploy-job) - Step: An individual command executed sequentially within a Job. You can run a shell script (
run) or use an action someone else created (uses).
What does a Node.js CI workflow look like?
The ci.yml example below automatically installs npm packages and runs tests whenever code is pushed in a simple React or Node.js project.
# .github/workflows/ci.yml
name: Node.js CI
# When will it run? (Event)
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build-and-test:
# What environment (OS) will it run in?
runs-on: ubuntu-latest
steps:
# 1. Import the code from the current repository into the virtual environment. (Checkout)
- name: Checkout repository
uses: actions/checkout@v3
# 2. Set up the Node.js environment.
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm' # Speed up the next build through npm caching.
# 3. Install dependency packages
- name: Install dependencies
run: npm ci
# 4. Run Lint check and test
- name: Run lint and tests
run: |
npm run lint
npm run test
How do you run the workflow and what comes next?
Save the YAML above in .github/workflows/ at the project root, commit it, and push. On the 'Actions' tab of your GitHub repository, you can watch the workflow run and test your code in an Ubuntu virtual environment.
Once CI is in place, the next step is adding a deployment (CD) pipeline that ships the code to a server such as AWS EC2 or Vercel. With GitHub Actions, you can leave tedious, repetitive manual tasks behind and spend more time writing creative code!




















