pact_broker-client 1.47.0 → 1.50.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,107 @@
1
+ # Using can-i-deploy with tags
2
+
3
+ The can-i-deploy tool was originally written to support specifying versions and dependencies using tags. This usage has now been superseded by first class support for [environments, deployments and releases](https://docs.pact.io/pact_broker/recording_deployments_and_releases/).
4
+
5
+ The following documentation covers the usage of can-i-deploy for users who are still using tags to track environments and deployments.
6
+
7
+ There are two ways to use `can-i-deploy` with tags. The first (recommended and most commonly used) approach is to specify just the application version you want to deploy and let the Pact Broker work out the dependencies for you. The second approach is to specify each application version explicitly. This would generally only be used if there were limitations that stopped you being able to use the first approach.
8
+
9
+ #### Specifying an application version
10
+
11
+ To specify an application (pacticipant) version you need to provide:
12
+
13
+ * the name of the application using the `--pacticipant PACTICIPANT` parameter,
14
+ * directly followed by *one* of the following parameters:
15
+ * `--version VERSION` to specify a known application version (recommended)
16
+ * `--latest` to specify the latest version
17
+ * `--latest TAG` to specify the latest version that has a particular tag
18
+ * `--all TAG` to specify all the versions that have a particular tag (eg. "all prod" versions). This would be used when ensuring you have backwards compatiblity with all production mobile clients for a provider. Note, when using this option, you need to specify dependency explicitly (see the second usage option).
19
+
20
+ Using a specific version is the easiest way to ensure you get an accurate response that won't be affected by race conditions.
21
+
22
+ #### Recommended usage - allowing the Pact Broker to automatically determine the dependencies
23
+
24
+ Prerequisite: if you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment.
25
+
26
+ How you do this depends on the version of the Pact Broker you are running.
27
+
28
+ If you are using a Broker version where deployment versions are supported, then you would notify the Broker of the deployment of this application version like so:
29
+
30
+ $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment test
31
+
32
+ This assumes that you have already set up an environment named "test" in the Broker.
33
+
34
+ If you are using a Broker version that does not support deployment environments, then you will need to use tags to notify the broker of the deployment of this application version, like so:
35
+
36
+ $ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test
37
+
38
+ Once you have configured your build to notify the Pact Broker of the successful deployment using either method describe above, you can use the following simple command to find out if you are safe to deploy (use either `--to` or `--to-environment` as supported):
39
+
40
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION
41
+ [--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG ]
42
+ --broker-base-url BROKER_BASE_URL
43
+
44
+ If the `--to` or `--to-environment` options are omitted, then the query will return the compatiblity with the overall latest version of each of the other applications.
45
+
46
+ Examples:
47
+
48
+
49
+ Can I deploy version 173153ae0 of application Foo to the test environment?
50
+
51
+
52
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
53
+ --to-environment test \
54
+ --broker-base-url https://my-pact-broker
55
+
56
+
57
+ Can I deploy the latest version of application Foo with the latest version of each of the applications it integrates to?
58
+
59
+
60
+ $ pact-broker can-i-deploy --pacticipant Foo --latest \
61
+ --broker-base-url https://my-pact-broker
62
+
63
+
64
+ Can I deploy the latest version of the application Foo that has the tag "test" to the "prod" environment?
65
+
66
+ $ pact-broker can-i-deploy --pacticipant Foo --latest test \
67
+ --to prod \
68
+ --broker-base-url https://my-pact-broker
69
+
70
+
71
+ #### Alternate usage - specifying dependencies explicitly
72
+
73
+ If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify one or more of the dependencies explictly. You must also do this if you want to use the `--all TAG` option for any of the pacticipants.
74
+
75
+ You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version.)
76
+
77
+ You can use explictly declared dependencies with or without the `--to ENVIRONMENT_TAG`. For example, if you declare two (or more) application versions with no `--to ENVIRONMENT_TAG`, then only the applications you specify will be taken into account when determining if it is safe to deploy. If you declare two (or more) application versions _as well as_ a `--to ENVIRONMENT`, then the Pact Broker will work out what integrations your declared applications will have in that environment when determining if it safe to deploy. When using this script for a production release, and you are using tags, it is always the most future-proof option to use the `--to` if possible, as it will catch any newly added consumers or providers.
78
+
79
+ If you are finding that your dependencies are not being automatically included when you supply multiple pacticipant versions, please upgrade to the latest version of the Pact Broker, as this is a more recently added feature.
80
+
81
+
82
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT_1 [--version VERSION_1 | --latest [TAG_1] | --all TAG_1] \
83
+ --pacticipant PACTICIPANT_2 [--version VERSION_2 | --latest [TAG_2] | --all TAG_2] \
84
+ [--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG]
85
+
86
+ Examples:
87
+
88
+
89
+ Can I deploy version Foo version 173153ae0 and Bar version ac23df1e8 together?
90
+
91
+
92
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
93
+ --pacticipant Bar --version ac23df1e8
94
+
95
+
96
+ Can I deploy the latest version of Foo with tag "master" and the latest version of Bar with tag "master" together?
97
+
98
+ $ pact-broker can-i-deploy --pacticipant Foo --latest master \
99
+ --pacticipant Bar --latest master
100
+
101
+
102
+ Mobile provider use case - can I deploy version b80e7b1b of Bar, all versions of Foo with tag "prod", and the latest version tagged "prod" of any other automatically calculated dependencies together? (Eg. where Bar is a provider and Foo is a mobile consumer with multiple versions in production, and Bar also has its own providers it needs to be compatible with.)
103
+
104
+
105
+ $ pact-broker can-i-deploy --pacticipant Bar --version b80e7b1b \
106
+ --pacticipant Foo --all prod \
107
+ --to prod
@@ -1159,7 +1159,6 @@ Pact Broker will respond with:
1159
1159
  },
