From 47140c2d81843093c6aa01121270b6f80fa7c8d6 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Thu, 22 Dec 2022 11:27:25 +0000 Subject: [PATCH] feat: append branch into tags if not main --- podman.mk | 15 +++++++++++---- vars/buildPodman.groovy | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/podman.mk b/podman.mk index f3f7b48..55cff91 100644 --- a/podman.mk +++ b/podman.mk @@ -1,12 +1,19 @@ # Parse version from latest git semver tag BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) -GIT_TAG=$(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) -TAG ?= $(shell echo $(GIT_TAG) | awk -F '-' '{ print $$1 "-" $$2 }' | sed -e 's/-$$//') -# EXTRA_TAGS supposed to be set at the caller, eg. $(shell echo $(TAG) | awk -F '.' '{ print $$1 "." $$2 }') +GIT_TAG := $(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) +TAG := $(GIT_TAG) + +# append branch name to tag if NOT main nor master +ifeq (,$(filter main master, $(BRANCH))) + TAG = $(GIT_TAG)-$(BRANCH) +endif + +# optionally set by the caller +EXTRA_TAGS := ARCH := amd64 ALL_ARCHS := amd64 arm64 -_ARCH = $(or $(filter ${ARCH},${ALL_ARCHS}),$(error $$ARCH [${ARCH}] must be exactly one of ${ALL_ARCHS})) +_ARCH = $(or $(filter $(ARCH),$(ALL_ARCHS)),$(error $$ARCH [$(ARCH)] must be exactly one of "$(ALL_ARCHS)")) ifneq ($(TRIVY_REMOTE),) TRIVY_OPTS := --server $(TRIVY_REMOTE) diff --git a/vars/buildPodman.groovy b/vars/buildPodman.groovy index ca43934..e5ecff9 100644 --- a/vars/buildPodman.groovy +++ b/vars/buildPodman.groovy @@ -10,6 +10,7 @@ def call(Map config=[:]) { stages { stage('Prepare') { steps { + // pull tags withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) { sh 'git fetch -q --tags ${GIT_URL}' }