Publishing go module in a monorepo envirnoment
Asked Answered
H

1

10

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.

Helbonia answered 23/4, 2021 at 5:1 Comment(2)
The semantic version of the module is determined by repository tags, so I don't think you will be able to version each module separately in the same repository (at least on git).Idelia
You may find this section of the go wiki helpful github.com/golang/go/wiki/…Idelia
G
18

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.

Grisaille answered 29/6, 2021 at 2:8 Comment(1)
I was searching for this for hours and almost gave up thinking this might not be possible. Not sure why Google doesn't rank it from search higher.Rumba

© 2022 - 2024 — McMap. All rights reserved.