Skip to content

build: unify build flags and embed build metadata in versioning#342

Open
SegueII wants to merge 2 commits into
mainfrom
version
Open

build: unify build flags and embed build metadata in versioning#342
SegueII wants to merge 2 commits into
mainfrom
version

Conversation

@SegueII

@SegueII SegueII commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Unify the per-binary build flags into a single BUILD_FLAGS variable across Makefile / MakefileEc2.mk and the CI/Docker build path.
  • Move version handling out of params/version.go into internal/version, and inject version / git commit / build time at build time.
  • Embed build metadata (git commit, version, build time) into Docker images and the geth binary, and surface it in the geth version output.

Changes

  • Makefile, MakefileEc2.mk: replace individual flags with the unified BUILD_FLAGS; pass git commit, version and build time into install / docker builds.
  • Dockerfile, Dockerfile.alltools, .github/workflows/docker_release.yml: introduce BUILD_TIME arg and propagate build metadata.
  • internal/version/version.go, internal/build/env.go, internal/flags/helpers.go: new versioning scheme; remove deprecated handling from params/version.go.
  • cmd/*, build/ci.go: surface build time and commit info in version output.

Test plan

  • make geth builds successfully and geth version shows commit + build time
  • Docker image build passes BUILD_TIME / commit / version args
  • CI docker_release workflow runs green

Made with Cursor

Close: #337

Summary by CodeRabbit

Release Notes

  • New Features

    • CLI tools now support -version flag to display version information.
    • Docker images now include build timestamp metadata in image labels.
  • Chores

    • Build system updated to derive version information from git tags (morph-v* pattern) instead of manual version bumping.
    • Build artifacts now automatically embed version, commit, and build timestamp metadata.

SegueII added 2 commits May 29, 2026 12:01
- Introduced BUILD_TIME argument in Dockerfiles to capture build time.
- Updated installation commands to pass git commit, version, and build time as arguments.
- Enhanced version command in Geth to display build time and commit information.
- Modified Makefile to include build metadata in Docker image builds.
- Updated CI configuration to output build time for Docker releases.
- Refactored build environment to support new build metadata fields.
…nd commands

- Replaced individual build flags with a unified BUILD_FLAGS variable in Makefiles.
- Updated installation commands in Makefiles and MakefileEc2.mk to utilize the new BUILD_FLAGS.
- Removed deprecated version handling from params/version.go and integrated versioning into the build process.
- Enhanced version output across various commands to include build metadata.
- Streamlined CI configuration to support the new versioning scheme and build flags.
@SegueII SegueII requested a review from a team as a code owner June 9, 2026 11:16
@SegueII SegueII requested review from secmgt and removed request for a team June 9, 2026 11:16
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors version and build metadata handling by replacing the params/version.go package with a new internal/version package that centralizes version reporting, semver parsing, and packaging format converters. Build metadata (git commit, version, build time) now flows through updated Makefiles and CI pipelines, embedded at link-time and finalized during execution. All CLI commands are updated to support -version flags via the new buildversion helpers, and the legacy version bumping script is simplified to a documentation note about using git tags.

Changes

Version system refactoring

Layer / File(s) Summary
New internal/version package: semver parsing and CLI output
internal/version/version.go
Added version reporting and semver parsing utilities (SemverParts, SemverCode, BaseSemverFor), packaging converters (DebianVersionFor, NSISVersionPartsFor), and CLI helpers (Print, PrintIfRequested) to replace params-based version composition.
Build environment: Version/BuildTime fields and finalization
internal/build/env.go
Extended Environment struct with Version and BuildTime fields; added command-line flags VersionFlag and BuildTimeFlag; introduced GitHub Actions CI detection; added finalizeEnv and tryGit helpers to populate missing metadata via git commands with dev/unknown fallbacks.
CLI app version integration: helpers and configuration
internal/flags/helpers.go
Updated NewApp signature to remove gitCommit/gitDate parameters; introduced ConfigureVersion function to wire app.Version from buildversion.Version and customize urfave/cli version printing.
Build system: Makefile and build/ci.go metadata propagation
Makefile, MakefileEc2.mk, build/ci.go, build/deb/ethereum/deb.rules
Added GITCOMMIT, VERSION, BUILD_TIME, and BUILD_FLAGS variables to build systems; switched build/ci.go from params.* to env.Version and buildversion helpers for archive naming, Docker tagging, and packaging metadata (Debian, NSIS, Maven, iOS Pod).
CI/Docker: BUILD_TIME extraction and propagation
.github/scripts/bump_version_dot_go.mjs, .github/workflows/docker_release.yml, Dockerfile, Dockerfile.alltools
Updated GitHub Actions workflow to extract BUILD_TIME (UTC timestamp) and BUILDNUM; Dockerfiles accept BUILD_TIME argument and pass it to build/ci.go; simplified version bump script to documentation note on using git tags.
geth command: config, version output, and console tests
cmd/geth/config.go, cmd/geth/main.go, cmd/geth/misccmd.go, cmd/geth/consolecmd_test.go
Updated geth to use buildversion.Version instead of params-based version; replaced manual version command output with buildversion.Print call; updated test templates to source version from buildversion package.
CLI commands: add -version flag support
cmd/abidump/main.go, cmd/bootnode/main.go, cmd/faucet/faucet.go, cmd/gen-preimages/main.go, cmd/migration-checker/main.go, cmd/rlpdump/main.go, cmd/clef/main.go, cmd/devp2p/main.go, cmd/p2psim/main.go, cmd/puppeth/puppeth.go, cmd/ethkey/main.go, cmd/evm/main.go, cmd/abigen/main.go, cmd/checkpoint-admin/main.go
Added -version flag support to CLI tools via buildversion.PrintIfRequested or flags.ConfigureVersion; removed linker-injected gitCommit/gitDate variables and simplified CLI app initialization.
Non-geth packages: migrate from params to buildversion
eth/backend.go, mobile/geth.go
Updated node configuration and database version reporting to use buildversion.Version instead of params.VersionWithMeta; replaced params-based semver extraction with buildversion helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • morph-l2/go-ethereum#298: Modifies .github/workflows/docker_release.yml to update how Docker image version and commit metadata are computed and passed as build arguments.
  • morph-l2/go-ethereum#297: Also updates .github/workflows/docker_release.yml to change version/commit derivation and Docker build argument passing.

Suggested reviewers

  • secmgt
  • FletcherMan
  • curryxbo

Poem

🐇 A rabbit's ode to the refactor:
From params to version anew,
Build metadata flows, clean and true,
Git tags and timestamps combined,
CLI tools with -version aligned,
Metadata embedded, the pipeline redefined! 🏗️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main objective of the changeset: unifying build flags and embedding build metadata into versioning across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch version

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
cmd/rlpdump/main.go (1)

138-138: 💤 Low value

Consider reverting to fmt.Fprintf for consistency.

This change from fmt.Fprintf(out, "%s[]", ws(depth)) to fmt.Fprint(out, ws(depth)+"[]") appears unrelated to the version system refactor. While it aligns the bracket output style with lines 140 and 151, it introduces inconsistency with the data output lines (130, 132) that use fmt.Fprintf with format strings. The original Fprintf approach is more idiomatic, avoids string concatenation overhead, and maintains consistency with the surrounding string formatting.

♻️ Suggested revert
-			fmt.Fprint(out, ws(depth)+"[]")
+			fmt.Fprintf(out, "%s[]", ws(depth))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/rlpdump/main.go` at line 138, Replace the direct string concatenation
fmt.Fprint(out, ws(depth)+"[]") with the idiomatic formatted call
fmt.Fprintf(out, "%s[]", ws(depth)) to match surrounding output lines; locate
the call that writes the empty-bracket representation (uses the ws(depth) helper
and the out writer) and change it to use Fprintf with a format string to avoid
concatenation overhead and preserve consistency.
.github/workflows/docker_release.yml (1)

21-24: ⚡ Quick win

Disable persisted checkout credentials.

Line 21-24 can avoid leaving credentials in git config by explicitly setting persist-credentials: false; this reduces token exposure risk in later steps/actions.

Suggested patch
       - uses: actions/checkout@v4
         with:
           ref: ${{ inputs.tag || github.ref }}
           fetch-depth: 0
+          persist-credentials: false
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/docker_release.yml around lines 21 - 24, The checkout step
currently uses actions/checkout@v4 with inputs ref and fetch-depth but does not
disable persisted credentials; update the checkout action (uses:
actions/checkout@v4) to include the input persist-credentials: false so git
credentials are not stored in the repo config after checkout, keeping the
existing ref and fetch-depth inputs intact.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Makefile`:
- Around line 10-13: The BUILD_FLAGS variable is defined with recursive
expansion which can re-evaluate timestamp-backed values; change its assignment
to use simple expansion so BUILD_FLAGS is evaluated once at parse time (freeze
the values of GITCOMMIT, VERSION and BUILD_TIME). Update the BUILD_FLAGS
assignment (the BUILD_FLAGS variable) to use a simple-expansion operator so it
captures the current $(GITCOMMIT), $(VERSION) and $(BUILD_TIME) values
immediately instead of re-evaluating them later.

In `@MakefileEc2.mk`:
- Around line 6-9: The BUILD_FLAGS variable is using recursive expansion which
can cause timestamp drift; change its definition to use simple (immediate)
expansion so it is frozen at assignment: define BUILD_FLAGS with := and compose
it from the already-defined GITCOMMIT, VERSION, and BUILD_TIME variables (so
BUILD_FLAGS := -git-commit=$(GITCOMMIT) -version=$(VERSION)
-build-time=$(BUILD_TIME)), ensuring BUILD_FLAGS is evaluated once rather than
on each reference.

---

Nitpick comments:
In @.github/workflows/docker_release.yml:
- Around line 21-24: The checkout step currently uses actions/checkout@v4 with
inputs ref and fetch-depth but does not disable persisted credentials; update
the checkout action (uses: actions/checkout@v4) to include the input
persist-credentials: false so git credentials are not stored in the repo config
after checkout, keeping the existing ref and fetch-depth inputs intact.

In `@cmd/rlpdump/main.go`:
- Line 138: Replace the direct string concatenation fmt.Fprint(out,
ws(depth)+"[]") with the idiomatic formatted call fmt.Fprintf(out, "%s[]",
ws(depth)) to match surrounding output lines; locate the call that writes the
empty-bracket representation (uses the ws(depth) helper and the out writer) and
change it to use Fprintf with a format string to avoid concatenation overhead
and preserve consistency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 49327af8-58b9-4239-bde0-f1ef74260ef8

📥 Commits

Reviewing files that changed from the base of the PR and between 01e8a42 and f83a2c0.

📒 Files selected for processing (32)
  • .github/scripts/bump_version_dot_go.mjs
  • .github/workflows/docker_release.yml
  • Dockerfile
  • Dockerfile.alltools
  • Makefile
  • MakefileEc2.mk
  • build/ci.go
  • build/deb/ethereum/deb.rules
  • cmd/abidump/main.go
  • cmd/abigen/main.go
  • cmd/bootnode/main.go
  • cmd/checkpoint-admin/main.go
  • cmd/clef/main.go
  • cmd/devp2p/main.go
  • cmd/ethkey/main.go
  • cmd/evm/main.go
  • cmd/faucet/faucet.go
  • cmd/gen-preimages/main.go
  • cmd/geth/config.go
  • cmd/geth/consolecmd_test.go
  • cmd/geth/main.go
  • cmd/geth/misccmd.go
  • cmd/migration-checker/main.go
  • cmd/p2psim/main.go
  • cmd/puppeth/puppeth.go
  • cmd/rlpdump/main.go
  • eth/backend.go
  • internal/build/env.go
  • internal/flags/helpers.go
  • internal/version/version.go
  • mobile/geth.go
  • params/version.go
💤 Files with no reviewable changes (1)
  • params/version.go

Comment thread Makefile
Comment on lines +10 to +13
GITCOMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_FLAGS = -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Freeze build metadata flags with simple expansion.

Line 13 currently uses recursive expansion; this can re-evaluate timestamp-backed values and make metadata inconsistent across references in one invocation. Prefer a simply expanded BUILD_FLAGS.

Suggested fix
 GITCOMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
 VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
 BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
-BUILD_FLAGS = -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)
+BUILD_FLAGS := -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)
🧰 Tools
🪛 checkmake (0.3.2)

[warning] 13-13: Variable "BUILD_TIME" possibly contains a timestamp and should be simply expanded.

(timestampexpanded)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 10 - 13, The BUILD_FLAGS variable is defined with
recursive expansion which can re-evaluate timestamp-backed values; change its
assignment to use simple expansion so BUILD_FLAGS is evaluated once at parse
time (freeze the values of GITCOMMIT, VERSION and BUILD_TIME). Update the
BUILD_FLAGS assignment (the BUILD_FLAGS variable) to use a simple-expansion
operator so it captures the current $(GITCOMMIT), $(VERSION) and $(BUILD_TIME)
values immediately instead of re-evaluating them later.

Source: Linters/SAST tools

Comment thread MakefileEc2.mk
Comment on lines +6 to +9
GITCOMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_FLAGS = -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use simple expansion for composed build flags here too.

Line 9 has the same recursive expansion pattern; freezing BUILD_FLAGS avoids timestamp drift between references.

Suggested fix
 GITCOMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
 VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
 BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
-BUILD_FLAGS = -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)
+BUILD_FLAGS := -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
GITCOMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_FLAGS = -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)
GITCOMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_FLAGS := -git-commit=$(GITCOMMIT) -version=$(VERSION) -build-time=$(BUILD_TIME)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MakefileEc2.mk` around lines 6 - 9, The BUILD_FLAGS variable is using
recursive expansion which can cause timestamp drift; change its definition to
use simple (immediate) expansion so it is frozen at assignment: define
BUILD_FLAGS with := and compose it from the already-defined GITCOMMIT, VERSION,
and BUILD_TIME variables (so BUILD_FLAGS := -git-commit=$(GITCOMMIT)
-version=$(VERSION) -build-time=$(BUILD_TIME)), ensuring BUILD_FLAGS is
evaluated once rather than on each reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor version specification (TBD)

1 participant