This is an example of a Node provider that uses Pact, PactFlow and Github Actions to ensure that it is compatible with the expectations its consumers have of it.
It is using a public tenant on PactFlow, which you can access here using the credentials dXfltyFMgNOFZAxr8io9wJ37iUpY42M
/O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
. The latest version of the Example PactFlow Consumer/Example PactFlow Provider pact is published here.
When using Pact in a CI/CD pipeline, there are two reasons for a pact verification task to take place:
When the provider changes, the pact verification task runs as part the provider's normal build pipeline, generally after the unit tests, and before any deployment takes place. This pact verification task is configured to dynamically fetch all the relevant pacts for the specified provider from PactFlow, verify them, and publish the results back to PactFlow.
To ensure that a verification is also run whenever a pact changes, we create a webhook in PactFlow that triggers a provider build, and passes in the URL of the changed pact, to verify it against the head and deployed/released versions of the provider. Ideally, this would be a completely separate build from your normal provider pipeline, and it should just verify the changed pact.
In .github/workflows/build.yml
In .github/workflows/contract_requiring_verification_published.yml
contract_requiring_verification_published
webhookIn the Makefile:
create_or_update_contract_requiring_verification_published_webhook
creates the PactFlow webhook that will trigger a build of the provider when any of its consumers publishes a pact with changed content.${user.githubToken}
. The secret can be created using the create_github_token_secret
target, or through the PactFlow UI.ci
runs when the provider has pushed a new commit. It performs the following tasks:
can-i-deploy
(ie. do we have a succesfully verified pact with the version of the consumer that is currently in production)can-i-deploy
.ci_webhook
just runs the pact verification step, and is used when the build is triggered by the webhook.create_or_update_contract_requiring_verification_published_webhook
creates the PactFlow webhook that will trigger a build of the provider when any of its consumers publishes a pact with changed content.${user.githubToken}
. The secret can be created using the create_github_token_secret
target, or through the PactFlow UI.In src/product/product.providerChange.pact.test.js:
$PACT_URL
is not set (ie. the build is running because the provider changed), the provider is configured to fetch all the pacts for the 'example-provider' provider which belong to the latest consumer versions associated with their main branch and those currently deployed to an environment. This ensures the provider is compatible with the latest changes that the consumer has made, and is also backwards compatible with the production/test versions of the consumer.$PACT_URL
is set (ie. the build is running because it was triggered by the 'contract requiring verification published' webhook, we just verify the pact at the $PACT_URL
against the head, test and production versions of the provider.See the PactFlow CI/CD Workshop.