1160
1160
  "body": {
1161
1161
  "number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
1162
- "branch": "main",
1163
1162
  "buildUrl": "http://my-ci/builds/1",
1164
1163
  "_links": {
1165
1164
  "self": {
@@ -1194,7 +1193,6 @@ Pact Broker will respond with:
1194
1193
  },
1195
1194
  "body": {
1196
1195
  "number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
1197
- "branch": "main",
1198
1196
  "buildUrl": "http://my-ci/builds/1",
1199
1197
  "_links": {
1200
1198
  "self": {
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+
3
+ # Use this to stop unnecessary verifications from running when triggered by the
4
+ # `contract_content_changed` webhook, or when using the webhookless flow.
5
+
6
+ set -eu
7
+
8
+ PACT_CLI_VERSION="0.47.0.0"
9
+
10
+ : "${PACT_URL:?PACT_URL is not set, cannot run verification.}"
11
+ : "${CONSUMER_NAME:?CONSUMER_NAME is not set, cannot check if verification is required.}"
12
+ : "${CONSUMER_VERSION_NUMBER:?CONSUMER_VERSION_NUMBER is not set, cannot check if verification is required.}"
13
+
14
+ # Delete unnecessary username/password/token
15
+ if docker run --rm \
16
+ -e PACT_BROKER_BASE_URL \
17
+ -e PACT_BROKER_TOKEN \
18
+ -e PACT_BROKER_USERNAME \
19
+ -e PACT_BROKER_PASSWORD \
20
+ -e PACT_BROKER_FEATURES="verification_required" \
21
+ -it \
22
+ pactfoundation/pact-cli:$PACT_CLI_VERSION \
23
+ broker verification-required \
24
+ --pacticipant pactflow-application-saas \
25
+ --version ${RELEASE_VERSION} \
26
+ --pacticipant ${CONSUMER_NAME} \
27
+ --version ${CONSUMER_VERSION_NUMBER} \
28
+ --verbose ; then
29
+ echo "Run the verification here"
30
+ fi
@@ -1,109 +1,24 @@
1
- Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) versions are compatible (ie. safe to deploy). Prints out the relevant pact/verification details, indicating any missing or failed verification results.
1
+ Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) has a successful verification result with each of the application versions that are already deployed to a particular environment. Prints out the relevant pact/verification details, indicating any missing or failed verification results.
2
2
 
3
- The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD may be used instead of their respective command line options.
3
+ The can-i-deploy tool was originally written to support specifying versions and dependencies using tags. This usage has now been superseded by first class support for environments, deployments and releases. For documentation on how to use can-i-deploy with tags, please see https://docs.pact.io/pact_broker/client_cli/can_i_deploy_usage_with_tags/
4
4
 
5
- There are two ways to use `can-i-deploy`. The first (recommended and most commonly used) approach is to specify just the application version you want to deploy and let the Pact Broker work out the dependencies for you. The second approach is to specify each application version explicitly. This would generally only be used if there were limitations that stopped you being able to use the first approach.
5
+ Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The "test" and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See https://docs.pact.io/pact_broker/client_cli/readme#environments for more information.
6
6
 
7
- #### Specifying an application version
7
+ $ pact-broker create-environment --name "uat" --display-name "UAT" --no-production
8
8
 
9
- To specify an application (pacticipant) version you need to provide:
9
+ After an application is deployed or released, its deployment must be recorded using the `record-deployment` or `record-release` commands. See https://docs.pact.io/pact_broker/recording_deployments_and_releases/ for more information.
10
10
 
11
- * the name of the application using the `--pacticipant PACTICIPANT` parameter,
12
- * directly followed by *one* of the following parameters:
13
- * `--version VERSION` to specify a known application version (recommended)
14
- * `--latest` to specify the latest version
15
- * `--latest TAG` to specify the latest version that has a particular tag
16
- * `--all TAG` to specify all the versions that have a particular tag (eg. "all prod" versions). This would be used when ensuring you have backwards compatiblity with all production mobile clients for a provider. Note, when using this option, you need to specify dependency explicitly (see the second usage option).
11
+ $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment uat
17
12
 
18
- Using a specific version is the easiest way to ensure you get an accurate response that won't be affected by race conditions.
13
+ Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy with the versions of each integrated application that are already in that environment.
19
14
 
20
- #### Recommended usage - allowing the Pact Broker to automatically determine the dependencies
15
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to-environment ENVIRONMENT
21
16
 
22
- Prerequisite: if you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment.
17
+ Example: can I deploy version 173153ae0 of application Foo to the test environment?
23
18
 
24
- How you do this depends on the version of the Pact Broker you are running.
19
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 --to-environment test
25
20
 
26
- If you are using a Broker version where deployment versions are supported, then you would notify the Broker of the deployment of this application version like so:
21
+ Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the latest version from the main branch of another application" it functions as a "can I merge" check.
27
22
 
28
- $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment test
29
-
30
- This assumes that you have already set up an environment named "test" in the Broker.
31
-
32
- If you are using a Broker version that does not support deployment environments, then you will need to use tags to notify the broker of the deployment of this application version, like so:
33
-
34
- $ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test
35
-
36
- Once you have configured your build to notify the Pact Broker of the successful deployment using either method describe above, you can use the following simple command to find out if you are safe to deploy (use either `--to` or `--to-environment` as supported):
37
-
38
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION
39
- [--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG ]
40
- --broker-base-url BROKER_BASE_URL
41
-
42
- If the `--to` or `--to-environment` options are omitted, then the query will return the compatiblity with the overall latest version of each of the other applications.
43
-
44
- Examples:
45
-
46
-
47
- Can I deploy version 173153ae0 of application Foo to the test environment?
48
-
49
-
50
- $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
51
- --to-environment test \
52
- --broker-base-url https://my-pact-broker
53
-
54
-
55
- Can I deploy the latest version of application Foo with the latest version of each of the applications it integrates to?
56
-
57
-
58
- $ pact-broker can-i-deploy --pacticipant Foo --latest \
59
- --broker-base-url https://my-pact-broker
60
-
61
-
62
- Can I deploy the latest version of the application Foo that has the tag "test" to the "prod" environment?
63
-
64
- $ pact-broker can-i-deploy --pacticipant Foo --latest test \
65
- --to prod \
66
- --broker-base-url https://my-pact-broker
67
-
68
-
69
- #### Alternate usage - specifying dependencies explicitly
70
-
71
- If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify one or more of the dependencies explictly. You must also do this if you want to use the `--all TAG` option for any of the pacticipants.
72
-
73
- You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version.)
74
-
75
- You can use explictly declared dependencies with or without the `--to ENVIRONMENT_TAG`. For example, if you declare two (or more) application versions with no `--to ENVIRONMENT_TAG`, then only the applications you specify will be taken into account when determining if it is safe to deploy. If you declare two (or more) application versions _as well as_ a `--to ENVIRONMENT`, then the Pact Broker will work out what integrations your declared applications will have in that environment when determining if it safe to deploy. When using this script for a production release, and you are using tags, it is always the most future-proof option to use the `--to` if possible, as it will catch any newly added consumers or providers.
76
-
77
- If you are finding that your dependencies are not being automatically included when you supply multiple pacticipant versions, please upgrade to the latest version of the Pact Broker, as this is a more recently added feature.
78
-
79
-
80
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT_1 [--version VERSION_1 | --latest [TAG_1] | --all TAG_1] \
81
- --pacticipant PACTICIPANT_2 [--version VERSION_2 | --latest [TAG_2] | --all TAG_2] \
82
- [--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG] \
83
- --broker-base-url BROKER_BASE_URL
84
-
85
- Examples:
86
-
87
-
88
- Can I deploy version Foo version 173153ae0 and Bar version ac23df1e8 together?
89
-
90
-
91
- $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
92
- --pacticipant Bar --version ac23df1e8 \
93
- --broker-base-url BROKER_BASE_URL
94
-
95
-
96
- Can I deploy the latest version of Foo with tag "master" and the latest version of Bar with tag "master" together?
97
-
98
- $ pact-broker can-i-deploy --pacticipant Foo --latest master \
99
- --pacticipant Bar --latest master \
100
- --broker-base-url BROKER_BASE_URL
101
-
102
-
103
- Mobile provider use case - can I deploy version b80e7b1b of Bar, all versions of Foo with tag "prod", and the latest version tagged "prod" of any other automatically calculated dependencies together? (Eg. where Bar is a provider and Foo is a mobile consumer with multiple versions in production, and Bar also has its own providers it needs to be compatible with.)
104
-
105
-
106
- $ pact-broker can-i-deploy --pacticipant Bar --version b80e7b1b \
107
- --pacticipant Foo --all prod \
108
- --to prod \
109
- --broker-base-url BROKER_BASE_URL
23
+ $ pact-broker can-i-deploy --pacticipant Foo 173153ae0 \
24
+ --pacticipant Bar --latest main
@@ -38,7 +38,7 @@ module PactBroker
38
38
  execute_environment_command(params_from_options([:uuid]), "DescribeEnvironment")
39
39
  end
40
40
 
41
- desc "list-environments", "List environment"
41
+ desc "list-environments", "List environments"
42
42
  method_option :output, aliases: "-o", desc: "json or text", default: 'text'
43
43
  shared_authentication_options
44
44
  def list_environments
@@ -12,8 +12,8 @@ module PactBroker
12
12
  method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
13
13
  method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option."
14
14
  method_option :latest, required: false, aliases: "-l", banner: "[TAG]", desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
15
- method_option :to, required: false, banner: "TAG", desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
16
- method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
15
+ method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil
16
+ method_option :to, required: false, banner: "TAG", desc: "The tag that represents the branch or environment of the integrated applications for which you want to check the verification result status.", default: nil
17
17
  method_option :output, aliases: "-o", desc: "json or table", default: "table"
18
18
  method_option :retry_while_unknown, banner: "TIMES", type: :numeric, default: 0, required: false, desc: "The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)"
19
19
  method_option :retry_interval, banner: "SECONDS", type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
@@ -28,11 +28,7 @@ module PactBroker
28
28
 
29
29
  validate_credentials
30
30
  selectors = VersionSelectorOptionsParser.call(ARGV).select { |s| !s[:ignore] }
31
- ignore_selectors = if ENV.fetch("PACT_BROKER_FEATURES", "").include?("ignore")
32
- VersionSelectorOptionsParser.call(ARGV).select { |s| s[:ignore] }
33
- else
34
- []
35
- end
31
+ ignore_selectors = VersionSelectorOptionsParser.call(ARGV).select { |s| s[:ignore] }
36
32
  validate_can_i_deploy_selectors(selectors)
37
33
  dry_run = options.dry_run || ENV["PACT_BROKER_CAN_I_DEPLOY_DRY_RUN"] == "true"
38
34
  can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval, dry_run: dry_run, verbose: options.verbose }
@@ -22,6 +22,9 @@ module PactBroker
22
22
  method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
23
23
  method_option :provider_verification_failed, type: :boolean, desc: "Trigger this webhook when a failed provider verification result is published"
24
24
  method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
25
+ if ENV.fetch("PACT_BROKER_FEATURES", "").include?("contract_requiring_verification_published")
26
+ method_option :contract_requiring_verification_published, type: :boolean, desc: "Trigger this webhook when a contract is published that requires verification"
27
+ end
25
28
  method_option :team_uuid, banner: "UUID", desc: "UUID of the Pactflow team to which the webhook should be assigned (Pactflow only)"
26
29
  shared_authentication_options
27
30
  end
@@ -62,12 +65,14 @@ module PactBroker
62
65
  events << 'provider_verification_published' if options.provider_verification_published
63
66
  events << 'provider_verification_succeeded' if options.provider_verification_succeeded
64
67
  events << 'provider_verification_failed' if options.provider_verification_failed
68
+ events << 'contract_requiring_verification_published' if options.contract_requiring_verification_published
65
69
  events
66
70
  end
67
71
 
68
72
  def parse_webhook_options(webhook_url)
69
73
  events = parse_webhook_events
70
74
 
75
+ # TODO update for contract_requiring_verification_published when released
71
76
  if events.size == 0
72
77
  raise WebhookCreationError.new("You must specify at least one of --contract-content-changed, --contract-published, --provider-verification-published, --provider-verification-succeeded or --provider-verification-failed")
73
78
  end
@@ -2,11 +2,33 @@ module PactBroker
2
2
  module Client
3
3
  class Matrix
4
4
  class AbbreviateVersionNumber
5
- def self.call version_number
6
- if version_number
7
- version_number.gsub(/[A-Za-z0-9]{40}/) do | val |
8
- val[0...7] + "..."
9
- end
5
+ # Official regex from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
6
+ SEMVER_REGEX = /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/
7
+ SHA1_REGEX = /[A-Za-z0-9]{40}/
8
+
9
+ class << self
10
+ def call version_number
11
+ return unless version_number
12
+
13
+ return replace_all_git_sha(version_number) if [SEMVER_REGEX, SHA1_REGEX].all?{|r| regex_match?(r, version_number) }
14
+
15
+ return replace_all_git_sha(version_number) if regex_match?(Regexp.new("\\A#{SHA1_REGEX.source}\\z"), version_number)
16
+
17
+ # Trim to some meaningful value in case we couldn't match anything, just not to mess with the output
18
+ return version_number[0...60] + '...' if version_number.length > 60
19
+
20
+ version_number
21
+ end
22
+
23
+ private
24
+
25
+ # To support ruby2.2
26
+ def regex_match?(regex, value)
27
+ !regex.match(value).nil?
28
+ end
29
+
30
+ def replace_all_git_sha(version)
31
+ version.gsub(SHA1_REGEX) { |val| val[0...7] + '...' }
10
32
  end
11
33
  end
12
34
  end
@@ -30,6 +30,10 @@ module PactBroker
30
30
  end
31
31
  end
32
32
 
33
+ def no_results?
34
+ self[:summary][:success] == 0 && self[:summary][:failed] == 0
35
+ end
36
+
33
37
  def supports_unknown_count?
34
38
  !!(self[:summary] && Integer === self[:summary][:unknown] )
35
39
  end
@@ -17,7 +17,9 @@ module PactBroker
17
17
 
18
18
  def create_result(matrix)
19
19
  matrix_and_notices = format_matrix(matrix) + "\n\n" + remove_warnings(Term::ANSIColor.uncolor(notice_or_reason(matrix, :white)))
20
- if matrix.any_unknown?
20
+ # If the specified version numbers do not exist, then all the counts come back 0. Can't just check for unknown to be 0.
21
+ # This command needs to handle "I screwed up the query"
22
+ if matrix.no_results?
21
23
  Result.new(true, matrix_and_notices + "\n\nVerification is required.")
22
24
  else
23
25
  Result.new(false, matrix_and_notices + "\n\nNo verification is required.")
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.47.0'
3
+ VERSION = '1.50.0'
4
4
  end
5
5
  end
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+ require "stringio"
3
+ require "pact_broker/client/cli/broker"
4
+
5
+ ENV["THOR_COLUMNS"] = "160"
6
+ START_MARKER = "<!-- start-autogenerated-docs -->"
7
+ END_MARKER = "<!-- end-autogenerated-docs -->"
8
+ TERMINAL_WIDTH = 80
9
+
10
+ def print_wrapped(message, options = {})
11
+ out = StringIO.new
12
+ indent = options[:indent] || 0
13
+ width = TERMINAL_WIDTH - indent
14
+ paras = message.split("\n\n")
15
+
16
+ paras.map! do |unwrapped|
17
+ counter = 0
18
+ unwrapped.split(" ").inject do |memo, word|
19
+ word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
20
+ counter = 0 if word.include? "\n"
21
+ if (counter + word.length + 1) < width
22
+ memo = "#{memo} #{word}"
23
+ counter += (word.length + 1)
24
+ else
25
+ memo = "#{memo}\n#{word}"
26
+ counter = word.length
27
+ end
28
+ memo
29
+ end
30
+ end.compact!
31
+
32
+ paras.each do |para|
33
+ para.split("\n").each do |line|
34
+ out.puts line.insert(0, " " * indent)
35
+ end
36
+ out.puts unless para == paras.last
37
+ end
38
+ out.string
39
+ end
40
+
41
+ def format_banner(banner)
42
+ banner_lines = print_wrapped(banner, indent: 16).split("\n")
43
+ banner_lines[0] = banner_lines[0].gsub(/^\s\s/, "")
44
+ banner_lines
45
+ end
46
+
47
+ def generate_thor_docs
48
+ begin
49
+ out = StringIO.new
50
+ $stdout = out
51
+
52
+ command_groups = [
53
+ ["Pacts", %w[publish list-latest-pact-versions] ],
54
+ ["Environments", %w[create-environment update-environment describe-environment delete-environment list-environments]],
55
+ ["Deployments", %w[record-deployment record-undeployment]],
56
+ ["Releases", %w[record-release record-support-ended]],
57
+ ["Matrix", %w[can-i-deploy]],
58
+ ["Pacticipants", %w[create-or-update-pacticipant describe-pacticipant list-pacticipants]],
59
+ ["Webhooks", %w[create-webhook create-or-update-webhook test-webhook]],
60
+ ["Tags", %w[create-version-tag]],
61
+ ["Versions", %w[describe-version]],
62
+ ["Miscellaneous", %w[generate-uuid]]
63
+ ]
64
+
65
+ command_groups.collect do | group, commands |
66
+ puts "### #{group}\n\n"
67
+ commands.each do | command |
68
+ puts "#### #{command}\n\n"
69
+ PactBroker::Client::CLI::Broker.start(["help", command])
70
+ puts "\n"
71
+ end
72
+ end
73
+ out.string
74
+ ensure
75
+ $stdout = STDOUT
76
+ end
77
+ end
78
+
79
+ STATES = {
80
+ start: {
81
+ /^Usage:/ => :usage
82
+ },
83
+ usage: {
84
+ /^Options:/ => :options
85
+ },
86
+ options: {
87
+ /^$/ => :after_options
88
+ },
89
+ after_options: {
90
+ /^Usage:/ => :usage
91
+ }
92
+ }
93
+
94
+ def entered?(state)
95
+ @old_state != state && @current_state == state
96
+ end
97
+
98
+ def exited?(state)
99
+ @old_state == state && @current_state != state
100
+ end
101
+
102
+ def has_option_and_banner(line)
103
+ line =~ /--.*\s#\s/
104
+ end
105
+
106
+ def has_only_banner(line)
107
+ line =~ /^\s+#\s/
108
+ end
109
+
110
+ @current_state = :start
111
+ @old_state = nil
112
+
113
+ def reformat_docs(generated_thor_docs)
114
+ generated_thor_docs.split("\n").collect do | line |
115
+ @old_state = @current_state
116
+
117
+ transitions = STATES[@current_state]
118
+
119
+ line_starts_with = transitions.keys.find { | key | line =~ key }
120
+ if line_starts_with
121
+ @current_state = transitions[line_starts_with]
122
+ end
123
+
124
+
125
+ lines = if has_option_and_banner(line)
126
+ option, banner = line.split("#", 2)
127
+ [option] + format_banner("# " + banner)
128
+ elsif has_only_banner(line)
129
+ space, banner = line.split("#", 2)
130
+ format_banner("# " + banner)
131
+ else
132
+ [line]
133
+ end
134
+
135
+ if entered?(:usage) || exited?(:options)
136
+ ["```"] + lines
137
+ else
138
+ lines
139
+ end
140
+ # line
141
+ end.flatten.join("\n").gsub("/go/", "/").gsub(File.basename(__FILE__), "pact-broker")
142
+ end
143
+
144
+ def update_readme(usage_docs)
145
+ readme_text = File.read("README.md")
146
+ before_text = readme_text.split(START_MARKER).first
147
+ after_text = readme_text.split("<!-- end-autogenerated-docs -->", 2).last
148
+ new_readme_text = before_text + START_MARKER + "\n\n" + usage_docs + "\n\n" + END_MARKER + after_text
149
+ File.open("README.md", "w") { |file| file << new_readme_text }
150
+ end
151
+
152
+ update_readme(reformat_docs(generate_thor_docs))