From ac885b855a90b26faab28d45cf54ec664360f79a Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 6 Nov 2021 03:16:02 -0400 Subject: [PATCH] Ensure all helper scripts pushd/popd Make sure all of these move to the root of the repository first, then return to where they were afterwards, using pushd/popd. This allows them to be executed from anywhere in the repo. --- build-and-deploy.sh | 5 +++++ build-deb.sh | 2 ++ build-unstable-deb.sh | 2 ++ bump-version | 4 ++++ format | 4 ++++ gen-api-migrations | 6 ++++-- gen-zk-migrations | 6 ++++-- lint | 4 ++++ 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/build-and-deploy.sh b/build-and-deploy.sh index 82524886..ca1daf24 100755 --- a/build-and-deploy.sh +++ b/build-and-deploy.sh @@ -27,6 +27,9 @@ fi HOSTS=( ${@} ) echo "> Deploying to host(s): ${HOSTS[@]}" +# Move to repo root if we're not +pushd $( git rev-parse --show-toplevel ) &>/dev/null + # Prepare code echo "Preparing code (format and lint)..." ./prepare || exit @@ -64,3 +67,5 @@ done if [[ -z ${KEEP_ARTIFACTS} ]]; then rm ../pvc*_${version}* fi + +popd &>/dev/null diff --git a/build-deb.sh b/build-deb.sh index ad0de68a..47a4077a 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -1,4 +1,5 @@ #!/bin/sh +pushd $( git rev-parse --show-toplevel ) &>/dev/null ver="$( head -1 debian/changelog | awk -F'[()-]' '{ print $2 }' )" git pull rm ../pvc_* @@ -6,3 +7,4 @@ find . -name "__pycache__" -exec rm -r {} \; dh_make -p pvc_${ver} --createorig --single --yes dpkg-buildpackage -us -uc dh_clean +popd &>/dev/null diff --git a/build-unstable-deb.sh b/build-unstable-deb.sh index 3635b70d..f2214ae8 100755 --- a/build-unstable-deb.sh +++ b/build-unstable-deb.sh @@ -2,6 +2,7 @@ set -o xtrace exec 3>&1 exec 1>&2 +pushd $( git rev-parse --show-toplevel ) &>/dev/null # Ensure we're up to date git pull --rebase # Update the version to a sensible git revision for easy visualization @@ -37,3 +38,4 @@ cp -a ${tmpdir}/api-Daemon.py api-daemon/pvcapid/Daemon.py # Clean up rm -r ${tmpdir} dh_clean +popd &>/dev/null diff --git a/bump-version b/bump-version index 5bbbc6c6..fb819f76 100755 --- a/bump-version +++ b/bump-version @@ -7,6 +7,8 @@ if [[ -z ${new_version} ]]; then exit 1 fi +pushd $( git rev-parse --show-toplevel ) &>/dev/null + current_version="$( cat .version )" echo "${current_version} -> ${new_version}" @@ -47,6 +49,8 @@ mv ${deb_changelog_file} debian/changelog git add node-daemon/pvcnoded/Daemon.py api-daemon/pvcapid/Daemon.py client-cli/setup.py debian/changelog CHANGELOG.md .version git commit -v +popd &>/dev/null + echo echo "GitLab release message:" echo diff --git a/format b/format index a5304949..22b684e1 100755 --- a/format +++ b/format @@ -5,10 +5,14 @@ if ! which black &>/dev/null; then exit 1 fi +pushd $( git rev-parse --show-toplevel ) &>/dev/null + echo "Formatting..." black --safe --exclude api-daemon/migrations . ret=$? if [[ $ret -eq 0 ]]; then echo "Successfully formatted project!" fi + +popd &>/dev/null exit $ret diff --git a/gen-api-migrations b/gen-api-migrations index 03f8cb89..be0fb733 100755 --- a/gen-api-migrations +++ b/gen-api-migrations @@ -4,8 +4,10 @@ VERSION="$( head -1 debian/changelog | awk -F'[()-]' '{ print $2 }' )" -pushd api-daemon +pushd $( git rev-parse --show-toplevel ) &>/dev/null +pushd api-daemon &>/dev/null export PVC_CONFIG_FILE="./pvcapid.sample.yaml" ./pvcapid-manage.py db migrate -m "PVC version ${VERSION}" ./pvcapid-manage.py db upgrade -popd +popd &>/dev/null +popd &>/dev/null diff --git a/gen-zk-migrations b/gen-zk-migrations index c64bb8c0..17a7b95b 100755 --- a/gen-zk-migrations +++ b/gen-zk-migrations @@ -2,6 +2,8 @@ # Generate the Zookeeper migration files -pushd api-daemon +pushd $( git rev-parse --show-toplevel ) &>/dev/null +pushd api-daemon &>/dev/null ./pvcapid-manage-zk.py -popd +popd &>/dev/null +popd &>/dev/null diff --git a/lint b/lint index 4369364a..a38e1d4b 100755 --- a/lint +++ b/lint @@ -5,10 +5,14 @@ if ! which flake8 &>/dev/null; then exit 1 fi +pushd $( git rev-parse --show-toplevel ) &>/dev/null + echo "Linting..." flake8 ret=$? if [[ $ret -eq 0 ]]; then echo "No linting issues found!" fi + +popd &>/dev/null exit $ret