From c7f3b7b72b08efc656938551baeb2cc1bee5fa6c Mon Sep 17 00:00:00 2001 From: Cal Bera Date: Fri, 8 Aug 2025 15:06:53 -0700 Subject: [PATCH] chore(version): Use git tag for version reporting (#51) * chore: miscellaneous nits * use correct default chain configs * add validation and logs around prague1 checks * fix unit tests * chore(version): Use git tag for version reporting * docker + release binaries fix * redeclare docker args in build stage --- .github/workflows/release.yml | 10 ++++++++-- Dockerfile | 14 +++++++++++++- Dockerfile.alltools | 20 ++++++++++++++++++-- Makefile | 5 ----- build/ci.go | 7 ++++++- cmd/bera-geth/config.go | 8 +++++++- eth/backend.go | 15 ++++++++++++--- internal/flags/helpers.go | 7 ++++++- internal/version/version.go | 8 +++++++- 9 files changed, 77 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffb3aa9c42..c3372e85e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,10 @@ jobs: linux-intel: name: Linux Build (intel) + needs: [extract-version] runs-on: ubuntu-latest + env: + VERSION: ${{ needs.extract-version.outputs.VERSION }} steps: - uses: actions/checkout@v4 @@ -36,7 +39,7 @@ jobs: - name: Build (amd64) run: | - go run build/ci.go install -static -arch amd64 -dlgo + go run build/ci.go install -static -arch amd64 -dlgo -git-tag="${{ env.VERSION }}" - name: Create archive (amd64) run: | @@ -57,7 +60,10 @@ jobs: linux-arm: name: Linux Build (arm) + needs: [extract-version] runs-on: ubuntu-latest + env: + VERSION: ${{ needs.extract-version.outputs.VERSION }} steps: - uses: actions/checkout@v4 @@ -75,7 +81,7 @@ jobs: - name: Build (arm64) run: | - go run build/ci.go install -static -dlgo -arch arm64 -cc aarch64-linux-gnu-gcc + go run build/ci.go install -static -dlgo -arch arm64 -cc aarch64-linux-gnu-gcc -git-tag="${{ env.VERSION }}" - name: Create archive (arm64) run: | diff --git a/Dockerfile b/Dockerfile index c29ba713bd..902599f848 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,11 @@ ARG BUILDNUM="" # Build Geth in a stock Go builder container FROM golang:1.24-alpine AS builder +# These build arguments need to be redeclared in the builder stage +ARG COMMIT +ARG VERSION +ARG BUILDNUM + RUN apk add --no-cache gcc musl-dev linux-headers git # Get dependencies - will also be cached if we won't change go.mod/go.sum @@ -14,7 +19,14 @@ COPY go.sum /bera-geth/ RUN cd /bera-geth && go mod download ADD . /bera-geth -RUN cd /bera-geth && go run build/ci.go install -static ./cmd/bera-geth +# Pass git information to the build process +# When VERSION is provided (e.g., from CI), use it as the git tag +RUN cd /bera-geth && \ + if [ -n "$VERSION" ]; then \ + go run build/ci.go install -static -git-tag="$VERSION" -git-commit="$COMMIT" ./cmd/bera-geth; \ + else \ + go run build/ci.go install -static ./cmd/bera-geth; \ + fi # Pull Geth into a second stage deploy alpine container FROM alpine:latest diff --git a/Dockerfile.alltools b/Dockerfile.alltools index bd8ef68ae3..2e2867cb93 100644 --- a/Dockerfile.alltools +++ b/Dockerfile.alltools @@ -6,6 +6,11 @@ ARG BUILDNUM="" # Build Geth in a stock Go builder container FROM golang:1.24-alpine AS builder +# These build arguments need to be redeclared in the builder stage +ARG COMMIT +ARG VERSION +ARG BUILDNUM + RUN apk add --no-cache gcc musl-dev linux-headers git # Get dependencies - will also be cached if we won't change go.mod/go.sum @@ -19,9 +24,20 @@ ADD . /bera-geth # makes it so that under certain circumstances, the docker layer can be cached, # and the builder can jump to the next (build all) command, with the go cache fully loaded. # -RUN cd /bera-geth && go run build/ci.go install -static ./cmd/bera-geth +# Pass git information to the build process when provided +RUN cd /bera-geth && \ + if [ -n "$VERSION" ]; then \ + go run build/ci.go install -static -git-tag="$VERSION" -git-commit="$COMMIT" ./cmd/bera-geth; \ + else \ + go run build/ci.go install -static ./cmd/bera-geth; \ + fi -RUN cd /bera-geth && go run build/ci.go install -static +RUN cd /bera-geth && \ + if [ -n "$VERSION" ]; then \ + go run build/ci.go install -static -git-tag="$VERSION" -git-commit="$COMMIT"; \ + else \ + go run build/ci.go install -static; \ + fi # Pull all binaries into a second stage deploy alpine container FROM alpine:latest diff --git a/Makefile b/Makefile index ffa9bae6a5..791a422754 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,6 @@ GOBIN = ./build/bin GO ?= latest GORUN = go run -COMMIT = $(shell git log -1 --format='%H') -BRANCH = $(shell git rev-parse --abbrev-ref HEAD) -TAG := $(shell git describe --tags --abbrev=0 --match "v*") -BUILD_FLAGS := -git-commit=$(COMMIT) -git-branch=$(BRANCH) -git-tag=$(TAG) - #? bera-geth: Build bera-geth. bera-geth: $(GORUN) build/ci.go install ./cmd/bera-geth diff --git a/build/ci.go b/build/ci.go index a34dc92a8e..4f335fa8f2 100644 --- a/build/ci.go +++ b/build/ci.go @@ -705,9 +705,14 @@ func doDockerBuildx(cmdline []string) { {file: "Dockerfile.alltools", base: fmt.Sprintf("%s:alltools-", *hubImage)}, } { gethImage := fmt.Sprintf("%s%s", spec.base, tag) + // Prefer tag when present for VERSION + dockerVersion := version.WithMeta + if env.Tag != "" { + dockerVersion = env.Tag + } cmd := exec.Command("docker", "buildx", "build", "--build-arg", "COMMIT="+env.Commit, - "--build-arg", "VERSION="+version.WithMeta, + "--build-arg", "VERSION="+dockerVersion, "--build-arg", "BUILDNUM="+env.Buildnum, "--tag", gethImage, "--platform", *platform, diff --git a/cmd/bera-geth/config.go b/cmd/bera-geth/config.go index 96bd715e88..f6e9e97172 100644 --- a/cmd/bera-geth/config.go +++ b/cmd/bera-geth/config.go @@ -131,7 +131,13 @@ func defaultNodeConfig() node.Config { git, _ := version.VCS() cfg := node.DefaultConfig cfg.Name = clientIdentifier - cfg.Version = version.WithCommit(git.Commit, git.Date) + // Prefer git tag for the advertised version (used in web3_clientVersion), + // trimming any leading 'v' because NodeName adds the 'v' prefix itself. + ver := version.WithMeta + if git.Tag != "" { + ver = strings.TrimPrefix(git.Tag, "v") + } + cfg.Version = ver cfg.HTTPModules = append(cfg.HTTPModules, "eth") cfg.WSModules = append(cfg.WSModules, "eth") cfg.IPCPath = clientIdentifier + ".ipc" diff --git a/eth/backend.go b/eth/backend.go index 82716e1e40..5bf1586029 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -24,6 +24,7 @@ import ( "math" "math/big" "runtime" + "strings" "sync" "time" @@ -357,13 +358,21 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { func makeExtraData(extra []byte) []byte { if len(extra) == 0 { - // create default extradata in ASCII format similar to reth - // Format: "bera-geth/vX.Y.Z/platform" + // Create default extradata in ASCII format similar to reth + // Desired format examples: + // - bera-geth/v1.011602.0-rc5/linux when tag exists + // - bera-geth/v/linux as fallback tag := version.WithMeta if vcs, ok := version.VCS(); ok && vcs.Tag != "" { + // Use tag as-is here because the desired extradata includes the leading 'v' tag = vcs.Tag } - versionStr := fmt.Sprintf("bera-geth/v%s/%s", tag, runtime.GOOS) + versionStr := fmt.Sprintf("bera-geth/%s/%s", func() string { + if strings.HasPrefix(tag, "v") { + return tag + } + return "v" + tag + }(), runtime.GOOS) extra = []byte(versionStr) } if uint64(len(extra)) > params.MaximumExtraDataSize { diff --git a/internal/flags/helpers.go b/internal/flags/helpers.go index fc84ae85da..43e5704425 100644 --- a/internal/flags/helpers.go +++ b/internal/flags/helpers.go @@ -38,7 +38,12 @@ func NewApp(usage string) *cli.App { git, _ := version.VCS() app := cli.NewApp() app.EnableBashCompletion = true - app.Version = version.WithCommit(git.Commit, git.Date) + // Prefer git tag for the concise CLI version (-v), falling back to commit-based string + if git.Tag != "" { + app.Version = git.Tag + } else { + app.Version = version.WithCommit(git.Commit, git.Date) + } app.Usage = usage app.Copyright = "Copyright 2013-2025 The go-ethereum Authors" app.Before = func(ctx *cli.Context) error { diff --git a/internal/version/version.go b/internal/version/version.go index ff93368ecf..0aa96f30b4 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -69,9 +69,15 @@ func Archive(tag, gitCommit string) string { // conventions in the Ethereum p2p network. func ClientName(clientIdentifier string) string { git, _ := VCS() + // Compose version for client name: prefer git tag (without leading 'v'), + // otherwise fall back to WithCommit (which includes meta/commit/date if needed). + ver := WithCommit(git.Commit, git.Date) + if git.Tag != "" { + ver = strings.TrimPrefix(git.Tag, "v") + } return fmt.Sprintf("%s/v%v/%v-%v/%v", strings.Title(clientIdentifier), - WithCommit(git.Commit, git.Date), + ver, runtime.GOOS, runtime.GOARCH, runtime.Version(), )