Browse Source

scripts/release: Apply shellcheck findings

I run https://github.com/koalaman/shellcheck/ over scripts/* and fixed
the findings it returned.

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
Manuel Rüger 6 years ago
parent
commit
d981fe6b6b
1 changed files with 36 additions and 31 deletions
  1. 36 31
      scripts/release

+ 36 - 31
scripts/release

@@ -5,7 +5,7 @@ set -o nounset
 set -o pipefail
 set -o pipefail
 
 
 help() {
 help() {
-  echo "$(basename $0) [version]"
+  echo "$(basename "$0") [version]"
   echo "Release etcd using the same approach as the etcd-release-runbook (https://goo.gl/Gxwysq)"
   echo "Release etcd using the same approach as the etcd-release-runbook (https://goo.gl/Gxwysq)"
   echo ""
   echo ""
   echo "WARNING: This does not perform the 'Add API capabilities', 'Performance testing' "
   echo "WARNING: This does not perform the 'Add API capabilities', 'Performance testing' "
@@ -56,25 +56,28 @@ main() {
   cd "${reldir}/etcd"
   cd "${reldir}/etcd"
 
 
   # If a release version tag already exists, use it.
   # If a release version tag already exists, use it.
-  local remote_tag_exists=$(git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}")
-  if [ ${remote_tag_exists} -gt 0 ]; then
+  local remote_tag_exists
+  remote_tag_exists=$(git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}")
+  if [ "${remote_tag_exists}" -gt 0 ]; then
     echo "Release version tag exists on remote. Checking out refs/tags/${RELEASE_VERSION}"
     echo "Release version tag exists on remote. Checking out refs/tags/${RELEASE_VERSION}"
     git checkout -q "tags/${RELEASE_VERSION}"
     git checkout -q "tags/${RELEASE_VERSION}"
   fi
   fi
 
 
   # Check go version.
   # Check go version.
   # download "yq" from https://github.com/mikefarah/yq
   # download "yq" from https://github.com/mikefarah/yq
-  local go_version="go$(yq read .travis.yml "go[0]")"
-  local current_go_version=$(go version | awk '{ print $3 }')
+  local go_version current_go_version
+  go_version="go$(yq read .travis.yml "go[0]")"
+  current_go_version=$(go version | awk '{ print $3 }')
   if [[ "${current_go_version}" != "${go_version}" ]]; then
   if [[ "${current_go_version}" != "${go_version}" ]]; then
     echo "Current go version is ${current_go_version}, but etcd ${RELEASE_VERSION} requires ${go_version} (see .travis.yml)."
     echo "Current go version is ${current_go_version}, but etcd ${RELEASE_VERSION} requires ${go_version} (see .travis.yml)."
     exit 1
     exit 1
   fi
   fi
 
 
   # If the release tag does not already exist remotely, create it.
   # If the release tag does not already exist remotely, create it.
-  if [ ${remote_tag_exists} -eq 0 ]; then
+  if [ "${remote_tag_exists}" -eq 0 ]; then
     # Bump version/version.go to release version.
     # Bump version/version.go to release version.
-    local source_version=$(egrep "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
+    local source_version
+    source_version=$(grep -E "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
     if [[ "${source_version}" != "${VERSION}" ]]; then
     if [[ "${source_version}" != "${VERSION}" ]]; then
       source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
       source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
       if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
       if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
@@ -87,13 +90,14 @@ main() {
 
 
     echo "Building etcd and checking --version output"
     echo "Building etcd and checking --version output"
     ./build
     ./build
-    local etcd_version=$(bin/etcd --version | grep "etcd Version" | awk '{ print $3 }')
+    local etcd_version
+    etcd_version=$(bin/etcd --version | grep "etcd Version" | awk '{ print $3 }')
     if [[ "${etcd_version}" != "${VERSION}" ]]; then
     if [[ "${etcd_version}" != "${VERSION}" ]]; then
       echo "Wrong etcd version in version/version.go. Expected ${etcd_version} but got ${VERSION}. Aborting."
       echo "Wrong etcd version in version/version.go. Expected ${etcd_version} but got ${VERSION}. Aborting."
       exit 1
       exit 1
     fi
     fi
 
 
-    if [[ ! -z $(git status -s) ]]; then
+    if [[ -n $(git status -s) ]]; then
       echo "Committing version/version.go update."
       echo "Committing version/version.go update."
       git add version/version.go
       git add version/version.go
       git commit -m "version: bump up to ${VERSION}"
       git commit -m "version: bump up to ${VERSION}"
@@ -101,14 +105,14 @@ main() {
     fi
     fi
 
 
     # Push the version change if it's not already been pushed.
     # Push the version change if it's not already been pushed.
-    if [ $(git rev-list --count "origin/${BRANCH}..${BRANCH}") -gt 0 ]; then
-      read -p "Push version bump up to ${VERSION} to github.com/etcd-io/etcd [y/N]? " confirm
+    if [ "$(git rev-list --count "origin/${BRANCH}..${BRANCH}")" -gt 0 ]; then
+      read -pr "Push version bump up to ${VERSION} to github.com/etcd-io/etcd [y/N]? " confirm
       [[ "${confirm,,}" == "y" ]] || exit 1
       [[ "${confirm,,}" == "y" ]] || exit 1
       git push
       git push
     fi
     fi
 
 
     # Tag release.
     # Tag release.
-    if [ $(git tag --list | grep -c "${RELEASE_VERSION}") -gt 0 ]; then
+    if [ "$(git tag --list | grep -c "${RELEASE_VERSION}")" -gt 0 ]; then
       echo "Skipping tag step. git tag ${RELEASE_VERSION} already exists."
       echo "Skipping tag step. git tag ${RELEASE_VERSION} already exists."
     else
     else
       echo "Tagging release..."
       echo "Tagging release..."
@@ -116,7 +120,7 @@ main() {
     fi
     fi
 
 
     # Push the tag change if it's not already been pushed.
     # Push the tag change if it's not already been pushed.
-    read -p "Push etcd ${RELEASE_VERSION} tag [y/N]? " confirm
+    read -pr "Push etcd ${RELEASE_VERSION} tag [y/N]? " confirm
     [[ "${confirm,,}" == "y" ]] || exit 1
     [[ "${confirm,,}" == "y" ]] || exit 1
     git push origin "tags/${RELEASE_VERSION}"
     git push origin "tags/${RELEASE_VERSION}"
   fi
   fi
@@ -137,13 +141,13 @@ main() {
   fi
   fi
 
 
   # Sanity checks.
   # Sanity checks.
-  ./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcd --version | grep -q "etcd Version: ${VERSION}" || true
-  ./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcdctl version | grep -q "etcdctl version: ${VERSION}" || true
+  "./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcd" --version | grep -q "etcd Version: ${VERSION}" || true
+  "./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcdctl" version | grep -q "etcdctl version: ${VERSION}" || true
 
 
   # Generate SHA256SUMS
   # Generate SHA256SUMS
   echo -e "Generating sha256sums of release artifacts.\n"
   echo -e "Generating sha256sums of release artifacts.\n"
   pushd ./release
   pushd ./release
-  ls . | grep -E '\.tar.gz$|\.zip$' | xargs shasum -a 256 > ./SHA256SUMS
+  grep . -E '\.tar.gz$|\.zip$' | xargs shasum -a 256 > ./SHA256SUMS
   popd
   popd
   if [ -s ./release/SHA256SUMS ]; then
   if [ -s ./release/SHA256SUMS ]; then
     cat ./release/SHA256SUMS
     cat ./release/SHA256SUMS
@@ -156,38 +160,39 @@ main() {
   if [ "${NO_UPLOAD}" == 1 ]; then
   if [ "${NO_UPLOAD}" == 1 ]; then
     echo "Skipping artifact upload to gs://etcd. --no-upload flat is set."
     echo "Skipping artifact upload to gs://etcd. --no-upload flat is set."
   else
   else
-    read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
+    read -pr "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
     [[ "${confirm,,}" == "y" ]] || exit 1
     [[ "${confirm,,}" == "y" ]] || exit 1
-    gsutil -m cp ./release/SHA256SUMS gs://etcd/${RELEASE_VERSION}/
-    gsutil -m cp ./release/*.zip gs://etcd/${RELEASE_VERSION}/
-    gsutil -m cp ./release/*.tar.gz gs://etcd/${RELEASE_VERSION}/
-    gsutil -m acl ch -u allUsers:R -r gs://etcd/${RELEASE_VERSION}/
+    gsutil -m cp ./release/SHA256SUMS "gs://etcd/${RELEASE_VERSION}/"
+    gsutil -m cp ./release/*.zip "gs://etcd/${RELEASE_VERSION}/"
+    gsutil -m cp ./release/*.tar.gz "gs://etcd/${RELEASE_VERSION}/"
+    gsutil -m acl ch -u allUsers:R -r "gs://etcd/${RELEASE_VERSION}/"
   fi
   fi
 
 
   # Push images.
   # Push images.
   if [ "${NO_DOCKER_PUSH}" == 1 ]; then
   if [ "${NO_DOCKER_PUSH}" == 1 ]; then
     echo "Skipping docker push. --no-docker-push flat is set."
     echo "Skipping docker push. --no-docker-push flat is set."
   else
   else
-    read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
+    read -pr "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
     [[ "${confirm,,}" == "y" ]] || exit 1
     [[ "${confirm,,}" == "y" ]] || exit 1
+    # shellcheck disable=SC2034
     for i in {1..5}; do
     for i in {1..5}; do
       docker login quay.io && break
       docker login quay.io && break
       echo "login failed, retrying"
       echo "login failed, retrying"
     done
     done
     gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
     gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
 
 
-    echo "Pushing container images to quay.io" ${RELEASE_VERSION}
-    docker push quay.io/coreos/etcd:${RELEASE_VERSION}
+    echo "Pushing container images to quay.io ${RELEASE_VERSION}"
+    docker push "quay.io/coreos/etcd:${RELEASE_VERSION}"
 
 
-    echo "Pushing container images to gcr.io" ${RELEASE_VERSION}
-    gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}
+    echo "Pushing container images to gcr.io ${RELEASE_VERSION}"
+    gcloud docker -- "push gcr.io/etcd-development/etcd:${RELEASE_VERSION}"
 
 
     for TARGET_ARCH in "-arm64" "-ppc64le"; do
     for TARGET_ARCH in "-arm64" "-ppc64le"; do
-      echo "Pushing container images to quay.io" ${RELEASE_VERSION}${TARGET_ARCH}
-      docker push quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}
+      echo "Pushing container images to quay.io ${RELEASE_VERSION}${TARGET_ARCH}"
+      docker push "quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}"
 
 
-      echo "Pushing container images to gcr.io" ${RELEASE_VERSION}${TARGET_ARCH}
-      gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}
+      echo "Pushing container images to gcr.io ${RELEASE_VERSION}${TARGET_ARCH}"
+      gcloud docker -- push "gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}"
     done
     done
 
 
     echo "Setting permissions using gsutil..."
     echo "Setting permissions using gsutil..."
@@ -234,4 +239,4 @@ if [[ ! $# -eq 1 ]]; then
   exit 1
   exit 1
 fi
 fi
 
 
-main $1
+main "$1"