chore_: get version with go generate (#6014)

* chore_: get version with go generate

* fix_: test-functional

* fix_: trip space in version and gitcommit

* fix_: TestUserAgent
This commit is contained in:
Igor Sirotin 2024-11-03 00:47:15 +00:00 committed by GitHub
parent c040cc753e
commit e938635d04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 65 additions and 33 deletions

2
.gitignore vendored
View File

@ -120,6 +120,8 @@ bindata.go
migrations.go migrations.go
cmd/status-backend/server/endpoints.go cmd/status-backend/server/endpoints.go
protocol/messenger_handlers.go protocol/messenger_handlers.go
params/VERSION
params/GIT_COMMIT
# Don't ignore generated files in the vendor/ directory # Don't ignore generated files in the vendor/ directory
!vendor/**/*.pb.go !vendor/**/*.pb.go

View File

@ -32,7 +32,6 @@ help: ##@other Show this help
RELEASE_TAG ?= $(shell ./_assets/scripts/version.sh) RELEASE_TAG ?= $(shell ./_assets/scripts/version.sh)
RELEASE_DIR ?= /tmp/release-$(RELEASE_TAG) RELEASE_DIR ?= /tmp/release-$(RELEASE_TAG)
GOLANGCI_BINARY = golangci-lint GOLANGCI_BINARY = golangci-lint
IPFS_GATEWAY_URL ?= https://ipfs.status.im/
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows detected_OS := Windows
@ -61,14 +60,8 @@ GIT_AUTHOR ?= $(shell git config user.email || echo $$USER)
ENABLE_METRICS ?= true ENABLE_METRICS ?= true
BUILD_TAGS ?= gowaku_no_rln BUILD_TAGS ?= gowaku_no_rln
BUILD_FLAGS ?= -ldflags="-X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \ BUILD_FLAGS ?= -ldflags="-X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=$(ENABLE_METRICS)"
-X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \ BUILD_FLAGS_MOBILE ?=
-X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL) \
-X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=$(ENABLE_METRICS)"
BUILD_FLAGS_MOBILE ?= -ldflags="-X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \
-X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \
-X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL)"
networkid ?= StatusChain networkid ?= StatusChain

View File

@ -5,7 +5,7 @@ FROM golang:1.21-alpine3.18 as builder
ENV CC=clang ENV CC=clang
ENV CXX=clang++ ENV CXX=clang++
RUN apk add --no-cache git make llvm clang musl-dev linux-headers protobuf-dev~3.21 RUN apk add --no-cache git bash make llvm clang musl-dev linux-headers protobuf-dev~3.21
ARG build_tags ARG build_tags
ARG build_flags ARG build_flags

View File

@ -112,8 +112,8 @@ func NewGethStatusBackend(logger *zap.Logger) *GethStatusBackend {
backend.initialize() backend.initialize()
logger.Info("Status backend initialized", logger.Info("Status backend initialized",
zap.String("backend geth version", params.Version), zap.String("backend geth version", params.Version()),
zap.String("commit", params.GitCommit), zap.String("commit", params.GitCommit()),
zap.String("IpfsGatewayURL", params.IpfsGatewayURL)) zap.String("IpfsGatewayURL", params.IpfsGatewayURL))
return backend return backend
@ -2065,7 +2065,7 @@ func (b *GethStatusBackend) loadNodeConfig(inputNodeCfg *params.NodeConfig) erro
// NodeConfig.Version should be taken from params.Version // NodeConfig.Version should be taken from params.Version
// which is set at the compile time. // which is set at the compile time.
// What's cached is usually outdated so we overwrite it here. // What's cached is usually outdated so we overwrite it here.
conf.Version = params.Version conf.Version = params.Version()
conf.RootDataDir = b.rootDataDir conf.RootDataDir = b.rootDataDir
conf.DataDir = filepath.Join(b.rootDataDir, conf.DataDir) conf.DataDir = filepath.Join(b.rootDataDir, conf.DataDir)
conf.KeyStoreDir = filepath.Join(b.rootDataDir, conf.KeyStoreDir) conf.KeyStoreDir = filepath.Join(b.rootDataDir, conf.KeyStoreDir)
@ -2111,7 +2111,9 @@ func (b *GethStatusBackend) startNode(config *params.NodeConfig) (err error) {
} }
}() }()
b.logger.Info("status-go version details", zap.String("version", params.Version), zap.String("commit", params.GitCommit)) b.logger.Info("status-go version details",
zap.String("version", params.Version()),
zap.String("commit", params.GitCommit()))
b.logger.Debug("starting node with config", zap.Stringer("config", config)) b.logger.Debug("starting node with config", zap.Stringer("config", config))
// Update config with some defaults. // Update config with some defaults.
if err := config.UpdateWithDefaults(); err != nil { if err := config.UpdateWithDefaults(); err != nil {

View File

@ -11,6 +11,7 @@ import (
"github.com/status-im/status-go/cmd/status-backend/server" "github.com/status-im/status-go/cmd/status-backend/server"
"github.com/status-im/status-go/logutils" "github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/params"
) )
var ( var (
@ -42,7 +43,11 @@ func main() {
return return
} }
log.Info("server started", "address", srv.Address()) log.Info("status-backend started",
"address", srv.Address(),
"version", params.Version(),
"gitCommit", params.GitCommit(),
)
srv.RegisterMobileAPI() srv.RegisterMobileAPI()
srv.Serve() srv.Serve()
} }

