Golang:多个模块的单独版本控制

Golang: separate versioning of multiple modules

假设我有一个存储库 github.com/user/golang-examples 并且我准备单独对其中的每个示例模块进行版本控制:

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

  /modB
    /go.mod
    /pkgB1
    /pkgB2

(我知道成语是“one repo - one module”,但是多模块项目也有用例,所以这不是讨论的主题)

同时,语义 git 标记(v1.0.0v2.0.0 等)发生在 repo 级别,而不是它的 子文件夹 。这使得无法单独标记模块,例如

  1. 首先,modA 在主版本的开发中超越了 modB,标签 v2.0.0 被推送到 repo 级别,目的是版本 modA
  2. 以后想升级modB到v2的时候,不能把同一个v2.0.0git标签第二次推送到modB版本。

如何按照golang的版本控制范式来完成这个任务?同样,这是关于多模块项目的。将模块拆分为存储库的明显解决方案在这里有点不利,因为需要顶级存储库的总体“示例”语义。

谢谢!

好的,在继续搜索后我找到了这个资源:https://github.com/go-modules-by-example/index/blob/master/009_submodules/README.md

适用于我的情况,答案是使用:

  • 对于模块 modA 使用 modA/vX.Y.Z 形式的标签(使用语义版本控制)
  • 对于模块 modB 使用格式为 modB/vX.Y.Z
  • 的标签

对于上下文,引用上面的 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.

出于某种原因,我仍然找不到正确的 docs/specs 参考。

这是 golang 标签子模块的文档:
https://github.com/golang/go/wiki/Modules#publishing-a-release

A new module version may be published by pushing a tag to the repository that contains the module source code. The tag is formed by concatenating two strings: a prefix and a version.

The version is the semantic import version for the release. It should be chosen by following the rules of semantic import versioning.

The prefix indicates where a module is defined within a repository. If the module is defined at the root of the repository, the prefix is empty, and the tag is just the version. However, in multi-module repositories, the prefix distinguishes versions for different modules. The prefix is the directory within the repository where the module is defined. If the repository follows the major subdirectory pattern described above, the prefix does not include the major version suffix.

For example, suppose we have a module example.com/repo/sub/v2, and we want to publish version v2.1.6. The repository root corresponds to example.com/repo, and the module is defined in sub/v2/go.mod within the repository. The prefix for this module is sub/. The full tag for this release should be sub/v2.1.6.