From 389ac07bd7db1a41f01b31997dacd8ad7b26099e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 17 Jun 2015 16:25:34 +1000 Subject: [PATCH] Store commit at start of build process and use it throughout --- script/ci/includes.sh | 15 +++++++++++++++ script/ci/merge_master_into_branch.sh | 3 +++ script/ci/push_to_production.sh | 4 ++-- script/ci/push_to_staging.sh | 2 +- script/ci/run_js_tests.sh | 1 + script/ci/run_tests.sh | 1 + 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/script/ci/includes.sh b/script/ci/includes.sh index d7619f7d23..5bfe5b836f 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 `git rev-parse $BUILDKITE_BRANCH` +} + +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" ]] +[[ $(git push production `get_ofn_commit`:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index c634ca53a4..080228cae5 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -16,4 +16,4 @@ 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" ]] +[[ $(git push staging2 `get_ofn_commit`:master --force 2>&1) =~ "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