diff --git a/Dockerfile.build b/Dockerfile.build index 1b0a7b8..b8d59a8 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -35,9 +35,10 @@ ARG GOCC ARG GOARCH ARG GOAMD64 ARG GOARM +ARG VERSION WORKDIR /src ENV CGO_ENABLED=1 PKG_CONFIG_PATH="/build/vcpkg_installed/$TRIPLET/lib/pkgconfig" CC="$GOCC" \ GOARCH="$GOARCH" GOAMD64="$GOAMD64" GOARM="$GOARM" \ GOCACHE=/src/.gocache/go-build GOMODCACHE=/src/.gocache/mod -CMD ["go", "build", "-o", "./go-librespot", "-a", "-ldflags", "-s -w", "./cmd/daemon"] +CMD ["go", "build", "-o", "./go-librespot", "-a", "-ldflags", "-s -w -X github.com/devgianlu/go-librespot.version=$VERSION", "./cmd/daemon"] diff --git a/crosscompile.sh b/crosscompile.sh index ffe53fa..ca65f68 100755 --- a/crosscompile.sh +++ b/crosscompile.sh @@ -8,6 +8,10 @@ if [ -z "$VARIANT" ]; then exit 1 fi +# Get the tag associated with the current commit +VERSION="$(git tag --points-at HEAD)" +VERSION="${VERSION#v}" + # Validate and map variant to compilation envs if [ "$VARIANT" = "x86_64" ]; then TARGET="x86-64-linux-gnu" @@ -47,6 +51,7 @@ DOCKER_IMAGE_NAME="go-librespot-build-${VARIANT}" # Build the image for cross-compilation docker build \ --build-arg "TARGET=$TARGET" \ + --build-arg "VERSION=$VERSION" \ --build-arg "TRIPLET=$TRIPLET" \ --build-arg "GOARCH=$GOARCH" \ --build-arg "GOAMD64=$GOAMD64" \ diff --git a/version.go b/version.go index e41f163..cf30dd8 100644 --- a/version.go +++ b/version.go @@ -9,7 +9,7 @@ import ( const SpotifyVersionCode = 125200442 -var commit, version string +var version string // Extract and return the commit hash stored in the binary, if available. func commitHash() string { @@ -26,8 +26,6 @@ func commitHash() string { func VersionNumberString() string { if len(version) > 0 { return strings.TrimPrefix(version, "v") - } else if len(commit) >= 8 { - return commit[:8] } else if commit := commitHash(); len(commit) >= 8 { return commit[:8] } else { @@ -37,9 +35,7 @@ func VersionNumberString() string { func SpotifyLikeClientVersion() string { if len(version) > 0 { - if len(commit) >= 8 { - return fmt.Sprintf("%s.g%s", version, commit[:8]) - } else if commit := commitHash(); len(commit) >= 8 { + if commit := commitHash(); len(commit) >= 8 { return fmt.Sprintf("%s.g%s", version, commit[:8]) } else { return version