Skip to content

Commit 34f7101

Browse files
committed
chore: add version when compiling
1 parent a80ad10 commit 34f7101

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

Dockerfile.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ ARG GOCC
3535
ARG GOARCH
3636
ARG GOAMD64
3737
ARG GOARM
38+
ARG VERSION
3839

3940
WORKDIR /src
4041
ENV CGO_ENABLED=1 PKG_CONFIG_PATH="/build/vcpkg_installed/$TRIPLET/lib/pkgconfig" CC="$GOCC" \
4142
GOARCH="$GOARCH" GOAMD64="$GOAMD64" GOARM="$GOARM" \
4243
GOCACHE=/src/.gocache/go-build GOMODCACHE=/src/.gocache/mod
43-
CMD ["go", "build", "-o", "./go-librespot", "-a", "-ldflags", "-s -w", "./cmd/daemon"]
44+
CMD ["go", "build", "-o", "./go-librespot", "-a", "-ldflags", "-s -w -X github.com/devgianlu/go-librespot.version=$VERSION", "./cmd/daemon"]

crosscompile.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ if [ -z "$VARIANT" ]; then
88
exit 1
99
fi
1010

11+
# Get the tag associated with the current commit
12+
VERSION="$(git tag --points-at HEAD)"
13+
VERSION="${VERSION#v}"
14+
1115
# Validate and map variant to compilation envs
1216
if [ "$VARIANT" = "x86_64" ]; then
1317
TARGET="x86-64-linux-gnu"
@@ -47,6 +51,7 @@ DOCKER_IMAGE_NAME="go-librespot-build-${VARIANT}"
4751
# Build the image for cross-compilation
4852
docker build \
4953
--build-arg "TARGET=$TARGET" \
54+
--build-arg "VERSION=$VERSION" \
5055
--build-arg "TRIPLET=$TRIPLET" \
5156
--build-arg "GOARCH=$GOARCH" \
5257
--build-arg "GOAMD64=$GOAMD64" \

version.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
const SpotifyVersionCode = 125200442
1111

12-
var commit, version string
12+
var version string
1313

1414
// Extract and return the commit hash stored in the binary, if available.
1515
func commitHash() string {
@@ -26,8 +26,6 @@ func commitHash() string {
2626
func VersionNumberString() string {
2727
if len(version) > 0 {
2828
return strings.TrimPrefix(version, "v")
29-
} else if len(commit) >= 8 {
30-
return commit[:8]
3129
} else if commit := commitHash(); len(commit) >= 8 {
3230
return commit[:8]
3331
} else {
@@ -37,9 +35,7 @@ func VersionNumberString() string {
3735

3836
func SpotifyLikeClientVersion() string {
3937
if len(version) > 0 {
40-
if len(commit) >= 8 {
41-
return fmt.Sprintf("%s.g%s", version, commit[:8])
42-
} else if commit := commitHash(); len(commit) >= 8 {
38+
if commit := commitHash(); len(commit) >= 8 {
4339
return fmt.Sprintf("%s.g%s", version, commit[:8])
4440
} else {
4541
return version

0 commit comments

Comments
 (0)