mirror of
https://github.com/agent-substrate/substrate.git
synced 2026-11-10 10:13:50 +08:00
Adds internal/version with three vars (Version, Commit, BuildDate) set
via -ldflags -X at build time. When unset (e.g. plain `go build`
without LDFLAGS), runtime/debug.ReadBuildInfo() populates them from the
embedded vcs info so `go install`, `go run`, and ko-built images
(buildvcs is on by default) still produce something meaningful.
Wired through:
- Makefile: VERSION / COMMIT / BUILD_DATE resolved from `git describe`
/ `git rev-parse` / `date`. LDFLAGS plumbed into every go-build and
ko-build target (build-images, build-atectl, build-atenet,
build-demos).
- hack/install-ate.sh: untouched here — ko apply / resolve don't
accept --ldflags, and ko's buildvcs embedding gives Commit +
BuildDate automatically through runtime/debug.ReadBuildInfo() in
the version package's init() fallback.
All six binaries respond to `--version`:
- kubectl-ate and atenet (cobra): rootCmd.Version = version.String()
- ateapi, atelet, ateom-gvisor, podcertcontroller (flag): explicit
`-version` bool that prints and exits.
Sample output:
kubectl-ate version 3b0a0d5 commit=3b0a0d5c2... \
built=2026-05-26T14:16:53Z darwin/arm64
Closes the "kubectl-ate --version has nothing to print" gap; gives ops
a way to tell at a glance which commit a deployed substrate component
came from.
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
95 lines
2.4 KiB
Makefile
95 lines
2.4 KiB
Makefile
# Copyright 2026 Google LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# Default project ID, can be overridden
|
|
PROJECT_ID ?= $(shell echo $${USER}-gke-dev)
|
|
|
|
# Ko configuration
|
|
export KO_DOCKER_REPO := gcr.io/$(PROJECT_ID)/ate-images
|
|
|
|
# Go commands
|
|
GO := go
|
|
KO := hack/run-tool.sh ko
|
|
|
|
# Binaries
|
|
BINDIR := bin/
|
|
ATECTL := $(BINDIR)/kubectl-ate
|
|
|
|
# Version stamping. Override on the make command line to pin
|
|
# (e.g. `make VERSION=v0.5.0 build`).
|
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
|
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo unknown)
|
|
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
VERSION_PKG := github.com/agent-substrate/substrate/internal/version
|
|
LDFLAGS := -X $(VERSION_PKG).Version=$(VERSION) \
|
|
-X $(VERSION_PKG).Commit=$(COMMIT) \
|
|
-X $(VERSION_PKG).BuildDate=$(BUILD_DATE)
|
|
|
|
.PHONY: all
|
|
all: build
|
|
|
|
.PHONY: build
|
|
build: build-images build-atectl
|
|
|
|
.PHONY: build-images
|
|
build-images:
|
|
$(KO) build --ldflags "$(LDFLAGS)" ./cmd/ateapi
|
|
$(KO) build --ldflags "$(LDFLAGS)" ./cmd/atelet
|
|
$(KO) build --ldflags "$(LDFLAGS)" ./cmd/podcertcontroller
|
|
$(KO) build --ldflags "$(LDFLAGS)" ./cmd/atenet
|
|
|
|
.PHONY: build-atectl
|
|
build-atectl:
|
|
$(GO) build -ldflags "$(LDFLAGS)" -o $(ATECTL) ./cmd/kubectl-ate
|
|
|
|
.PHONY: build-atenet
|
|
build-atenet:
|
|
$(GO) build -ldflags "$(LDFLAGS)" -o $(BINDIR)/atenet ./cmd/atenet
|
|
|
|
.PHONY: build-demos
|
|
build-demos:
|
|
$(KO) build --ldflags "$(LDFLAGS)" ./demos/counter
|
|
|
|
.PHONY: test
|
|
test:
|
|
$(GO) test ./...
|
|
|
|
.PHONY: e2e
|
|
e2e: build build-demos
|
|
hack/run-e2e.sh
|
|
|
|
.PHONY: fmt verify-fmt
|
|
|
|
# Formats all Go files in the project
|
|
fmt:
|
|
@./hack/update/gofmt.sh
|
|
|
|
# Fails if any Go files are not formatted properly
|
|
verify-fmt:
|
|
@./hack/verify/gofmt.sh
|
|
|
|
.PHONY: lint
|
|
|
|
# Runs golangci-lint and fails on any reported issues.
|
|
lint:
|
|
@./hack/verify/golangci-lint.sh
|
|
|
|
.PHONY: verify
|
|
verify: test
|
|
bash hack/verify-all.sh
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(BINDIR)
|