From d74a61dfc43d5a162b718c294a4f674ca02c8807 Mon Sep 17 00:00:00 2001 From: Timothy Jones Date: Mon, 24 Jun 2019 14:44:30 +1000 Subject: [PATCH] chore: improve bash script robustness --- scripts/build.sh | 5 +++-- scripts/create_npmrc_file.sh | 4 +++- scripts/prepare.sh | 8 ++++---- scripts/publish.sh | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 62ed2f503..84b838c99 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" npm run dist -${DIR}/prepare.sh +"${DIR}"/prepare.sh # Link the build so that the examples are always testing the # current build, in it's properly exported format @@ -12,10 +12,11 @@ ${DIR}/prepare.sh echo "Running e2e examples build for node version ${TRAVIS_NODE_VERSION}" for i in examples/*; do + [ -e "$i" ] || continue # prevent failure if there are no examples echo "------------------------------------------------" echo "------------> continuing to test example project: $i" cd "$i" - if [[ $i =~ "karma" ]]; then + if [[ "$i" =~ "karma" ]]; then echo "linking pact-web" npm link @pact-foundation/pact-web else diff --git a/scripts/create_npmrc_file.sh b/scripts/create_npmrc_file.sh index 998bb58d4..6db6bce6e 100755 --- a/scripts/create_npmrc_file.sh +++ b/scripts/create_npmrc_file.sh @@ -1,7 +1,9 @@ +#!/bin/bash -e + set +x #Don't echo the NPM key NPMRC_FILE=.npmrc -echo "@pact-foundation:registry=https://registry.npmjs.org/" > $NPMRC_FILE +echo "@pact-foundation:registry=https://registry.npmjs.org/" > $NPMRC_FILE echo "//registry.npmjs.org/:_authToken=${NPM_KEY}" >> $NPMRC_FILE echo "//registry.npmjs.org/:username=pact-foundation" >> $NPMRC_FILE echo "//registry.npmjs.org/:email=pact-foundation@googlegroups.com" >> $NPMRC_FILE diff --git a/scripts/prepare.sh b/scripts/prepare.sh index f8fb65155..8f1a19c94 100755 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -9,9 +9,9 @@ artifacts=(LICENSE *md package.json) for artifact in "${artifacts[@]}"; do echo " Copying ${artifact} => ./dist/${artifact}" - cp ${artifact} ./dist/${artifact} + cp "${artifact}" "./dist/${artifact}" echo " Copying ${artifact} => ./dist-web/${artifact}" - cp ${artifact} ./dist-web/${artifact} + cp "${artifact}" "./dist-web/${artifact}" done echo "--> Creating pact-web package" @@ -21,7 +21,7 @@ sed "s/VERSION/${VERSION}/g" < package.json.web > dist-web/package.json types=( $(find dist -name "*.d.ts" | grep -v node_modules | sed 's/dist\///') ) for type in "${types[@]}"; do echo " Copying ${type} => ./dist-web/${type}" - echo "creating dir: " $(dirname "./dist-web/${type}") - mkdir -p $(dirname "./dist-web/${type}") + echo "creating dir: $(dirname "./dist-web/${type}")" + mkdir -p "$(dirname "./dist-web/${type}")" cp -r "dist/${type}" "./dist-web/${type}" done \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh index 9a777f9ea..5a4b8a27f 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -2,7 +2,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -${DIR}/prepare.sh +"${DIR}"/prepare.sh VERSION=$(grep '\"version\"' package.json | grep -E -o "([0-9\.]+(-[a-z\.0-9]+)?)") echo "--> Releasing version ${VERSION}"