From e9d590264bab45b707b3ad5fa4d5c0632d7a365e Mon Sep 17 00:00:00 2001 From: Hongcai Ren Date: Tue, 8 Dec 2020 10:06:32 +0800 Subject: [PATCH] Enable detect version by git tags (#63) --- .github/workflows/ci.yml | 4 ++++ Makefile | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd5d045c9..5c2c95ad0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,10 @@ jobs: steps: - name: checkout code uses: actions/checkout@v2 + with: + # Number of commits to fetch. 0 indicates all history for all branches and tags. + # We need to guess version via git tags. + fetch-depth: 0 - name: install Go uses: actions/setup-go@v2 with: diff --git a/Makefile b/Makefile index de13549c1..b23749932 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,20 @@ REGISTRY_USER_NAME?="" REGISTRY_PASSWORD?="" REGISTRY_SERVER_ADDRESS?="" -# Set you version by env or using latest tags from git -VERSION?=$(shell git describe --tags) - -# We don't have tags yet, so just use hardcode one -VERSION="latest" +# Set your version by env or using latest tags from git +VERSION?="" +ifeq ($(VERSION), "") + $(info "Guessing version from git latest tags...") + LATEST_TAG=$(shell git describe --tags) + ifeq ($(LATEST_TAG),) + # Forked repo may not sync tags from upstream, so give it a default tag to make CI happy. + $(info "no tags found, set version with unknown") + VERSION="unknown" + else + $(info "using latest git tag($(LATEST_TAG)) as version") + VERSION=$(LATEST_TAG) + endif +endif all: karmada-controller-manager karmadactl