Skip to content

Commit

Permalink
Set version and revision at linked time
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Aug 21, 2022
1 parent 6dfcfc1 commit f05ce44
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions 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

Expand All @@ -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))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion credentials/credentials.go
Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions 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 = ""
)

0 comments on commit f05ce44

Please sign in to comment.