Skip to content

Commit

Permalink
Add more build information in binaries
Browse files Browse the repository at this point in the history
This will fix the builds that are downloaded, but not the ones from go install
  • Loading branch information
gagbo committed Nov 6, 2023
1 parent aa3aeec commit 2204339
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion cmd/autometrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
6 changes: 6 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion scripts/build_generator
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2204339

Please sign in to comment.