πŸš€ A Complete Guide to CI/CD for Go Projects using GitHub Actions

🧠 What is CI/CD?

Setting up a solid CI/CD pipeline is one of the most impactful steps in delivering reliable software. If you’re working with Go (Golang) and deploying using Docker Compose, GitHub Actions offers a robust, free, and easy-to-use CI/CD platform.

In this blog, I’ll walk you through setting up a real-world CI pipeline for a Go project using my open-source project GoTaskify as an example.

🧠 Why CI/CD for Go?

With Go’s simplicity and GitHub Actions’ power, you can:

  • Automatically test code on every push or PR

  • Build and run Docker containers in CI

  • Measure test coverage and report to Codecov

  • Ensure a clean and repeatable deployment process

πŸ—‚οΈ Folder Structure for GitHub Actions

my-go-project/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml         # GitHub Actions Workflow
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ main.go
└── handler/
    └── task.go

πŸ› οΈ Writing Your First GitHub Actions CI Pipeline

name: GoTaskify CI

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

jobs:
  build-test:
    name: Build, Deploy, and Test
    runs-on: ubuntu-latest

    steps:
      - name: ⬇️ Checkout repository
        uses: actions/checkout@v3

      - name: πŸ— Set up Go 1.24.1
        uses: actions/setup-go@v5
        with:
          go-version: '1.24.1'

      - name: πŸ“₯ Install dependencies
        run: go mod tidy

      - name: 🐳 Install Docker Compose
        run: sudo apt-get update && sudo apt-get install -y docker-compose

      - name: 🐳 Build and deploy with Docker Compose
        run: docker-compose up --build -d

      - name: βœ… Run Go tests (unit/integration)
        run: go test ./test/...

      - name: πŸ§ͺ Run tests with coverage
        run: go test -coverprofile=coverage.out ./...

      - name: πŸ“€ Upload to Codecov
        uses: codecov/codecov-action@v5
        with:
          files: coverage.out
          fail_ci_if_error: true

      - name: 🧹 Shut down Docker
        run: docker-compose down

πŸ” Step-by-Step Breakdown

StepDescription
Checkout repositoryClones your code into the GitHub Actions runner
Set up GoInstalls Go version 1.24.1
Install dependenciesRuns go mod tidy to fetch and clean dependencies
Install Docker ComposeEnsures docker-compose is available for the job
Build and DeploySpins up your app and services using Docker Compose
Run Go TestsExecutes unit/integration tests inside /test/ directory
CoverageGenerates test coverage report
Upload to CodecovSends coverage report to Codecov for tracking
Shutdown DockerGracefully tears down containers post-test

In the GoTaskify project, this pipeline ensures that every pull request is tested, verified, and production-ready β€” all automatically.

πŸ™Œ About the Author

Sidharth Chauhan

Backend Developer | DevOps Learner

🌐 GitHub | πŸ’Ό LinkedIn

0
Subscribe to my newsletter

Read articles from Sidharth chauhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sidharth chauhan
Sidharth chauhan

🌟 Hello! I'm Sidharth Chauhan, a passionate DevOps Engineer dedicated to automating and optimizing processes to enhance software development and deployment. With expertise in Docker, Kubernetes, CI/CD, AWS, and more, I thrive in environments that leverage cutting-edge technologies and tools.I love sharing my knowledge and experiences through blogging, and I'm always eager to connect with like-minded professionals. Whether you're looking to collaborate on a project, need help with DevOps, or just want to chat about the latest tech trends, feel free to reach out!πŸ”— Connect with Me: