Skip to content

Commit 48fc5b4

Browse files
authored
Merge pull request #243 from tricktron/f-inject-version-from-tags
Inject Version From Tags
2 parents d6688c1 + 7a730e3 commit 48fc5b4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ MANINSTALLDIR=${PREFIX}/share/man
77
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
88
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
99
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}")
10+
VERSION := $(shell git describe --tags --always | cut -c 2-)
1011
DOCKER_IMAGE := manifest-tool-dev$(if $(GIT_BRANCH),:$(GIT_BRANCH))
1112
# set env like gobuildtag?
1213
DOCKER_RUN := docker run --rm -i #$(DOCKER_ENVS)
@@ -22,17 +23,19 @@ DOCKER_RUN_DOCKER := $(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/man
2223
all: binary
2324

2425
build:
25-
$(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/manifest-tool -w /go/src/github.com/estesp/manifest-tool golang:1.17 /bin/bash -c "\
26-
cd v2 && go build -ldflags \"-X main.gitCommit=${COMMIT}\" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool"
26+
$(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/manifest-tool -w /go/src/github.com/estesp/manifest-tool golang:1.20 /bin/bash -c "\
27+
cd v2 && go build -ldflags \"-X main.gitCommit=${COMMIT} main.version=${VERSION}\" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool"
2728

2829
# Target to build a dynamically linked binary
2930
binary: v2/pkg/util/oslist.go
30-
cd v2 && go build -ldflags "-X main.gitCommit=${COMMIT}" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
31+
cd v2 && go build \
32+
-ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" \
33+
-o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
3134

3235
# Target to build a statically linked binary
3336
static: v2/pkg/util/oslist.go
3437
cd v2 && GO_EXTLINK_ENABLED=0 CGO_ENABLED=0 go build \
35-
-ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT}" \
38+
-ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" \
3639
-tags netgo -installsuffix netgo \
3740
-o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
3841

v2/cmd/manifest-tool/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
// filled in at compile time
1414
var gitCommit = ""
15+
var version = ""
1516

1617
const (
17-
version = "2.1.2"
1818
usage = "registry client to inspect and push multi-platform OCI & Docker v2 images"
1919
)
2020

0 commit comments

Comments
 (0)