Configure consumer and provider pipelines
Setup deployment environment
Note
This step should only be required if you have a legacy API Hub for Contract Testing account. New users should automatically have a production account created and can move onto the configure consumer pipeline step.
Create a new production environment to record deployments against
Log in to your API Hub for Contract Testing account (
https://<your-subdomain>.pactflow.io
), and go to Settings > Environments.Click Add Environment.
Enter
production
for the name and display name.Check the "this is a production environment" checkbox.
Select the default team.
Click "Create".
Configure consumer pipeline
The source repositories are configured to use the the public broker at test.pactflow.io. You will need to update the credentials to point to your own API Hub for Contract Testing account. To do this, we need to update the PACT_BROKER_BASE_URL
environment variable in the Github workflow file, and create a Github Secret to store the API Hub for Contract Testing API token in.
Create a Github Secret to store your API Hub for Contract Testing API token in
In API Hub for Contract Testing:
Log in to your API Hub for Contract Testing account (
https://<your-subdomain>.pactflow.io
), and go to Settings > API Tokens.Click the Copy button for the read/write CI token (make sure it's the read write one, not the read only one).
In Github:
Open your forked
example-consumer
project (https://github.com/<your-username>/example-consumer
)Click on the
Settings
tab.Open the
Secrets and variables
dropdown in the side menu.Select Actions from the dropdown
Click the
New repository secret
buttonSet the name of the secret to
PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP
Paste in the API Hub for Contract Testing API token value you copied in the previous step.
Update your workflow files in GitHub to point at your API Hub for Contract Testing Broker
In API Hub for Contract Testing:
Go to Settings > API Tokens.
Click the
COPY PACTFLOW BASE URL
button
In Github:
Open your forked
example-consumer
project (https://github.com/<your-username>/example-consumer
)Open
.github/workflows/build.yml
In the upper right corner of the file view, click 🖊️ to open the file editor.
Update the value of
PACT_BROKER_BASE_URL
to the base URL of your own API Hub for Contract Testing account. You can easily get this by clicking the COPY PACTFLOW BASE URL button on the API Tokens page in API Hub for Contract Testing.Press the green
Commit changes
button
View the build:
In Github:
Select the most recent build, this will have been triggered when you committed the changes in the last page
Note
This build should now successfully publish the pact, but it will fail on the can-i-deploy
step before it tries to deploy.This is because the provider has not published a successful verification result for the pact.
Configure provider pipeline
🔁 Repeat the above instructions to configure the API Hub for Contract Testing account for your provider project.
⚠️ There are TWO workflow files to be updated in the provider project -
.github/workflows/build.yml
.github/workflows/contract_requiring_verification_published.yml
After you have pushed your changes to the workflow files, the provider pipeline will run, fetching and verifying the configured pacts from your API Hub for Contract Testing account, and publishing the results back. The can-i-deploy
command will pass, and allow the provider to be deployed. ✅
Back to the consumer
✅ To make both your builds go green, we are going to retry can-i-deploy, now that the consumer is deployed to production.
Find the latest failing
example-consumer
workflow in the GithubActions
page (Actions
-> UnderWorkflows
, selectBuild
->failing build
).In the top right on of the failing job page, select to Re-run the failed jobs (can-i-deploy) (
Actions
-> UnderRe-run jobs
, selectRe-run failed jobs
).The test run should be pre-passing
The
can-i-deploy
step should now pass - our consumer is safe to deploy, now that our provider published a verification result, and is deployed to productionIf you click on the step you should see a successful verification result, andComputer says yes \o/
The
deploy
step should pass too - our consumer is deployed to production, and we record this with therecord-deployment
command, marking this application version of our consumer as deployed toproduction
Expected state by the end of this step
Both consumer and provider builds passing ✅