Search code examples
semantic-versioninggo-modules

Golang: separate versioning of multiple modules


Imagine I have a repo github.com/user/golang-examples and I provision to version each example module within it separately:

guthub.com/user/golang-examples
  /modA
    /go.mod
    /pkgA1
    /pkgA2

  /modB
    /go.mod
    /pkgB1
    /pkgB2

(I know the idiom is “one repo - one module” but there are usecases for multimodule projects, too, so this is not the subject of the discussion)

At the same time, semantic git tagging (v1.0.0, v2.0.0 etc.) happens on the level of repo, not its subfolders. This makes it impossible to tag modules separately, for example

  1. First, modA overtakes modB in development by major version, and tag v2.0.0 is pushed at the repo level, with intent to version modA
  2. Later, when one wants to upgrade modB to v2, one can’t push the same v2.0.0 git tag for the second time to version modB.

How can this task be accomplished in line with golang’s versioning paradigm? Again, this is about multi-module project. Obvious solution to split modules into repos is kind of unfavourable here because the overarching “examples” semantics of the top repo is desired.

Thanks!


Solution

  • Ok, after a continued search I found this resource: https://github.com/go-modules-by-example/index/blob/master/009_submodules/README.md

    Applied to my situation, the answer is to use:

    • for module modA use tags of the form modA/vX.Y.Z (using semantic versioning)
    • for module modB use tags of the form modB/vX.Y.Z

    For the context, the citation from the above lint:

    The official modules proposal predicts that most projects will follow the simplest approach of using a single Go module per repository, which typically means creating one go.mod file located in the root directory of a repository.

    For some reason, I still cannot find a correct docs/specs reference.