Skip to content
代码片段 群组 项目
提交 fe6e2d64 编辑于 作者: Richard Chong's avatar Richard Chong 提交者: Andrejs Cunskis
浏览文件

Introduces script to publish contracts

上级 70198204
No related branches found
No related tags found
无相关合并请求
显示
78 个添加1 个删除
......@@ -24,9 +24,13 @@ namespace :contracts do
end
Pact::VerificationTask.new(:get_pipeline_header_data) do |pact|
# pact.uri(
# "http://localhost:9292/pacts/provider/GET%20pipeline%20header%20data/consumer/Pipelines%23show/latest",
# pact_helper: "#{provider}/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb"
# )
pact.uri(
"#{contracts}/show/pipelines#show-get_pipeline_header_data.json",
pact_helper: "#{provider}/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb"
pact_helper: "#{provider}/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb"
)
end
......
# 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
......@@ -11,6 +11,8 @@ module DiffsBatchHelper
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
......@@ -11,6 +11,10 @@ module DiffsMetadataHelper
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
......@@ -11,6 +11,10 @@ module DiscussionsHelper
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
......@@ -11,6 +11,10 @@ module CreateNewPipelineHelper
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
......@@ -11,6 +11,10 @@ module GetListProjectPipelinesHelper
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
# 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 DeletePipelineHelper
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
# 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 GetPipelinesHeaderDataHelper
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
......@@ -11,6 +11,10 @@ module CreateNewPipelineHelper
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
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
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册