Skip to content

Instantly share code, notes, and snippets.

@jsok
Created January 25, 2022 04:36
Show Gist options
  • Save jsok/75a7c2914ace98c3ed1aab2be904221c to your computer and use it in GitHub Desktop.
Save jsok/75a7c2914ace98c3ed1aab2be904221c to your computer and use it in GitHub Desktop.
Go Build ID at a particular commit
#!/usr/bin/env bash
# Shows the build id (as reported by "go list" and "go tool buildid") of a package at a given git ref.
COMMIT=${1?Error: supply a commit}
PACKAGE=${2?Error: supply a package}
git checkout --detach "${COMMIT}" >/dev/null 2>&1
go build -o tmp "${PACKAGE}" >/dev/null 2>&1
echo -n "go tool buildid: "
go tool buildid tmp
echo -n "go list -e -export -f '{{ .BuildID }}': "
go list -e -export -f '{{ .BuildID }}' "${PACKAGE}"
git switch - >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment