Publishing go module in a monorepo envirnoment

Viewed 1321

Suppose I have a monorepo and there are several individual golang services:

root    
└── services
        ├── svc1
        │   ├── go.mod
        │   ├── go.sum
        │   └── main.go
        └── svc2
            ├── go.mod
            ├── go.sum
            └── main.go

Whereas svc2 will depend on svc1 in the future. Also, it is a requirement that svc1 and svc2 can be released individually.

Is there a way I can publish the module indivdually? The go mod documentation only assume that there is only repo so it doesn't provide such flexibility.

1 Answers

To tag a release version for a module within a subdirectory of a repository, add the subdirectory as a prefix of the tag, like svc1/v0.1.0.

Per https://golang.org/ref/mod#vcs-version:

If a module is defined in a subdirectory within the repository …, then each tag name must be prefixed with the module subdirectory, followed by a slash. For example, the module golang.org/x/tools/gopls is defined in the gopls subdirectory of the repository with root path golang.org/x/tools. The version v0.4.0 of that module must have the tag named gopls/v0.4.0 in that repository.

Related