diff --git a/Dockerfile b/Dockerfile index f6358cba..13ab23d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,6 @@ ARG XX_VERSION=1.1.2 ARG OSXCROSS_VERSION=11.3-r7-alpine ARG GOLANGCI_LINT_VERSION=v1.47.3 -ARG PKG=github.com/docker/docker-credential-helpers - # xx is a helper for cross-compilation FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx @@ -58,10 +56,9 @@ RUN --mount=type=bind,target=. \ golangci-lint run ./... FROM gobase AS version -ARG PKG RUN --mount=target=. \ - VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags); \ - echo "-s -w -X ${PKG}/credentials.Version=${VERSION}" | tee /tmp/.ldflags; \ + PKG=github.com/docker/docker-credential-helpers VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \ + echo "-s -w -X ${PKG}/credentials.Version=${VERSION} -X ${PKG}/credentials.Revision=${REVISION} -X ${PKG}/credentials.Package=${PKG}" | tee /tmp/.ldflags; \ echo -n "${VERSION}" | tee /tmp/.version; FROM gobase AS base diff --git a/Makefile b/Makefile index 36f8a764..24129a4b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ .PHONY: all osxkeychain secretservice test lint validate-vendor fmt validate wincred pass deb vendor -VERSION := $(shell grep 'const Version' credentials/version.go | awk -F'"' '{ print $$2 }') +PKG := github.com/docker/docker-credential-helpers +VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags) +REVISION ?= $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) + +LDFLAGS="-s -w -X ${PKG}/credentials.Version=${VERSION} -X ${PKG}/credentials.Revision=${REVISION} -X ${PKG}/credentials.Package=${PKG}" all: test @@ -10,7 +14,7 @@ clean: osxkeychain: mkdir -p bin - go build -ldflags -s -o bin/docker-credential-osxkeychain osxkeychain/cmd/ + go build -ldflags=$(LDFLAGS) -o bin/docker-credential-osxkeychain ./osxkeychain/cmd/ osxcodesign: osxkeychain $(eval SIGNINGHASH = $(shell security find-identity -v -p codesigning | grep "Developer ID Application: Docker Inc" | cut -d ' ' -f 4)) @@ -19,28 +23,28 @@ osxcodesign: osxkeychain secretservice: mkdir -p bin - go build -o bin/docker-credential-secretservice secretservice/cmd/ + go build -ldflags=$(LDFLAGS) -o bin/docker-credential-secretservice ./secretservice/cmd/ pass: mkdir -p bin - go build -o bin/docker-credential-pass pass/cmd/ + go build -ldflags=$(LDFLAGS) -o bin/docker-credential-pass ./pass/cmd/ wincred: mkdir -p bin - go build -o bin/docker-credential-wincred.exe wincred/cmd/ + go build -ldflags=$(LDFLAGS) -o bin/docker-credential-wincred.exe ./wincred/cmd/ linuxrelease: mkdir -p release - cd bin && tar cvfz ../release/docker-credential-pass-v$(VERSION)-amd64.tar.gz docker-credential-pass - cd bin && tar cvfz ../release/docker-credential-secretservice-v$(VERSION)-amd64.tar.gz docker-credential-secretservice + cd bin && tar cvfz ../release/docker-credential-pass-amd64.tar.gz docker-credential-pass + cd bin && tar cvfz ../release/docker-credential-secretservice-amd64.tar.gz docker-credential-secretservice osxrelease: mkdir -p release - cd bin && tar cvfz ../release/docker-credential-osxkeychain-v$(VERSION)-amd64.tar.gz docker-credential-osxkeychain + cd bin && tar cvfz ../release/docker-credential-osxkeychain-amd64.tar.gz docker-credential-osxkeychain winrelease: mkdir -p release - cd bin && zip ../release/docker-credential-wincred-v$(VERSION)-amd64.zip docker-credential-wincred.exe + cd bin && zip ../release/docker-credential-wincred-amd64.zip docker-credential-wincred.exe test: # tests all packages except vendor diff --git a/credentials/credentials.go b/credentials/credentials.go index 58014ad5..330130a4 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -181,6 +181,6 @@ func List(helper Helper, writer io.Writer) error { // PrintVersion outputs the current version. func PrintVersion(writer io.Writer) error { - fmt.Fprintln(writer, Version) + fmt.Fprintln(writer, Package, Version, Revision) return nil } diff --git a/credentials/version.go b/credentials/version.go index 185e3679..ac0f2e19 100644 --- a/credentials/version.go +++ b/credentials/version.go @@ -1,4 +1,13 @@ package credentials -// Version holds a string describing the current version -const Version = "0.6.4" +var ( + // Package is filled at linking time + Package = "github.com/docker/docker-credential-helpers" + + // Version holds the complete version number. Filled in at linking time. + Version = "v0.0.0+unknown" + + // Revision is filled with the VCS (e.g. git) revision being used to build + // the program at linking time. + Revision = "" +)