diff options
Diffstat (limited to 'spec/contracts')
10 files changed, 73 insertions, 0 deletions
diff --git a/spec/contracts/provider/helpers/publish_contract_helper.rb b/spec/contracts/provider/helpers/publish_contract_helper.rb new file mode 100644 index 00000000000..102a73d87ee --- /dev/null +++ b/spec/contracts/provider/helpers/publish_contract_helper.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Provider + module PublishContractHelper + PROVIDER_VERSION = ENV['GIT_COMMIT'] || `git rev-parse --verify HEAD`.strip + PROVIDER_BRANCH = ENV['GIT_BRANCH'] || `git name-rev --name-only HEAD`.strip + PUBLISH_FLAG = true + + def self.publish_contract_setup + @setup ||= -> { + app_version PROVIDER_VERSION + app_version_branch PROVIDER_BRANCH + publish_verification_results PUBLISH_FLAG + } + end + end +end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb index f94ce47b1f3..71f302f2c44 100644 --- a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_batch_helper.rb @@ -11,6 +11,8 @@ module Provider honours_pact_with 'MergeRequest#show' do pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json' end + + Provider::PublishContractHelper.publish_contract_setup.call end end end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb index 61567214b7a..60a3abea5ae 100644 --- a/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb @@ -11,6 +11,10 @@ module Provider honours_pact_with 'MergeRequest#show' do pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb b/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb index fa76ce8889a..b9308af0a1a 100644 --- a/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/merge_request/show/discussions_helper.rb @@ -11,6 +11,10 @@ module Provider honours_pact_with 'MergeRequest#show' do pact_uri '../contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb index 247a7c4ca8e..2af960bc9fd 100644 --- a/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb @@ -11,6 +11,10 @@ module Provider honours_pact_with 'Pipelines#new' do pact_uri '../contracts/project/pipeline/new/pipelines#new-post_create_a_new_pipeline.json' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb index 80cbbe3b4dd..37cddd1b80e 100644 --- a/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb @@ -11,6 +11,10 @@ module Provider honours_pact_with 'Pipelines#index' do pact_uri '../contracts/project/project/pipeline/index/pipelines#index-get_list_project_pipelines.json' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb index 2d29fabfeca..0455281fcd7 100644 --- a/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative '../../../../spec_helper' +require_relative '../../../../helpers/publish_contract_helper' require_relative '../../../../states/project/pipeline/show_state' module Provider @@ -11,6 +12,10 @@ module Provider honours_pact_with 'Pipelines#show' do pact_uri '../contracts/project/pipeline/show/pipelines#show-delete_pipeline.json' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb index bc8c04cc455..bce1c4ab3f4 100644 --- a/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative '../../../../spec_helper' +require_relative '../../../../helpers/publish_contract_helper' require_relative '../../../../states/project/pipeline/show_state' module Provider @@ -10,7 +11,12 @@ module Provider honours_pact_with 'Pipelines#show' do pact_uri '../contracts/project/pipeline/show/pipelines#show-get_project_pipeline_header_data.json' + # pact_uri 'http://localhost:9292/pacts/provider/GET%20pipeline%20header%20data/consumer/Pipelines%23show/latest' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb b/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb index a83aa9524dc..d95a09abd8d 100644 --- a/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb +++ b/spec/contracts/provider/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb @@ -11,6 +11,10 @@ module Provider honours_pact_with 'PipelineSchedule#edit' do pact_uri '../contracts/project/pipeline_schedule/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json' end + + app_version Provider::PublishContractHelper::PROVIDER_VERSION + app_version_branch Provider::PublishContractHelper::PROVIDER_BRANCH + publish_verification_results Provider::PublishContractHelper::PUBLISH_FLAG end end end diff --git a/spec/contracts/publish-contracts.sh b/spec/contracts/publish-contracts.sh new file mode 100644 index 00000000000..f20cc43e258 --- /dev/null +++ b/spec/contracts/publish-contracts.sh @@ -0,0 +1,23 @@ +LATEST_SHA=$(git rev-parse HEAD) +GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +BROKER_BASE_URL="http://localhost:9292" + +CONTRACTS=$(find ./contracts -name "*.json") +ERROR=0 + +trap 'catch' ERR + +function catch() { + printf "\e[31mAn error occured while trying to publish the pact.\033[0m\n" + ERROR=1 +} + +for contract in $CONTRACTS +do + printf "\e[32mPublishing ${contract}...\033[0m\n" + pact-broker publish $contract --consumer-app-version $LATEST_SHA --branch $GIT_BRANCH --broker-base-url $BROKER_BASE_URL --output json +done + +if [ ${ERROR} = 1 ]; then + exit 1; +fi
\ No newline at end of file |