Skip to main content

Building a CI/CD pipeline with GitHub Actions

· 2 min read
Judith Lopez
CI/CD & Automation Engineer @ InSkillOps

A good CI/CD pipeline turns every git push into a tested, deploy-ready artifact. GitHub Actions lets you do this straight from your repository, with no server to manage.

Anatomy of a workflow

A workflow triggers on an event (push, pull request…) and runs jobs made of steps. Create .github/workflows/ci.yml:

name: CI

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm test

At this point, every push and pull request runs the tests automatically.

Adding build and publish

We chain a second job that builds the Docker image and publishes it, only on main:

  build-and-push:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest

Best practices

  • needs to chain jobs and only build if tests pass;
  • GitHub secrets rather than hardcoded values;
  • dependency caching to speed up runs;
  • short, readable workflows split by responsibility.

Towards GitOps

The next step is to have the published image deployed automatically by a tool like Argo CD or Flux, which syncs the cluster state with a Git repository. That's the heart of the GitOps approach, which we cover in our courses.