Skip to content

Commit

Permalink
feat: add --verification-exit-code to publish-provider-contract command
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 10, 2022
1 parent 0179e06 commit d35d908
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
67 changes: 44 additions & 23 deletions lib/pactflow/client/cli/provider_contract_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def self.included(thor)
#method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
method_option :specification, default: "oas", desc: "The contract specification"
method_option :content_type, desc: "The content type. eg. application/yml"
method_option :verification_success, type: :boolean
method_option :verification_success, type: :boolean, desc: "Whether or not the self verification passed successfully."
method_option :verification_exit_code, type: :numeric, desc: "The exit code of the verification process. Can be used instead of --verificaiton-success|--no-verification-success for a simpler build script."
method_option :verification_results, desc: "The path to the file containing the output from the verification process"
method_option :verification_results_content_type, desc: "The content type of the verification output eg. text/plain, application/yaml"
method_option :verification_results_format, desc: "The format of the verification output eg. junit, text"
Expand All @@ -34,31 +35,51 @@ def self.included(thor)
def publish_provider_contract(provider_contract_path)
require "pactflow/client/provider_contracts/publish"

params = params = {
provider_name: options.provider.strip,
provider_version_number: options.provider_app_version.strip,
branch_name: options.branch && options.branch.strip,
tags: (options.tag && options.tag.collect(&:strip)) || [],
contract: {
content: File.read(provider_contract_path),
content_type: options.content_type,
specification: options.specification
},
verification_results: {
success: options.verification_success,
content: options.verification_results ? File.read(options.verification_results) : nil,
content_type: options.verification_results_content_type,
format: options.verification_results_format,
verifier: options.verifier,
verifier_version: options.verifier_version
}
}

command_options = { verbose: options.verbose, output: options.output }
result = ::Pactflow::Client::ProviderContracts::Publish.call(params, command_options, pact_broker_client_options)
validate_publish_provider_contract_options(provider_contract_path)
result = ::Pactflow::Client::ProviderContracts::Publish.call(
publish_provider_contract_command_params(provider_contract_path),
command_options,
pact_broker_client_options
)
$stdout.puts result.message
exit(1) unless result.success
end

no_commands do
def command_options
{ verbose: options.verbose, output: options.output }
end

def validate_publish_provider_contract_options(provider_contract_path)
if !options.verification_success.nil? && options.verification_exit_code
raise Thor::Error, "Cannot use both --verification-success|--no-verification-success and --verification-exit-code"
end
end

def publish_provider_contract_command_params(provider_contract_path)
success = !options.verification_success.nil? ? options.verification_success : ( options.verification_exit_code && options.verification_exit_code == 0 )

{
provider_name: options.provider.strip,
provider_version_number: options.provider_app_version.strip,
branch_name: options.branch && options.branch.strip,
tags: (options.tag && options.tag.collect(&:strip)) || [],
contract: {
content: File.read(provider_contract_path),
content_type: options.content_type,
specification: options.specification
},
verification_results: {
success: success,
content: options.verification_results ? File.read(options.verification_results) : nil,
content_type: options.verification_results_content_type,
format: options.verification_results_format,
verifier: options.verifier,
verifier_version: options.verifier_version
}
}
end
end
end
end
end
Expand Down
37 changes: 19 additions & 18 deletions script/publish-provider-contract.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
export PACT_BROKER_BASE_URL="http://localhost:9292"
export PACT_BROKER_BASE_URL=${PACT_BROKER_BASE_URL:-"http://localhost:9292"}
export PACTFLOW_FEATURES=publish-provider-contract
bundle exec bin/pactflow publish-provider-contract \
script/oas.yml \
--provider Foo \
--provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
--branch main \
--tag dev \
--specification oas \
--content-type application/yml \
--verification-exit-code 0 \
--verification-results script/verification-results.txt \
--verification-results-content-type text/plain \
--verification-results-format text \
--verifier my-custom-tool \
--verifier-version "1.0" \
--verbose


# bundle exec bin/pactflow publish-provider-contract \
# script/oas.yml \
# --provider Foo \
# --provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
# --branch main \
# --tag dev \
# --specification oas \
# --content-type application/yml \
# --no-verification-success \
# --verification-results script/verification-results.txt \
# --verification-results-content-type text/plain \
# --verification-results-format text \
# --verifier my-custom-tool \
# --verifier-version "1.0" \
# --verbose

# --content-type application/yml

bundle exec bin/pactflow publish-provider-contract \
script/oas.yml \
--provider Foo \
--provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
--branch main \
--tag dev \
--specification oas \
--content-type application/yml

0 comments on commit d35d908

Please sign in to comment.