Skip to content

Commit

Permalink
feat: enabled deployment, release and environment commands without a …
Browse files Browse the repository at this point in the history
…feature toggle
  • Loading branch information
bethesque committed Jul 8, 2021
1 parent 6f6ca2f commit bd64caa
Show file tree
Hide file tree
Showing 10 changed files with 641 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
feature: ["", "publish_contracts", "deployments"]
feature: ["", "publish_contracts"]
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
315 changes: 315 additions & 0 deletions doc/pacts/markdown/Pact Broker Client - Pact Broker.md

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ class VersionCreationError < ::Thor::Error; end

class Broker < CustomThor
using PactBroker::Client::HashRefinements
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
include PactBroker::Client::CLI::EnvironmentCommands
include PactBroker::Client::CLI::DeploymentCommands
end

include PactBroker::Client::CLI::EnvironmentCommands
include PactBroker::Client::CLI::DeploymentCommands
include PactBroker::Client::CLI::PacticipantCommands
include PactBroker::Client::CLI::WebhookCommands


desc 'can-i-deploy', ''
long_desc File.read(File.join(__dir__, 'can_i_deploy_long_desc.txt'))

Expand Down
2 changes: 1 addition & 1 deletion script/record-deployment.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PACT_BROKER_FEATURES=deployments bundle exec bin/pact-broker record-deployment \
bundle exec bin/pact-broker record-deployment \
--pacticipant foo-consumer --version 1 --environment prod --broker-base-url http://localhost:9292
2 changes: 0 additions & 2 deletions script/record-deployments-and-releases.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export PACT_BROKER_FEATURES=deployments

bundle exec bin/pact-broker create-or-update-pacticipant --name Foo
bundle exec bin/pact-broker create-version-tag --pacticipant Foo --version 2 --tag main --auto-create-version
bundle exec bin/pact-broker describe-version --pacticipant Foo --version 2
Expand Down
2 changes: 1 addition & 1 deletion script/record-undeployment.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PACT_BROKER_FEATURES=deployments bundle exec bin/pact-broker record-undeployment \
bundle exec bin/pact-broker record-undeployment \
--pacticipant foo-consumer --version 1 --environment prod --broker-base-url http://localhost:9292 --output json --verbose


