diff --git a/script/ci/includes.sh b/script/ci/includes.sh index d7619f7d23..497959d33b 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -19,6 +19,21 @@ function succeed_if_master_merged { fi } +function set_ofn_commit { + echo "Setting commit to $1" + buildkite-agent meta-data set "openfoodnetwork:git:commit" $1 +} + +function get_ofn_commit { + echo `buildkite-agent meta-data get "openfoodnetwork:git:commit"` +} + +function checkout_ofn_commit { + OFN_COMMIT=`buildkite-agent meta-data get "openfoodnetwork:git:commit"` + echo "Checking out stored commit $OFN_COMMIT" + git checkout -qf "$OFN_COMMIT" +} + function drop_and_recreate_database { # Adapted from: http://stackoverflow.com/questions/12924466/capistrano-with-postgresql-error-database-is-being-accessed-by-other-users psql -U openfoodweb postgres <&1) =~ "Done" ]] +exec 5>&1 +OUTPUT=$(git push production `get_ofn_commit`:master --force 2>&1 |tee /dev/fd/5) +[[ $OUTPUT =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index c634ca53a4..7ace392276 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -ex +set -e source ./script/ci/includes.sh # Add staging git remote if required @@ -16,4 +16,6 @@ echo "--- Loading baseline data" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" echo "--- Pushing to staging" -[[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] +exec 5>&1 +OUTPUT=$(git push staging2 `get_ofn_commit`:master --force 2>&1 |tee /dev/fd/5) +[[ $OUTPUT =~ "Done" ]] diff --git a/script/ci/run_js_tests.sh b/script/ci/run_js_tests.sh index 91a4be09d9..c4a03403b9 100755 --- a/script/ci/run_js_tests.sh +++ b/script/ci/run_js_tests.sh @@ -5,6 +5,7 @@ set -e echo "--- Loading environment" source ./script/ci/includes.sh load_environment +checkout_ofn_commit echo "--- Verifying branch is based on current master" exit_unless_master_merged diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 9f9cdfa30d..efae0805a6 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -5,6 +5,7 @@ set -e echo "--- Loading environment" source ./script/ci/includes.sh load_environment +checkout_ofn_commit echo "--- Verifying branch is based on current master" exit_unless_master_merged