From 3f0313b9949f7f1808f14d33ae583313b5f438bc Mon Sep 17 00:00:00 2001 From: Rio Martinez <35539750+rioam2@users.noreply.github.com> Date: Thu, 10 Oct 2019 20:07:32 -0500 Subject: [PATCH] projects without staging env fallback to prod (#91) --- package.json | 2 +- scripts/loadenv.js | 1 + scripts/test.sh | 16 +++++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a445189..32d73ae 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "preview:staging": "cross-env NODE_ENV=production yarn loadenv ./scripts/preview.sh", "setup": "./scripts/setup.js", "test": "yarn test:unit && yarn test:cypress", - "test:cypress": "start-server-and-test 'yarn preview:staging > /dev/null' 3000 'cypress run'", + "test:cypress": "yarn loadenv yarn start-server-and-test '[ -z %STATIC_STAGE_PROJECT ] && yarn preview:production > /dev/null || yarn preview:staging > /dev/null' 3000 'cypress run'", "test:cypress:watch": "start-server-and-test 'yarn dev > /dev/null' 3000 'cypress open'", "test:unit": "mocha ./**/*.unit.test.ts", "test:unit:watch": "yarn test:unit --watch", diff --git a/scripts/loadenv.js b/scripts/loadenv.js index 5f605e4..762f599 100755 --- a/scripts/loadenv.js +++ b/scripts/loadenv.js @@ -19,6 +19,7 @@ const { exec } = require('child_process'); const mergedEnv = { ...dotenv.parsed, ...process.env }; const command = process.argv .slice(2) + .map((arg) => (arg.includes(' ') && `'${arg}'`) || arg) .join(' ') .replace(/\%\S+/g, (match) => `"${mergedEnv[match.slice(1)] || ''}"`); diff --git a/scripts/test.sh b/scripts/test.sh index caf6220..0f5a1de 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,16 +2,18 @@ set -e -if [[ $TRAVIS_SECURE_ENV_VARS == 'true' ]]; then - yarn test - - # Continuous Deployment for staging/production - if [[ $TRAVIS_BRANCH == 'master' ]]; then - if [[ $TRAVIS_PULL_REQUEST == 'false' ]]; then +yarn test + +# Continuous Deployment for staging/production +if [[ $TRAVIS_BRANCH == 'master' ]]; then + if [[ $TRAVIS_PULL_REQUEST == 'false' ]]; then + if [[ ! -z $STATIC_PROD_PROJECT ]] && [[ ! -z $STATIC_DEPLOY_KEY ]]; then # If tests passed on master and not a PR, deploy to production yarn deploy:production wget "https://$STATIC_PROD_PROJECT.web.app" -O /dev/null - else + fi + else + if [[ ! -z $STATIC_STAGE_PROJECT ]] && [[ ! -z $STATIC_DEPLOY_KEY ]]; then # If tests passed on master for PR, deploy to staging yarn deploy:staging wget "https://$STATIC_STAGE_PROJECT.web.app" -O /dev/null