Created
May 18, 2018 22:59
-
-
Save surpher/485312dbc42289eac9b443ab19f970ff to your computer and use it in GitHub Desktop.
Publish a Pact contract to a Pact Broker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
################################################################################## | |
## Use pact-broker CLI tool instead of this script! | |
## https://github.com/pact-foundation/pact-ruby-standalone/releases | |
################################################################################## | |
## If for some reason can't use the pact-broker tool, the following could work... | |
## env vars: | |
## $pactBrokerAccount | |
## $pactBrokerUsername | |
## $pactBrokerPassword | |
################################################################################## | |
## Use | |
## ./pact_publish.sh 0.0.1 feature/member_details | |
## | |
############################# | |
## Note: this script always exits with 0! Even if it fails to publish or tag your | |
## Pact contract. | |
## | |
pactVersion=$1 | |
branch=$2 | |
consumerName='My Consumer Name' | |
providerName='My Provider Name' | |
url_encode() { | |
to_escape="$1" | |
echo "$to_escape" | sed 's/ /%20/' | tr '/' '_' | |
} | |
consumerNameEsc=`url_encode "$consumerName"` | |
providerNameEsc=`url_encode "$providerName"` | |
branchName=`url_encode "$branch"` | |
filename_encode() { | |
to_escape="$1" | |
echo "$to_escape" | tr '[ A-Z]' '[_a-z]' | |
} | |
consumerFilenameEsc=`filename_encode "$consumerName"` | |
providerFilenameEsc=`filename_encode "$providerName"` | |
baseUrl="https://$pactBrokerAccount.pact.dius.com.au" | |
pactUrl="$baseUrl/pacts/provider/$providerNameEsc/consumer/$consumerNameEsc/version/$pactVersion" | |
tagUrl="$baseUrl/pacticipants/$consumerNameEsc/versions/$pactVersion/tags/$branchName" | |
curl -v \ | |
-X PUT \ | |
-H 'Content-Type: application/json' \ | |
-d@"$BITRISE_SOURCE_DIR/tmp/pacts/$consumerFilenameEsc-$providerFilenameEsc.json" \ | |
-u "$pactBrokerUsername":"$pactBrokerPassword" \ | |
"$pactUrl" | |
curl -v \ | |
-X PUT \ | |
-H 'Content-Type: application/json' \ | |
-u "$pactBrokerUsername":"$pactBrokerPassword" \ | |
"$tagUrl" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment