Skip to content

Commit

Permalink
build infos
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Feb 4, 2024
1 parent 0929c13 commit 317c891
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
21 changes: 11 additions & 10 deletions buildinfo/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var name = "unknown"
var module = "unknown"

var Tag = "unknown"
var Release = "unknown"

var rev = "unknown"
var dirty = false

Expand Down Expand Up @@ -54,19 +56,18 @@ func Module() string {
return module
}

func SemVer() string {
ver := Tag
if dirty {
ver = ver + "-dirty"
}
return ver
}

func PrintInfos() {
fmt.Printf("%s %s %s %s\n",
fmt.Printf("%s %s %s %s",
Name(),
SemVer(),
Tag,
rev,
fmt.Sprintf("%s-%s-%s", Arch, Os, compiler),
)
if dirty {
fmt.Printf(" %s", "DIRTY")
}
if Release != "true" {
fmt.Printf(" %s", "PRE-RELEASE")
}
fmt.Print("\n")
}
25 changes: 16 additions & 9 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ rm -rf "dist"
mkdir -p "dist"

# check for version tag on HEAD commit
tag="$(git describe --exact-match "$(git rev-parse HEAD)" 2>/dev/null || true |
grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+' || true)"

# if HEAD has no version tag
if test -z "${tag}"; then
# get last version tag in history
tag="$(git describe --tags --abbrev=0 --match v[0-9]* 2>/dev/null |
grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+')-indev"
tag="$(git tag --points-at HEAD |
grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+' || true | tail -n 1)"

# is there a version tag pointing to HEAD?
if test -n "${tag}"; then
# yes, this is a release version
release="true"
else
# no, not a release version...
release="false"
# get last version tag in history
tag="$(git describe --tags --abbrev=0 --match v[0-9]* 2>/dev/null |
grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+')"
# mark as dev build
tag="${tag}-indev"
fi

build() (
Expand All @@ -33,7 +40,7 @@ build() (
# build static binary
GOOS="$1" GOARCH="$2" go build \
-tags netgo,timetzdata \
-ldflags="-X 'hub.lol/mrpack-install/buildinfo.Tag=${tag}' -extldflags=-static" \
-ldflags="-X 'hub.lol/mrpack-install/buildinfo.Tag=${tag}' -X 'hub.lol/mrpack-install/buildinfo.Release=${release}' -extldflags=-static" \
-o "${file}" \
.

Expand Down

0 comments on commit 317c891

Please sign in to comment.