From 4a2455e5f02e1de5eb21391f94d1944e195d69af Mon Sep 17 00:00:00 2001 From: "Dennis J. Bell" Date: Mon, 7 Oct 2024 14:36:13 -0700 Subject: [PATCH] Improved package script workflow * moved variable declarations to the top of the script * added a `package_version` variable to store the version of the package * fixed logic to create the package in the correct directory * cleaned up the exit_trap function to remove the temporary files if they exist --- bin/package | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bin/package b/bin/package index a04420394..7612cfd6c 100755 --- a/bin/package +++ b/bin/package @@ -1,7 +1,18 @@ #!/usr/bin/env bash +# shellcheck disable=SC2317 set -xeuo pipefail +declare git_url git_tag work_dir +declare -x TAG NODE_VERSION TMP_DIR + +git_url="https://github.com/cloudfoundry-community/stratos.git" +git_tag="${TAG:-develop}" +work_dir="${PWD}" +NODE_VERSION="${NODE_VERISON:-20.13.1}" +NODE_SHA2="${NODE_SHA2:-71ec5c92b35770170dad21ff65130f3e4201e8a0bcd32986e5dcf32b57f379e6}" +TMP_DIR=/tmp + node::install() { local download_file download_file="${TMP_DIR}/node${NODE_VERSION}.tar.gz" @@ -21,15 +32,14 @@ node::install() { # source: https://nodejs.org/dist/v20.13.1/node-v20.13.1.tar.gz # source_sha256: a85ee53aa0a5c2f5ca94fa414cdbceb91eb7d18a77fc498358512c14cc6c6991 - NODE_SHA2="71ec5c92b35770170dad21ff65130f3e4201e8a0bcd32986e5dcf32b57f379e6" URL=https://buildpacks.cloudfoundry.org/dependencies/node/node_${NODE_VERSION}_linux_x64_cflinuxfs4_71ec5c92.tgz echo "-----> Download Nodejs ${NODE_VERSION}" - curl -s -L --retry 15 --retry-delay 2 $URL -o ${download_file} + curl -s -L --retry 15 --retry-delay 2 "$URL" -o "${download_file}" - DOWNLOAD_SHA2=$(sha256sum ${download_file} | cut -d ' ' -f 1) + DOWNLOAD_SHA2=$(sha256sum "${download_file}" | cut -d ' ' -f 1) - if [[ ${DOWNLOAD_SHA2} != ${NODE_SHA2} ]]; then + if [[ ${DOWNLOAD_SHA2} != "${NODE_SHA2}" ]]; then echo " **ERROR** MD5 mismatch: got $DOWNLOAD_SHA2 expected $NODE_SHA2" exit 1 fi @@ -46,14 +56,6 @@ node::install() { export NODE_HOME="${node_install_dir}" } -declare git_url git_tag work_dir -declare -x TAG NODE_VERSION TMP_DIR - -git_url="https://github.com/cloudfoundry-community/stratos.git" -git_tag="${TAG:-develop}" -work_dir="${PWD}" -NODE_VERSION="${NODE_VERISON:-20.13.1}" -TMP_DIR=/tmp if [[ -z ${USE_LOCAL:-""} ]] ; then @@ -73,10 +75,10 @@ if [[ -z ${VERSION:-""} ]] ; then export stratos_version="${VERSION}" # Will be tagged on publish in Concourse fi -function exit_trap() { +exit_trap() { # See: install_nodejs.sh - NODE_VERSION="20.13.1" - rm -rf "/tmp/node${NODE_VERSION}.tar.gz" "/tmp/node${NODE_VERSION}" + [[ -d "${TMP_DIR}/node${NODE_VERSION}" ]] && rm -rf "${TMP_DIR}/node${NODE_VERSION}" + [[ -f "${TMP_DIR}/node${NODE_VERSION}.tar.gz" ]] && rm -rf "${TMP_DIR}/node${NODE_VERSION}.tar.gz" } trap exit_trap EXIT @@ -117,10 +119,11 @@ echo "web: ./deploy/cloud-foundry/start.sh" > "${build_dir}/Procfile" ls -lah "${build_dir}" cd "${build_dir}" -if [[ -z ${BUILD_ROOT:-"" } ]] ; then - zip -r -x@exclude.lst "${BUILD_ROOT}/stratos-ui-packaged.zip" ./* +package_version="${stratos_version:-"dev-$(date +%Y%m%d%H%M%S)"}" +if [[ -n ${RELEASE_DIR:-""} ]] ; then + zip -r -x@exclude.lst "${RELEASE_DIR}/stratos-ui-${package_version}.zip" ./* else - zip -r -x@exclude.lst "${work_dir}/stratos-ui-packaged.zip" ./* + zip -r -x@exclude.lst "${work_dir}/stratos-ui-${package_version}.zip" ./* fi cd "${work_dir}"