mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
fix(version): produce shorter user agent for tagged release builds
when building from a version-tagged commit with a clean tree, omit the redundant git commit hash from the libp2p user agent string, saving bytes in HTTP requests and libp2p identify. `ipfs version --commit` still reports the full commit hash. before (tagged release): kubo/0.37.0/6898472 after (tagged release): kubo/0.37.0 non-tagged and dirty builds are unaffected.
This commit is contained in:
parent
ce8b70779f
commit
bbefaea82e
@ -12,7 +12,7 @@ PATH := $(realpath $(d)):$(PATH)
|
||||
# DEPS_OO_$(d) += merkledag/pb/merkledag.pb.go namesys/pb/namesys.pb.go
|
||||
# DEPS_OO_$(d) += pin/internal/pb/header.pb.go unixfs/pb/unixfs.pb.go
|
||||
|
||||
$(d)_flags =-ldflags="-X "github.com/ipfs/kubo".CurrentCommit=$(git-hash)"
|
||||
$(d)_flags =-ldflags="-X "github.com/ipfs/kubo".CurrentCommit=$(git-hash) -X "github.com/ipfs/kubo".taggedRelease=$(git-tag)"
|
||||
|
||||
$(IPFS_BIN_$(d)): GOFLAGS += $(cmd/ipfs_flags)
|
||||
|
||||
|
||||
@ -2,3 +2,11 @@
|
||||
# If that fails (e.g., we're building a docker image and have an empty objects
|
||||
# directory), assume the source isn't dirty and build anyways.
|
||||
git-hash:=$(shell git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
|
||||
|
||||
# Detect if HEAD is a clean, tagged release. Used to omit redundant commit
|
||||
# hash from the libp2p user agent (the version number suffices).
|
||||
ifeq ($(findstring dirty,$(git-hash)),)
|
||||
git-tag:=$(shell git tag --points-at HEAD 2>/dev/null | grep '^v' | head -1)
|
||||
else
|
||||
git-tag:=
|
||||
endif
|
||||
|
||||
25
version.go
25
version.go
@ -10,6 +10,12 @@ import (
|
||||
// CurrentCommit is the current git commit, this is set as a ldflag in the Makefile.
|
||||
var CurrentCommit string
|
||||
|
||||
// taggedRelease is set via ldflag when building from a version-tagged commit
|
||||
// with a clean tree. When set, the commit hash is omitted from the libp2p
|
||||
// identify agent version and the HTTP user agent, since the version number
|
||||
// already identifies the exact source.
|
||||
var taggedRelease string
|
||||
|
||||
// CurrentVersionNumber is the current application's version literal.
|
||||
const CurrentVersionNumber = "0.40.0-rc1"
|
||||
|
||||
@ -19,15 +25,20 @@ const ApiVersion = "/kubo/" + CurrentVersionNumber + "/" //nolint
|
||||
const RepoVersion = 18
|
||||
|
||||
// GetUserAgentVersion is the libp2p user agent used by go-ipfs.
|
||||
//
|
||||
// Note: This will end in `/` when no commit is available. This is expected.
|
||||
func GetUserAgentVersion() string {
|
||||
userAgent := "kubo/" + CurrentVersionNumber + "/" + CurrentCommit
|
||||
if userAgentSuffix != "" {
|
||||
if CurrentCommit != "" {
|
||||
userAgent += "/"
|
||||
// For tagged release builds with a clean tree, the commit hash is
|
||||
// redundant since the version number identifies the exact source.
|
||||
commit := CurrentCommit
|
||||
if taggedRelease != "" {
|
||||
commit = ""
|
||||
}
|
||||
userAgent += userAgentSuffix
|
||||
|
||||
userAgent := "kubo/" + CurrentVersionNumber
|
||||
if commit != "" {
|
||||
userAgent += "/" + commit
|
||||
}
|
||||
if userAgentSuffix != "" {
|
||||
userAgent += "/" + userAgentSuffix
|
||||
}
|
||||
return cmdutils.CleanAndTrim(userAgent)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user