mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-06 20:32:44 +08:00
feat: add GitCommit/GitBranch/BuildTime in version info
This commit is contained in:
8
Makefile
8
Makefile
@@ -16,7 +16,13 @@ bump: ## bump hrp version, e.g. make bump version=4.0.0
|
||||
.PHONY: build
|
||||
build: ## build hrp cli tool
|
||||
@echo "[info] build hrp cli tool"
|
||||
@. scripts/build.sh $(tags)
|
||||
go build -ldflags "\
|
||||
-s -w \
|
||||
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
|
||||
-X 'github.com/httprunner/httprunner/v5/internal/version.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)' \
|
||||
-X 'github.com/httprunner/httprunner/v5/internal/version.BuildTime=$(shell date "+%y%m%d%H%M")'" \
|
||||
-o output/hrp ./cmd/cli
|
||||
./output/hrp -v
|
||||
|
||||
.PHONY: install-hooks
|
||||
install-hooks: ## install git hooks
|
||||
|
||||
@@ -51,7 +51,7 @@ Copyright © 2017-present debugtalk. Apache-2.0 License.`,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
hrp.InitLogger(logLevel, logJSON)
|
||||
},
|
||||
Version: version.VERSION,
|
||||
Version: version.GetVersionInfo(),
|
||||
TraverseChildren: true, // parses flags on all parents before executing child command
|
||||
SilenceUsage: true, // silence usage when an error occurs
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
v5.0.0-beta-2503172016
|
||||
v5.0.0-beta-2503172040
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed VERSION
|
||||
var VERSION string
|
||||
|
||||
func init() {
|
||||
VERSION = strings.TrimSpace(VERSION)
|
||||
}
|
||||
31
internal/version/version.go
Normal file
31
internal/version/version.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed VERSION
|
||||
var VERSION string
|
||||
|
||||
func init() {
|
||||
VERSION = strings.TrimSpace(VERSION)
|
||||
}
|
||||
|
||||
// 版本信息,在编译时通过 -ldflags 注入
|
||||
var (
|
||||
GitCommit = "unknown"
|
||||
GitBranch = "unknown"
|
||||
BuildTime = "unknown"
|
||||
)
|
||||
|
||||
func GetVersionInfo() string {
|
||||
commitID := GitCommit
|
||||
if len(commitID) > 8 {
|
||||
commitID = commitID[:8]
|
||||
}
|
||||
return fmt.Sprintf("%s (branch=%s, commit=%s, build=%s)",
|
||||
VERSION, GitBranch, commitID, BuildTime)
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
# build hrp cli binary for testing
|
||||
# release will be triggered on github actions, see .github/workflows/release.yml
|
||||
|
||||
# Usage:
|
||||
# $ make build
|
||||
# or
|
||||
# $ bash scripts/build.sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
# prepare path
|
||||
mkdir -p "output"
|
||||
bin_path="output/hrp"
|
||||
|
||||
# build
|
||||
go build -ldflags '-s -w' -o "$bin_path" cmd/cli/main.go
|
||||
|
||||
# check output and version
|
||||
ls -lh "$bin_path"
|
||||
chmod +x "$bin_path"
|
||||
./"$bin_path" -v
|
||||
Reference in New Issue
Block a user