浏览代码

hack/make: Refactor VERSION normalization

Turn the if-else tree into a `case`.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 1 年之前
父节点
当前提交
dd41f86339
共有 1 个文件被更改,包括 6 次插入9 次删除
  1. 6 9
      hack/make.sh

+ 6 - 9
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