From dd41f863392c38bc7c2df8196b5e84c38fad340c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 5 Jan 2024 13:21:13 +0100 Subject: [PATCH] hack/make: Refactor VERSION normalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turn the if-else tree into a `case`. Signed-off-by: Paweł Gronowski --- hack/make.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/hack/make.sh b/hack/make.sh index 16d5875b83..a913ebed86 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -39,15 +39,12 @@ DEFAULT_BUNDLES=( ) VERSION=${VERSION:-dev} -if [[ $VERSION == refs/tags/v* ]]; then - VERSION=${VERSION#refs/tags/v} -else if [[ $VERSION == refs/tags/* ]]; then - VERSION=${VERSION#refs/tags/} -elif [[ $VERSION == refs/heads/* ]]; then - VERSION=$(sed <<< "${VERSION#refs/heads/}" -r 's#/+#-#g') -elif [[ $VERSION == refs/pull/* ]]; then - VERSION=pr-$(grep <<< "$VERSION" -o '[0-9]\+') -fi +case "$VERSION" in + refs/tags/v*) VERSION=${VERSION#refs/tags/v} ;; + refs/tags/*) VERSION=${VERSION#refs/tags/} ;; + refs/heads/*) VERSION=$(echo "${VERSION#refs/heads/}" | sed -r 's#/+#-#g') ;; + refs/pull/*) VERSION=pr-$(echo "$VERSION" | grep -o '[0-9]\+') ;; +esac ! BUILDTIME=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') if [ "$DOCKER_GITCOMMIT" ]; then