DEV Community

flowerinthenight
flowerinthenight

Posted on

An example of a Golang-based monorepo

Planning to use a monorepo to structure your Go codes but not quite keen on the complexity of Bazel? You might want to check out:

GitHub logo flowerinthenight / golang-monorepo

An example of a golang-based monorepo.

GitHub Actions CircleCI
Main CircleCI

Overview

This is an example of a golang-based monorepo. It has the following features:

  • Only build the services or cmds that are modified in a commit;
  • Build all services and/or cmds that are affected by changes in common codes (i.e. pkg);
  • Build all services and/or cmds that are affected by changes in vendor codes.

For now, CircleCI 2.1 and GitHub Actions are supported. But since it uses bash scripts and Makefiles, it should be fairly straightforward to port to TravisCI or AppVeyor, etc.

At the moment, CI is setup with GO111MODULE=on and GOFLAGS=-mod=vendor environment variables enabled during build. See sample dockerfile for more details.

How does it work

During CI builds, build.sh iterates the updated files within the commit range (CIRCLE_COMPARE_URL environment variable in CircleCI) or the modified files within a single commit (when the value is not a valid range), excluding hidden files…

It uses Bash scripts, Makefiles, and the go tools to determine what binaries to build based on commit changes. You might find this useful.

Top comments (0)