From b7682edb5e73cfceb7d7c7b7291f0d1b8b7fd293 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 5 Oct 2022 14:50:05 +0100 Subject: [PATCH] chore: deprecate tags/pact_changed workflows --- .github/workflows/verify_changed_pact.yml | 30 ----------------------- README.md | 26 ++++---------------- src/product/product.pact.test.js | 9 ++----- 3 files changed, 7 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/verify_changed_pact.yml diff --git a/.github/workflows/verify_changed_pact.yml b/.github/workflows/verify_changed_pact.yml deleted file mode 100644 index d254f9ae..00000000 --- a/.github/workflows/verify_changed_pact.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Verify changed pact - -# This workflow leverages the https://docs.pact.io/pact_broker/webhooks#the-contract-content-changed-event webhook - -on: - repository_dispatch: - types: - - pact_changed - -env: - PACT_BROKER_BASE_URL: https://test.pactflow.io - PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }} - PACT_BROKER_PUBLISH_VERIFICATION_RESULTS: true - GIT_COMMIT: ${{ github.sha }} - GITHUB_REF: ${{ github.ref }} - PACT_URL: ${{ github.event.client_payload.pact_url }} - -jobs: - verify-changed-pact: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta - with: - node-version: "12" - - run: docker pull pactfoundation/pact-cli:latest - - name: Install - run: npm i - - name: Build - run: GIT_BRANCH=${GITHUB_REF:11} make ci_webhook diff --git a/README.md b/README.md index ce6ecb2e..20c1881d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -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 diff --git a/src/product/product.pact.test.js b/src/product/product.pact.test.js index 4abc47d4..b3f5419d 100644 --- a/src/product/product.pact.test.js +++ b/src/product/product.pact.test.js @@ -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. @@ -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,