From 2204339dbf6515812c7bd0a7398f057f15450e8d Mon Sep 17 00:00:00 2001 From: Gerry Agbobada Date: Mon, 6 Nov 2023 11:44:35 +0100 Subject: [PATCH] Add more build information in binaries This will fix the builds that are downloaded, but not the ones from go install --- .github/workflows/release.yml | 1 + cmd/autometrics/main.go | 6 +++++- internal/build/build.go | 6 ++++++ scripts/build_generator | 6 +++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2172de9..4b43b3d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,7 @@ jobs: with: # We need all tags fetch-depth: 0 + fetch-tags: true - name: Set up Go uses: actions/setup-go@v4 with: diff --git a/cmd/autometrics/main.go b/cmd/autometrics/main.go index 181aa40..6020879 100644 --- a/cmd/autometrics/main.go +++ b/cmd/autometrics/main.go @@ -31,7 +31,11 @@ type args struct { func (args) Version() string { var buf strings.Builder - fmt.Fprintf(&buf, "Autometrics %s", build.Version) + fmt.Fprintf(&buf, "Autometrics %s (built by %s on %s)", + build.Version, + build.User, + build.Time, + ) return buf.String() } diff --git a/internal/build/build.go b/internal/build/build.go index 3600686..6170b83 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -2,3 +2,9 @@ package build // import "github.com/autometrics-dev/autometrics-go/internal/buil // Version is the version string of the build, when made available through ldflags. var Version = "development" + +// User is the user who triggered this build, when made available through ldflags. +var User = "n/a" + +// Time is the timestamp string of the build, when made available through ldflags. +var Time = "n/a" diff --git a/scripts/build_generator b/scripts/build_generator index 8dd5121..652c777 100755 --- a/scripts/build_generator +++ b/scripts/build_generator @@ -4,6 +4,10 @@ set -euo pipefail BUILD_PACK="github.com/autometrics-dev/autometrics-go/internal/build" VERSION=`git describe --tags` +USER=`id -u -n` +DATE=`date -u` SCRIPT_DIR="$( dirname -- "$( readlink -f -- "$0"; )"; )" -go build -v -ldflags="-X '${BUILD_PACK}.Version=${VERSION}'" ${SCRIPT_DIR}/../cmd/autometrics/main.go +echo "Building version ${VERSION} (${USER} @ ${DATE})" + +go build -v -a -ldflags="-X '${BUILD_PACK}.Version=${VERSION}' -X '${BUILD_PACK}.User=${USER}' -X '${BUILD_PACK}.Time=${DATE}'" ${SCRIPT_DIR}/../cmd/autometrics/main.go