diff --git a/go.mod b/go.mod index 9fda3d36..1d081462 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,7 @@ module github.com/obalunenko/instadiff-cli go 1.22 - -toolchain go1.22.0 +toolchain go1.24.0 require ( github.com/Davincible/goinsta/v3 v3.2.6 @@ -11,7 +10,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/obalunenko/getenv v1.13.0 github.com/obalunenko/logger v1.1.0 - github.com/obalunenko/version v1.2.0 + github.com/obalunenko/version v1.3.1 github.com/olegfedoseev/image-diff v0.0.0-20171116094004-897a4e73dfd6 github.com/ory/dockertest/v3 v3.11.0 github.com/schollz/progressbar/v3 v3.18.0 diff --git a/go.sum b/go.sum index 50c87215..8b7f1219 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,8 @@ github.com/obalunenko/getenv v1.13.0 h1:KE6Kky3OMLkvOgzfZkaOjodnnMawhEEuju4Hbs7D github.com/obalunenko/getenv v1.13.0/go.mod h1:z/14VQJlEBeaa/JI/RNufa/EQOSDVA2RRUz56ukYOM0= github.com/obalunenko/logger v1.1.0 h1:Q5drJuCuwz16mm96tcrl5e20uoGSOI4O+VWSauR/mQg= github.com/obalunenko/logger v1.1.0/go.mod h1:rS66dO9P2j/lybFrDB0Sce1DEVaOi6ag6WDIzljTg8c= -github.com/obalunenko/version v1.2.0 h1:eUYme2w38fjzcvToInTGM85xAJycZHo65GvynbH8jCo= -github.com/obalunenko/version v1.2.0/go.mod h1:kXnCfV2LUe+UHRrzjwPC/5lpnPbypwmLZh7BJx7wG1A= +github.com/obalunenko/version v1.3.1 h1:NN+YSOrti8mEyJSnu+7//YSvGrOhLivh60hJXhIrNTI= +github.com/obalunenko/version v1.3.1/go.mod h1:56ydLXefFem3sEJ2iyguuZ7dwJ25VoIRTev/JfxFIa4= github.com/olegfedoseev/image-diff v0.0.0-20171116094004-897a4e73dfd6 h1:a/kynVgbdXJQDq3WWTgwL0bHyg4hu4/oIK9UB+Ugvfo= github.com/olegfedoseev/image-diff v0.0.0-20171116094004-897a4e73dfd6/go.mod h1:OgMVaRcJ1TgmPHB/MF2YaHOzRxmw6vVG/DquoMhkCiY= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= diff --git a/vendor/github.com/obalunenko/version/README.md b/vendor/github.com/obalunenko/version/README.md index 0c2d23fe..7dfdeb16 100644 --- a/vendor/github.com/obalunenko/version/README.md +++ b/vendor/github.com/obalunenko/version/README.md @@ -3,32 +3,22 @@ This package contains build information generated at build time and compiled into the binary. ```go -// Package version contains build information such as the git commit, app version, build date. +// Package version provides utilities for retrieving application build information +// such as version number, build date, commit hash, application name, and the Go +// language version used during the build process. // -// This info generated at build time and compiled into the binary. +// This package leverages the `runtime/debug` package to read build metadata +// embedded in the binary during the build process with Go modules. // -// Usage: -// At your build script add following lines: -// go install -ldflags '-X github.com/obalunenko/version.version APP_VERSION -X github.com/obalunenko/version.builddate BUILD_DATE -X github.com/obalunenko/version.commit COMMIT -X github.com/obalunenko/version.shortcommit SHORTCOMMIT -X github.com/obalunenko/version.appname APP_NAME' -// and then build your binary -// go build -// Please note that all future binaries will be compiled with the embedded information unless the version package is recompiled with new values. +// Build information can be accessed via the exposed methods: // -// Alternative is use ldflags on stage of compiling: -// GOVERSION=$(go version | awk '{print $3;}') -// APP=myapp -// BIN_OUT=bin/${APP} -// BUILDINFO_VARS_PKG=github.com/obalunenko/version -// GO_BUILD_LDFLAGS="-s -w \ -//-X ${BUILDINFO_VARS_PKG}.version=${VERSION} \ -//-X ${BUILDINFO_VARS_PKG}.commit=${COMMIT} \ -//-X ${BUILDINFO_VARS_PKG}.shortcommit=${SHORTCOMMIT} \ -//-X ${BUILDINFO_VARS_PKG}.builddate=${DATE} \ -//-X ${BUILDINFO_VARS_PKG}.appname=${APP}" \ -//-X ${BUILDINFO_VARS_PKG}.goversion=${GOVERSION}" -// GO_BUILD_PACKAGE="" - -// rm -rf ${BIN_OUT} +// - GetGoVersion: Returns the Go version used to build the app. +// - GetVersion: Returns the application's version. +// - GetBuildDate: Returns the date the application was built. +// - GetCommit: Returns the full commit hash the application was built from. +// - GetShortCommit: Returns a shortened commit hash (7 characters). +// - GetAppName: Returns the application's module path. // -// go build -o ${BIN_OUT} -a -ldflags "${GO_BUILD_LDFLAGS}" "${GO_BUILD_PACKAGE}" +// When the application is built from sources with uncommitted changes, the +// commit information will be suffixed with "+CHANGES". ``` diff --git a/vendor/github.com/obalunenko/version/version.go b/vendor/github.com/obalunenko/version/version.go index 936ce913..c10928ce 100644 --- a/vendor/github.com/obalunenko/version/version.go +++ b/vendor/github.com/obalunenko/version/version.go @@ -1,34 +1,27 @@ -// Package version contains build information such as the git commit, app version, build date. +// Package version provides utilities for retrieving application build information +// such as version number, build date, commit hash, application name, and the Go +// language version used during the build process. // -// This info generated at build time and compiled into the binary. +// This package leverages the `runtime/debug` package to read build metadata +// embedded in the binary during the build process with Go modules. // -// Usage: -// At your build script add following lines: -// go install -ldflags '-X github.com/obalunenko/version.version APP_VERSION -X github.com/obalunenko/version.builddate BUILD_DATE -X github.com/obalunenko/version.commit COMMIT -X github.com/obalunenko/version.shortcommit SHORTCOMMIT -X github.com/obalunenko/version.appname APP_NAME' -// and then build your binary -// go build -// Please note that all future binaries will be compiled with the embedded information unless the version package is recompiled with new values. +// Build information can be accessed via the exposed methods: // -// Alternative is use ldflags on stage of compiling: -// GOVERSION=$(go version | awk '{print $3;}') -// APP=myapp -// BIN_OUT=bin/${APP} -// BUILDINFO_VARS_PKG=github.com/obalunenko/version -// GO_BUILD_LDFLAGS="-s -w \ -//-X ${BUILDINFO_VARS_PKG}.version=${VERSION} \ -//-X ${BUILDINFO_VARS_PKG}.commit=${COMMIT} \ -//-X ${BUILDINFO_VARS_PKG}.shortcommit=${SHORTCOMMIT} \ -//-X ${BUILDINFO_VARS_PKG}.builddate=${DATE} \ -//-X ${BUILDINFO_VARS_PKG}.appname=${APP}" \ -//-X ${BUILDINFO_VARS_PKG}.goversion=${GOVERSION}" -// GO_BUILD_PACKAGE="" - -// rm -rf ${BIN_OUT} +// - GetGoVersion: Returns the Go version used to build the app. +// - GetVersion: Returns the application's version. +// - GetBuildDate: Returns the date the application was built. +// - GetCommit: Returns the full commit hash the application was built from. +// - GetShortCommit: Returns a shortened commit hash (7 characters). +// - GetAppName: Returns the application's module path. // -// go build -o ${BIN_OUT} -a -ldflags "${GO_BUILD_LDFLAGS}" "${GO_BUILD_PACKAGE}" - +// When the application is built from sources with uncommitted changes, the +// commit information will be suffixed with "+CHANGES". package version +import ( + "runtime/debug" +) + const unset = "unset" var ( // build info @@ -40,6 +33,42 @@ var ( // build info goversion = unset ) +func init() { + info, ok := debug.ReadBuildInfo() + if !ok { + return + } + + goversion = info.GoVersion + + var modified bool + + for _, setting := range info.Settings { + switch setting.Key { + case "vcs.revision": + commit = setting.Value + case "vcs.time": + builddate = setting.Value + case "vcs.modified": + modified = true + } + } + + if len(commit) < 7 { + shortcommit = commit + } else { + shortcommit = commit[:7] + } + + if modified { + commit += "+CHANGES" + shortcommit += "+CHANGES" + } + + appname = info.Path + version = info.Main.Version +} + // GetGoVersion returns the go version func GetGoVersion() string { return goversion diff --git a/vendor/modules.txt b/vendor/modules.txt index 832a8837..df5447ad 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -216,8 +216,8 @@ github.com/obalunenko/getenv/option # github.com/obalunenko/logger v1.1.0 ## explicit; go 1.22 github.com/obalunenko/logger -# github.com/obalunenko/version v1.2.0 -## explicit; go 1.22 +# github.com/obalunenko/version v1.3.1 +## explicit; go 1.24 github.com/obalunenko/version # github.com/olegfedoseev/image-diff v0.0.0-20171116094004-897a4e73dfd6 ## explicit