Skip to content

Commit

Permalink
Merge pull request #30 from pactflow/deprecate_old_workflows
Browse files Browse the repository at this point in the history
chore: deprecate tags/pact_changed workflows
  • Loading branch information
YOU54F authored Oct 6, 2022
2 parents 7ce8bc0 + b7682ed commit 2eb6f33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 58 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/verify_changed_pact.yml

This file was deleted.

26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ When using Pact in a CI/CD pipeline, there are two reasons for a pact verificati

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. Ideally, this would be a completely separate build from your normal provider pipeline, and it should just verify the changed pact.
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.

## Features

Expand All @@ -28,12 +28,9 @@ To ensure that a verification is also run whenever a pact changes, we create a w

* In [.github/workflows/contract_requiring_verification_published.yml](.github/workflows/contract_requiring_verification_published.yml)
* Recommended - This build is triggered by a webhook event, when a pact file changes and passes the url of the changed pact to the provider pact test to verify, as well as the branch and commit sha and checks out the provider codebase on the specified sha. See [here](https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event) for details on the `contract_requiring_verification_published` webhook

* In [.github/workflows/verify_changed_pact.yml](.github/workflows/verify_changed_pact.yml)
* Superceded by above - This build is triggered by a webhook event, when a pact file changes and passes the url of the changed pact to the provider pact test to verify. See [here](hhttps://docs.pact.io/pact_broker/webhooks#the-contract-published-event) for details on the `contract_content_changed` webhook

* In the [Makefile](Makefile):
* Recommended - Using the [contract requiring verification published](https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event) event
* Using the [contract requiring verification published](https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event) event
* The target `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.
* To call the Github API that triggers the build, the webhook uses a bearer token that is stored in a Pactflow secret called `${user.githubToken}`. The secret can be created using the `create_github_token_secret` target, or through the Pactflow UI.
* The target `ci` runs when the provider has pushed a new commit. It performs the following tasks:
Expand All @@ -45,25 +42,12 @@ To ensure that a verification is also run whenever a pact changes, we create a w
* The target `ci_webhook` just runs the pact verification step, and is used when the build is triggered by the webhook.
* The target `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.
* To call the Github API that triggers the build, the webhook uses a bearer token that is stored in a Pactflow secret called `${user.githubToken}`. The secret can be created using the `create_github_token_secret` target, or through the Pactflow UI.
* Superceded by above - Using the [contract content changed](https://docs.pact.io/pact_broker/webhooks#the-contract-content-changed-event) event
* The target `create_or_update_pact_changed_webhook` creates the Pactflow webhook that will trigger a build of the provider when any of its consumers publishes a pact with changed content.
* To call the Github API that triggers the build, the webhook uses a bearer token that is stored in a Pactflow secret called `${user.githubToken}`. The secret can be created using the `create_github_token_secret` target, or through the Pactflow UI.
* The target `ci` runs when the provider has pushed a new commit. It performs the following tasks:
* Run the isolated tests (including the pact verification tests, which publish the verification results)
* If we are on master:
* Check if we are safe to deploy to prod using `can-i-deploy` (ie. do we have a succesfully verified pact with the version of the consumer that is currently in production)
* Deploy (just pretend!)
* Record the deployed application version in Pactflow so Pactflow knows which version of the provider is in production when the consumer runs `can-i-deploy`.
* The target `ci_webhook` just runs the pact verification step, and is used when the build is triggered by the webhook.
* The target `create_or_update_pact_changed_webhook` creates the Pactflow webhook that will trigger a build of the provider when any of its consumers publishes a pact with changed content.
* To call the Github API that triggers the build, the webhook uses a bearer token that is stored in a Pactflow secret called `${user.githubToken}`. The secret can be created using the `create_github_token_secret` target, or through the Pactflow UI.

* In [src/product/product.pact.test.js](src/product/product.pact.test.js):
* When the `$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 tagged with `master` 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.
* When the `$PACT_URL` is set (ie. the build is running because it was triggered by the 'contract content changed' webhook), we just verify the pact at the `$PACT_URL`.
* When the `$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.
* When the `$PACT_URL` is set (ie. the build is running because it was triggered by the ['contract requiring verification published'](https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event) webhook, we just verify the pact at the `$PACT_URL` against the head, test and production versions of the provider.
* Pact-JS has a very flexible verification task configuration that allows us to use the same code for both the main pipeline verifications and the webhook-triggered verifications, with dynamically set options. Depending on your pact implementation, you may need to define separate tasks for each of these concerns.
* When the verification results are published, the provider version number is set to the git sha, and the provider version branch is the git branch name (recommended) or provider version tag is the git branch name (superceded by branch property). You can read more about versioning [here](https://docs.pact.io/getting_started/versioning_in_the_pact_broker).
* Recommended - The `providerVersionBranch` property is set, so that verification results are published with the branch property which is important for the [contract requiring verification published](https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event) event
* When the verification results are published, the provider version number is set to the git sha, and the provider version branch is the git branch name. You can read more about versioning [here](https://docs.pact.io/getting_started/versioning_in_the_pact_broker).

## Usage

Expand Down
9 changes: 2 additions & 7 deletions src/product/product.pact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ describe("Pact Verification", () => {
logLevel: "INFO",
providerBaseUrl: "http://localhost:8080",
providerVersion: process.env.GIT_COMMIT,
// providerVersionTags: process.env.GIT_BRANCH ? [process.env.GIT_BRANCH] : [], // the old way of publishing verification results with the tag property
providerVersionBranch: process.env.GIT_BRANCH
? process.env.GIT_BRANCH
: "", // the recommended way of publishing verification results with the branch property
verbose: process.env.VERBOSE === "true",
};

// For builds triggered by a 'contract_content_changed' just verify the changed pact.
// https://docs.pact.io/pact_broker/webhooks#the-contract-content-changed-event
// For builds trigged by a 'contract_requiring_verification_published' webhook, verify the changed pact against latest of mainBranch and any version currently deployed to an environment
// https://docs.pact.io/pact_broker/webhooks#using-webhooks-with-the-contract_requiring_verification_published-event
// The URL will bave been passed in from the webhook to the CI job.
Expand All @@ -37,12 +34,10 @@ describe("Pact Verification", () => {
// https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors
const fetchPactsDynamicallyOpts = {
provider: "pactflow-example-provider",
//consumerVersionTag: ['master', 'prod'], // the old way of specifying which pacts to verify if using tags
// consumerVersionSelectors: [{ tag: 'master', latest: true }, { deployed: true } ], // the newer way of specifying which pacts to verify if using tags
consumerVersionSelectors: [
consumerVersionSelectors: [
{ mainBranch: true },
{ deployed: true },
], // the new way of specifying which pacts to verify if using branches (recommended)
],
pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,
enablePending: false,
includeWipPactsSince: undefined,
Expand Down

0 comments on commit 2eb6f33

Please sign in to comment.