cert-manager/make/git.mk
Maël Valais 3f7bac6ad3 make: rebuild images when a different commit is checked out
When switching branches, the Go files may not change. But since the
images contain the commit hash, e.g.:

  cert-manager-controller-amd64:v1.7.0-beta.0-142-gfc0819af6

It is surprising when trying to deploy to Kind: the git commit that is
checked out does not match the commit hash of the image.

To avoid confusion, I added bin/release-version that gets updated only
when the currently checked out commit changes.

Signed-off-by: Maël Valais <mael@vls.dev>
2022-02-25 16:38:53 +01:00

34 lines
1.4 KiB
Makefile

RELEASE_VERSION := $(shell git describe --tags --match='v*' --abbrev=14)
GITCOMMIT := $(shell git rev-parse HEAD)
IS_TAGGED_RELEASE := $(shell git describe --exact-match HEAD >/dev/null 2>&1 && echo "true" || echo "false")
IS_PRERELEASE := $(shell echo $(RELEASE_VERSION) | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$' - && echo "false" || echo "true")
.PHONY: gitver
gitver:
@echo "Release version: \"$(RELEASE_VERSION)\""
@echo "Is tagged release: \"$(IS_TAGGED_RELEASE)\""
@echo "Is prerelease: \"$(IS_PRERELEASE)\""
@echo "Git commit hash: \"$(GITCOMMIT)\""
# Lists all remote tags on the upstream, which gives tags in format:
# "<commit> ref/tags/<tag>". Strips commit + tag prefix, filters out tags for v1+,
# and manually removes v1.2.0-alpha.1, since that version's manifest contains
# duplicate CRD resources (2 CRDs with the same name) which in turn can cause problems
# with the versionchecker test.
# Open question: how do we decide when to refresh this target?
bin/scratch/git/upstream-tags.txt: | bin/scratch/git
git ls-remote --tags --refs https://github.com/cert-manager/cert-manager.git | \
awk '{print $$2;}' | \
sed 's/refs\/tags\///' | \
sed -n '/v1.0.0/,$$p' | \
grep -v "v1.2.0-alpha.1" > $@
bin/release-version: | bin
@test "$(RELEASE_VERSION)" == "$$(cat "$@" 2>/dev/null)" || echo $(RELEASE_VERSION) > $@
bin/scratch/git:
@mkdir -p $@