#!/usr/bin/env bash set -ex function publish_pact_file_to_pact_broker() { echo "Publishing pact file to Pact Broker..." sha="$(git rev-parse --short HEAD)" docker-compose run --rm \ -e JENKINS_URL="${JENKINS_URL}" \ -e PACT_BROKER_HOST="${PACT_BROKER_HOST}" \ -e PACT_BROKER_USERNAME="${PACT_BROKER_USERNAME}" \ -e PACT_BROKER_PASSWORD="${PACT_BROKER_PASSWORD}" \ -e PACT_CONSUMER_TAG="${PACT_CONSUMER_TAG}" \ -e SHA="${sha}" \ contracts-testrunner bundle exec rake broker:pact:publish:jenkins_post_merge } function cleanup() { exit_code=$? set +e docker cp coverage:/app/coverage . docker-compose kill docker-compose rm -f exit $exit_code } trap cleanup INT TERM EXIT docker-compose build --pull echo "Running Rubocop..." docker-compose run --rm testrunner /bin/bash -lc \ "rvm-exec 2.4 bundle exec rubocop --fail-level autocorrect" echo "Running test suite..." docker-compose run --name coverage testrunner $@ echo echo "Running contract tests..." docker-compose run --name contracts -T contracts-testrunner bundle exec rspec spec/contracts docker cp contracts:/usr/src/app/pacts . docker cp contracts:/usr/src/app/log . echo if [[ "${GERRIT_EVENT_TYPE}" == "change-merged" ]]; then publish_pact_file_to_pact_broker fi