如何为 Go Mod / pkg.go.dev 消费者发布更新包?

How to release updated packages for Go Mod / pkg.go.dev consumers?

如何标记他们的回购协议,并让它显示在 go mod and/or pkg.go.dev 中?

我已将其中一个包裹转换为 go mod。但是,go mod 工具本身似乎只能看到我的包的非常旧的版本。

编辑:我刚刚注意到我的旧版本有一个“v”前缀,而我的新标签没有“v”前缀。

这是根本问题吗?该硬性要求记录在何处?


我的问题包裹:https://github.com/eduncan911/podcast

我标记的版本:https://github.com/eduncan911/podcast/releases

1.4.1
1.4.0
1.3.2
1.3.1
1.3.0 <- this is the current version Go Modules sees available

然而,pkg.go.dev shows:

v1 – github.com/eduncan911/podcast
v1.3.0 – Feb 19, 2017
v1.1.0 – Feb 6, 2017
v1.0.0 – Feb 5, 2017

https://proxy.golang.org/ 上的常见问题解答说:

I committed a new change (or released a new version) to a repository, why isn't it showing up when I run go get -u or go list -m --versions?

In order to improve our services' caching and serving latencies, new versions may not show up right away. If you want new code to be immediately available in the mirror, then first make sure there is a semantically versioned tag for this revision in the underlying source repository. Then explicitly request that version via go get module@version. After one minute for caches to expire, the go command will see that tagged version.

所以,我试过了:

$ go get github.com/eduncan911/podcast@1.3.1
go: cannot use path@version syntax in GOPATH mode

猜测这意味着我需要在一个 repo 或 Go 项目中;所以,我创建了一个:

$ cat main.go
package main

import (
        "fmt"
        "github.com/eduncan911/podcast"
)

func main() {
        fmt.Print(podcast.MP3)
}

更改到此目录,运行 go mod init,然后 运行 再次:

$ go mod download github.com/eduncan911/podcast@1.3.1
go: finding github.com/eduncan911/podcast 1.3.1
$ go mod download github.com/eduncan911/podcast@1.3.2
go: finding github.com/eduncan911/podcast 1.3.2
$ go mod download github.com/eduncan911/podcast@1.4.0
go: finding github.com/eduncan911/podcast 1.4.0
$ go mod download github.com/eduncan911/podcast@1.4.1
go: finding github.com/eduncan911/podcast 1.4.1

好的,没有反应,return 提示。也许我在做某事...

$ go run main.go
go: finding github.com/eduncan911/podcast v1.3.0
go: downloading github.com/eduncan911/podcast v1.3.0
go: extracting github.com/eduncan911/podcast v1.3.0

多哈

$ go mod graph
github.com/eduncan911/podcast-test github.com/eduncan911/podcast@v1.3.0
github.com/eduncan911/podcast-test github.com/pkg/errors@v0.9.1

也许我需要下载明确的版本,就像 FAQ 所说的 module@version。

我编辑了 go.mod 并指定了 1.3.1。那么:

$ go mod download
go: github.com/eduncan911/podcast@v1.3.1: reading github.com/eduncan911/podcast/go.mod at revision v1.3.1: unknown revision v1.3.1

我最后一次尝试是回到常见问题解答声明,运行 go get module@version 就像它说的那样:

$ go get github.com/eduncan911/podcast@1.4.1
go: github.com/eduncan911/podcast@v1.4.1: reading github.com/eduncan911/podcast/go.mod at revision v1.4.1: unknown revision v1.4.1

请注意,我在上面的某些陈述之间不断更改版本。但每次都是一个不存在的版本。

我已经等了几个小时并重试了其中的许多语句以清除任何缓存。

提前致谢!

Is that the root problem? Where is that hard requirement documented?

是的,这是必需的。来自 the Go wiki(强调已添加):

Modules must be semantically versioned according to semver, usually in the form v(major).(minor).(patch), such as v0.1.0, v1.2.3, or v1.5.0-rc.1. The leading v is required. If using Git, tag released commits with their versions. Public and private module repositories and proxies are becoming available (see FAQ below).

OP 有两个问题。

  1. Go Mod 忽略不以 v 为前缀的包标签,正如@Flimzy 指出的那样
  2. pkg.go.dev 不是 showing/exposing 新版本一旦被标记,依赖于 "community" 在找到新版本之前请求更新版本

第一个是简单的修复 - 用 v 前缀重新标记所有内容。

第二个可以通过将此添加到 CICD 管道来修复:

curl https://sum.golang.org/lookup/github.com/eduncan911/podcast@v1.4.1

这是强制 pkg.go.dev 更新并使新标签立即可用于其余管道 运行 和测试的最可靠方法。它通过强制 pkg.go.dev 获取该特定版本的哈希值来工作。如果该版本不存在,它将获取它 - 然后对其进行哈希处理。因此,添加到 Go Mod 数据源。

我必须警告它没有很好的记录,因此 API 可能会超时更改。他们希望您使用 Proxy 命令;但是,在许多测试发布中,我对它的可靠性并不高。但是,上面的 curl 命令每次都 100% 有效,并且立即可用(重置缓存)。