pact_broker-client 1.48.0 → 1.51.1

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
@@ -40,7 +40,7 @@
40
40
 
41
41
  * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:pacticipant-version_and_pb:environments_relations_exist_in_the_index_resource) given the pb:pacticipant-version and pb:environments relations exist in the index resource
42
42
 
43
- * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:pacticipant-version_relation_exists_in_the_index_resource) given the pb:pacticipant-version relation exists in the index resource
43
+ * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:publish-contracts_relations_exists_in_the_index_resource) given the pb:publish-contracts relations exists in the index resource
44
44
 
45
45
  * [A request for the index resource with the webhook relation](#a_request_for_the_index_resource_with_the_webhook_relation)
46
46
 
@@ -56,10 +56,6 @@
56
56
 
57
57
  * [A request to create a pacticipant](#a_request_to_create_a_pacticipant)
58
58
 
59
- * [A request to create a pacticipant version](#a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_exist) given version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does exist
60
-
61
- * [A request to create a pacticipant version](#a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_not_exist) given version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does not exist
62
-
63
59
  * [A request to create a webhook for a consumer and provider](#a_request_to_create_a_webhook_for_a_consumer_and_provider_given_'Condor'_does_not_exist_in_the_pact-broker) given 'Condor' does not exist in the pact-broker
64
60
 
65
61
  * [A request to create a webhook with a JSON body and a uuid](#a_request_to_create_a_webhook_with_a_JSON_body_and_a_uuid_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
@@ -100,6 +96,8 @@
100
96
 
101
97
  * [A request to publish a pact with method put](#a_request_to_publish_a_pact_with_method_put_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker,_and_Condor_already_has_a_pact_published_for_version_1.3.0) given the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0
102
98
 
99
+ * [A request to publish contracts](#a_request_to_publish_contracts)
100
+
103
101
  * [A request to record a deployment](#a_request_to_record_a_deployment_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment) given version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment
104
102
 
105
103
  * [A request to record a release](#a_request_to_record_a_release_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment) given version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment
@@ -855,11 +853,11 @@ Pact Broker will respond with:
855
853
  }
856
854
  }
857
855
  ```
858
- <a name="a_request_for_the_index_resource_given_the_pb:pacticipant-version_relation_exists_in_the_index_resource"></a>
859
- Given **the pb:pacticipant-version relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
856
+ <a name="a_request_for_the_index_resource_given_the_pb:publish-contracts_relations_exists_in_the_index_resource"></a>
857
+ Given **the pb:publish-contracts relations exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
860
858
  ```json
861
859
  {
862
- "method": "get",
860
+ "method": "GET",
863
861
  "path": "/",
864
862
  "headers": {
865
863
  "Accept": "application/hal+json"
@@ -875,8 +873,8 @@ Pact Broker will respond with:
875
873
  },
876
874
  "body": {
877
875
  "_links": {
878
- "pb:pacticipant-version": {
879
- "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
876
+ "pb:publish-contracts": {
877
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS"
880
878
  }
881
879
  }
882
880
  }
@@ -1134,76 +1132,6 @@ Pact Broker will respond with:
1134
1132
  }
1135
1133
  }
1136
1134
  ```
1137
- <a name="a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_exist"></a>
1138
- Given **version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does exist**, upon receiving **a request to create a pacticipant version** from Pact Broker Client, with
1139
- ```json
1140
- {
1141
- "method": "put",
1142
- "path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
1143
- "headers": {
1144
- "Content-Type": "application/json",
1145
- "Accept": "application/hal+json"
1146
- },
1147
- "body": {
1148
- "branch": "main",
1149
- "buildUrl": "http://my-ci/builds/1"
1150
- }
1151
- }
1152
- ```
1153
- Pact Broker will respond with:
1154
- ```json
1155
- {
1156
- "status": 200,
1157
- "headers": {
1158
- "Content-Type": "application/hal+json;charset=utf-8"
1159
- },
1160
- "body": {
1161
- "number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
1162
- "branch": "main",
1163
- "buildUrl": "http://my-ci/builds/1",
1164
- "_links": {
1165
- "self": {
1166
- "href": "http://localhost:1234/some-url"
1167
- }
1168
- }
1169
- }
1170
- }
1171
- ```
1172
- <a name="a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_not_exist"></a>
1173
- Given **version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does not exist**, upon receiving **a request to create a pacticipant version** from Pact Broker Client, with
1174
- ```json
1175
- {
1176
- "method": "put",
1177
- "path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
1178
- "headers": {
1179
- "Content-Type": "application/json",
1180
- "Accept": "application/hal+json"
1181
- },
1182
- "body": {
1183
- "branch": "main",
1184
- "buildUrl": "http://my-ci/builds/1"
1185
- }
1186
- }
1187
- ```
1188
- Pact Broker will respond with:
1189
- ```json
1190
- {
1191
- "status": 201,
1192
- "headers": {
1193
- "Content-Type": "application/hal+json;charset=utf-8"
1194
- },
1195
- "body": {
1196
- "number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
1197
- "branch": "main",
1198
- "buildUrl": "http://my-ci/builds/1",
1199
- "_links": {
1200
- "self": {
1201
- "href": "http://localhost:1234/some-url"
1202
- }
1203
- }
1204
- }
1205
- }
1206
- ```
1207
1135
  <a name="a_request_to_create_a_webhook_for_a_consumer_and_provider_given_&#39;Condor&#39;_does_not_exist_in_the_pact-broker"></a>
1208
1136
  Given **'Condor' does not exist in the pact-broker**, upon receiving **a request to create a webhook for a consumer and provider** from Pact Broker Client, with
1209
1137
  ```json
@@ -2121,6 +2049,75 @@ Pact Broker will respond with:
2121
2049
  }
2122
2050
  }
2123
2051
  ```
2052
+ <a name="a_request_to_publish_contracts"></a>
2053
+ Upon receiving **a request to publish contracts** from Pact Broker Client, with
2054
+ ```json
2055
+ {
2056
+ "method": "POST",
2057
+ "path": "/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS",
2058
+ "headers": {
2059
+ "Content-Type": "application/json",
2060
+ "Accept": "application/hal+json"
2061
+ },
2062
+ "body": {
2063
+ "pacticipantName": "Foo",
2064
+ "pacticipantVersionNumber": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
2065
+ "branch": "main",
2066
+ "tags": [
2067
+ "dev"
2068
+ ],
2069
+ "buildUrl": "http://build",
2070
+ "contracts": [
2071
+ {
2072
+ "consumerName": "Foo",
2073
+ "providerName": "Bar",
2074
+ "specification": "pact",
2075
+ "contentType": "application/json",
2076
+ "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbeyJkZXNjcmlwdGlvbiI6ImFuIGV4YW1wbGUgcmVxdWVzdCIsInByb3ZpZGVyU3RhdGUiOiJhIHByb3ZpZGVyIHN0YXRlIiwicmVxdWVzdCI6eyJtZXRob2QiOiJHRVQiLCJwYXRoIjoiLyIsImhlYWRlcnMiOnt9fSwicmVzcG9uc2UiOnsic3RhdHVzIjoyMDAsImhlYWRlcnMiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vaGFsK2pzb24ifX19XSwibWV0YWRhdGEiOnsicGFjdFNwZWNpZmljYXRpb24iOnsidmVyc2lvbiI6IjIuMC4wIn19fQ==",
2077
+ "onConflict": "merge"
2078
+ }
2079
+ ]
2080
+ }
2081
+ }
2082
+ ```
2083
+ Pact Broker will respond with:
2084
+ ```json
2085
+ {
2086
+ "status": 200,
2087
+ "headers": {
2088
+ "Content-Type": "application/hal+json;charset=utf-8"
2089
+ },
2090
+ "body": {
2091
+ "_embedded": {
2092
+ "pacticipant": {
2093
+ "name": "Foo"
2094
+ },
2095
+ "version": {
2096
+ "number": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
2097
+ "buildUrl": "http://build"
2098
+ }
2099
+ },
2100
+ "logs": [
2101
+ {
2102
+ "level": "info",
2103
+ "message": "some message"
2104
+ }
2105
+ ],
2106
+ "_links": {
2107
+ "pb:pacticipant-version-tags": [
2108
+ {
2109
+ "name": "dev"
2110
+ }
2111
+ ],
2112
+ "pb:contracts": [
2113
+ {
2114
+ "href": "http://some-pact"
2115
+ }
2116
+ ]
2117
+ }
2118
+ }
2119
+ }
2120
+ ```
2124
2121
  <a name="a_request_to_record_a_deployment_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment"></a>
2125
2122
  Given **version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment**, upon receiving **a request to record a deployment** from Pact Broker Client, with
2126
2123
  ```json
@@ -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
@@ -31,9 +31,7 @@ module PactBroker
31
31
  method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
32
32
  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"
33
33
  method_option :build_url, desc: "The build URL that created the pact"
34
- method_option :on_conflict, desc: "If a pact already exists for this consumer version and provider with different content, specify what action should be taken. Options are "
35
34
  method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
36
-
37
35
  output_option_json_or_text
38
36
  shared_authentication_options
39
37
 
@@ -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
@@ -28,7 +28,7 @@ module PactBroker
28
28
 
29
29
  def call
30
30
  validate
31
- if ENV.fetch("PACT_BROKER_FEATURES", "").include?("publish_contracts") && index_resource.can?("pb:publish-contracts")
31
+ if index_resource.can?("pb:publish-contracts")
32
32
  publish_pacts
33
33
  PactBroker::Client::CommandResult.new(success?, message)
34
34
  else
@@ -115,9 +115,8 @@ module PactBroker
115
115
  specification: "pact",
116
116
  contentType: "application/json",
117
117
  content: Base64.strict_encode64(pact_hash.to_json),
118
- writeMode: write_mode,
119
- onConflict: write_mode
120
- }
118
+ onConflict: on_conflict
119
+ }.compact
121
120
  end
122
121
  end
123
122
 
@@ -137,8 +136,8 @@ module PactBroker
137
136
  pact_files.collect(&:consumer_name).uniq
138
137
  end
139
138
 
140
- def write_mode
141
- options[:merge] ? "merge" : "overwrite"
139
+ def on_conflict
140
+ options[:merge] ? "merge" : nil
142
141
  end
143
142
 
144
143
  def validate