不需要。goreleaser 是一个本地构建工具,你只需在本地或 ci 环境中安装它并配置 .goreleaser.yaml 文件即可生成二进制包和发布内容。

如何配置 .goreleaser.yaml 以支持多平台构建
通过修改配置文件中的 builds 字段,你可以指定目标操作系统(GOOS)和架构(GOARCH),从而一次性为多个平台生成可执行文件。

module example.com/myapp go 1.21 require github.com/gin-gonic/gin v1.9.1 replace github.com/gin-gonic/gin => ./local_gin require ( github.com/gin-contrib/static v0.0.1 github.com/go-playground/validator/v10 v10.14.0 ) require ( github.com/bytedance/sonic v1.9.1 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.11.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect )
如何验证生成的二进制文件是否包含正确的版本信息
GoReleaser 使用 ldflags 将 Git 提交哈希、标签和构建时间注入到二进制文件中。你可以通过运行程序并检查其输出来验证这些信息是否正确嵌入。

package main
import (
"fmt"
"os"
"runtime"
)
var (
Version = "dev"
Commit = "none"
Date = "unknown"
BuildType = "unofficial"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "--version" {
fmt.Printf("Version: %s\n", Version)
fmt.Printf("Commit: %s\n", Commit)
fmt.Printf("Date: %s\n", Date)
fmt.Printf("Build Type: %s\n", BuildType)
return
}
fmt.Println("Hello, World!")
fmt.Printf("Running on %s/%s\n", runtime.GOOS, runtime.GOARCH)
}
基于程序中某个输入、条件或结果的具体问题
当你在本地运行 goreleaser build 时,如果未指定 --single-target 标志,GoReleaser 会根据当前系统的 GOOS 和 GOARCH 生成一个默认的二进制文件。如果你希望只生成特定平台的二进制文件,必须显式设置这些环境变量或使用 --single-target 标志来限制输出范围。


