317 changes: 317 additions & 0 deletions spec/pacts/pact_broker_client-pact_broker.json
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,323 @@
}
}
},
{
"description": "a request for the index resource",
"providerState": "the pb:pacticipant-version and pb:environments relations exist in the index resource",
"request": {
"method": "GET",
"path": "/",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_links": {
"pb:pacticipant-version": {
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
},
"pb:environments": {
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS"
}
}
},
"matchingRules": {
"$.body._links.pb:pacticipant-version.href": {
"match": "regex",
"regex": "http:\\/\\/.*{pacticipant}.*{version}"
},
"$.body._links.pb:environments.href": {
"match": "regex",
"regex": "http:\\/\\/.*"
}
}
}
},
{
"description": "a request for a pacticipant version",
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
"request": {
"method": "GET",
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_links": {
"pb:record-deployment": [
{
"name": "test",
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST"
}
]
}
},
"matchingRules": {
"$.body._links.pb:record-deployment[0].href": {
"match": "regex",
"regex": "http:\\/\\/.*"
}
}
}
},
{
"description": "a request to record a deployment",
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
"request": {
"method": "POST",
"path": "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
"headers": {
"Content-Type": "application/json",
"Accept": "application/hal+json"
},
"body": {
"target": "blue"
}
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"target": "blue"
}
}
},
{
"description": "a request for a pacticipant version",
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment",
"request": {
"method": "GET",
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_links": {
"pb:record-deployment": [
{
"name": "prod",
"href": "href"
},
{
"name": "dev",
"href": "href"
}
]
}
},
"matchingRules": {
"$.body._links.pb:record-deployment[0]": {
"match": "type"
},
"$.body._links.pb:record-deployment[1]": {
"match": "type"
}
}
}
},
{
"description": "a request for the environments",
"providerState": "an environment with name test exists",
"request": {
"method": "GET",
"path": "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_links": {
"pb:environments": [
{
"name": "test",
"href": "href"
}
]
}
},
"matchingRules": {
"$.body._links.pb:environments[0].href": {
"match": "type"
}
}
}
},
{
"description": "a request for a pacticipant version",
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for release",
"request": {
"method": "GET",
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_links": {
"pb:record-release": [
{
"name": "test",
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-RECORD-RELEASE-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST"
}
]
}
},
"matchingRules": {
"$.body._links.pb:record-release[0].href": {
"match": "regex",
"regex": "http:\\/\\/.*"
}
}
}
},
{
"description": "a request to record a release",
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
"request": {
"method": "POST",
"path": "/HAL-REL-PLACEHOLDER-PB-RECORD-RELEASE-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
"headers": {
"Content-Type": "application/json",
"Accept": "application/hal+json"
}
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
}
}
},
{
"description": "a request for an environment",
"providerState": "an environment with name test and UUID 16926ef3-590f-4e3f-838e-719717aa88c9 exists",
"request": {
"method": "GET",
"path": "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENT-16926ef3-590f-4e3f-838e-719717aa88c9",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_links": {
"pb:currently-deployed-deployed-versions": {
"href": "http://localhost:1234/PLACEHOLDER-ENVIRONMENT-CURRENTLY-DEPLOYED-16926ef3-590f-4e3f-838e-719717aa88c9"
}
}
},
"matchingRules": {
"$.body._links.pb:currently-deployed-deployed-versions.href": {
"match": "regex",
"regex": "^http.*"
}
}
}
},
{
"description": "a request to list the versions deployed to an environment for a pacticipant name and target",
"providerState": "an version is deployed to environment with UUID 16926ef3-590f-4e3f-838e-719717aa88c9 with target customer-1",
"request": {
"method": "GET",
"path": "/PLACEHOLDER-ENVIRONMENT-CURRENTLY-DEPLOYED-16926ef3-590f-4e3f-838e-719717aa88c9",
"query": "pacticipant=Foo",
"headers": {
"Accept": "application/hal+json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"_embedded": {
"deployedVersions": [
{
"target": "customer-1",
"_links": {
"self": {
"href": "http://localhost:1234/PLACEHOLDER-DEPLOYED-VERSION-ff3adecf-cfc5-4653-a4e3-f1861092f8e0"
}
}
}
]
}
},
"matchingRules": {
"$.body._embedded.deployedVersions[0]._links.self.href": {
"match": "regex",
"regex": "^http"
}
}
}
},
{
"description": "a request to mark a deployed version as not currently deploye",
"providerState": "a currently deployed version exists",
"request": {
"method": "PATCH",
"path": "/PLACEHOLDER-DEPLOYED-VERSION-ff3adecf-cfc5-4653-a4e3-f1861092f8e0",
"headers": {
"Content-Type": "application/merge-patch+json"
},
"body": {
"currentlyDeployed": false
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"currentlyDeployed": false,
"_embedded": {
"version": {
"number": "2"
}
}
},
"matchingRules": {
"$.body._embedded.version.number": {
"match": "type"
}
}
}
},
{
"description": "a request to create a webhook with a JSON body for a consumer and provider",
"providerState": "the 'Pricing Service' and 'Condor' already exist in the pact-broker",
Expand Down
4 changes: 1 addition & 3 deletions spec/service_providers/record_deployment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'service_providers/pact_helper'
require 'pact_broker/client/deployments/record_deployment'

deployment_feature_on = ENV.fetch('PACT_BROKER_FEATURES', '').include?("deployments")

RSpec.describe "recording a deployment", pact: true, skip: !deployment_feature_on do
RSpec.describe "recording a deployment", pact: true do
include_context "pact broker"
include PactBrokerPactHelperMethods

Expand Down
4 changes: 1 addition & 3 deletions spec/service_providers/record_release_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'service_providers/pact_helper'
require 'pact_broker/client/deployments/record_deployment'

deployment_feature_on = ENV.fetch('PACT_BROKER_FEATURES', '').include?("deployments")

RSpec.describe "recording a release", pact: true, skip: !deployment_feature_on do
RSpec.describe "recording a release", pact: true do
include_context "pact broker"
include PactBrokerPactHelperMethods

Expand Down
4 changes: 1 addition & 3 deletions spec/service_providers/record_undeployment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'service_providers/pact_helper'
require 'pact_broker/client/deployments/record_undeployment'

deployment_feature_on = ENV.fetch('PACT_BROKER_FEATURES', '').include?("deployments")

RSpec.describe "recording an undeployment", pact: true, skip: !deployment_feature_on do
RSpec.describe "recording an undeployment", pact: true do
include_context "pact broker"
include PactBrokerPactHelperMethods

Expand Down

0 comments on commit bd64caa

Please sign in to comment.