View File

@ -919,7 +919,7 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
DataDir: dataDir, DataDir: dataDir,
KeyStoreDir: keyStoreDir, KeyStoreDir: keyStoreDir,
KeycardPairingDataFile: keycardPairingDataFile, KeycardPairingDataFile: keycardPairingDataFile,
Version: Version, Version: Version(),
HTTPHost: "localhost", HTTPHost: "localhost",
HTTPPort: 8545, HTTPPort: 8545,
HTTPVirtualHosts: []string{"localhost"}, HTTPVirtualHosts: []string{"localhost"},

View File

@ -1,11 +1,39 @@
package params package params
// Version is defined in git tags. import (
// We set it from the Makefile. _ "embed"
var Version string "strings"
)
// GitCommit is a commit hash. // Use go:generate script to get the version and git commit.
var GitCommit string // VERSION and GIT_COMMIT files are used in further `go:embed` commands to load values to the variables.
// Suppress errors, assuming files have already been properly generated. Required for Docker builds.
//go:generate sh -c "../_assets/scripts/version.sh > VERSION || true"
//go:generate sh -c "git rev-parse --short HEAD > GIT_COMMIT || true"
var (
// version is defined in git tags.
// We set it from the Makefile.
//go:embed VERSION
version string
// gitCommit is a commit hash.
//go:embed GIT_COMMIT
gitCommit string
)
// IpfsGatewayURL is the Gateway URL to use for IPFS // IpfsGatewayURL is the Gateway URL to use for IPFS
var IpfsGatewayURL string const IpfsGatewayURL = "https://ipfs.status.im/"
func init() {
version = strings.TrimSpace(version)
gitCommit = strings.TrimSpace(gitCommit)
}
func Version() string {
return version
}
func GitCommit() string {
return gitCommit
}

View File

@ -59,17 +59,17 @@ var (
var ( var (
// rpcUserAgentName the user agent // rpcUserAgentName the user agent
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, "no-GOOS", params.Version) rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, "no-GOOS", params.Version())
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, "no-GOOS", params.Version) rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, "no-GOOS", params.Version())
) )
func init() { func init() {
if appCommon.IsMobilePlatform() { if appCommon.IsMobilePlatform() {
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, mobile, params.Version) rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, mobile, params.Version())
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, mobile, params.Version) rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, mobile, params.Version())
} else { } else {
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, desktop, params.Version) rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, desktop, params.Version())
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, desktop, params.Version) rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, desktop, params.Version())
} }
} }

View File

@ -8,6 +8,7 @@ import (
"math/big" "math/big"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings"
"sync" "sync"
"testing" "testing"
@ -184,6 +185,6 @@ func TestGetClientsUsingCache(t *testing.T) {
} }
func TestUserAgent(t *testing.T) { func TestUserAgent(t *testing.T) {
require.Equal(t, "procuratee-desktop/", rpcUserAgentName) require.True(t, strings.HasPrefix(rpcUserAgentName, "procuratee-desktop/"))
require.Equal(t, "procuratee-desktop-upstream/", rpcUserAgentUpstreamName) require.True(t, strings.HasPrefix(rpcUserAgentUpstreamName, "procuratee-desktop-upstream/"))
} }

View File

@ -176,7 +176,7 @@ func (s *Service) InitProtocol(nodeName string, identity *ecdsa.PrivateKey, appD
s.n, s.n,
s.config.ShhextConfig.InstallationID, s.config.ShhextConfig.InstallationID,
s.peerStore, s.peerStore,
params.Version, params.Version(),
options..., options...,
) )
if err != nil { if err != nil {

View File

@ -19,9 +19,10 @@ import (
wps "github.com/waku-org/go-waku/waku/v2/peerstore" wps "github.com/waku-org/go-waku/waku/v2/peerstore"
v2protocol "github.com/waku-org/go-waku/waku/v2/protocol"
v1protocol "github.com/status-im/status-go/protocol/v1" v1protocol "github.com/status-im/status-go/protocol/v1"
v2common "github.com/status-im/status-go/wakuv2/common" v2common "github.com/status-im/status-go/wakuv2/common"
v2protocol "github.com/waku-org/go-waku/waku/v2/protocol"
) )
type TelemetryType string type TelemetryType string

View File

@ -1,7 +1,7 @@
FROM ghcr.io/foundry-rs/foundry:latest FROM ghcr.io/foundry-rs/foundry:latest
RUN apk update && \ RUN apk update && \
apk add git apk add git bash
WORKDIR /app WORKDIR /app