Skip to content

Commit

Permalink
feat: support contract_requiring_verification_published_webhook flow
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Oct 17, 2024
1 parent 67cff06 commit 60ae049
Show file tree
Hide file tree
Showing 5 changed files with 1,947 additions and 1,234 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/contract_requiring_verification_published.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: contract_requiring_verification_published

# This workflow leverages the https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event webhook

on:
repository_dispatch:
types:
- contract_requiring_verification_published
workflow_dispatch:
# inputs aren't available on push, so we set them explicitly in separate steps
inputs:
PACT_URL:
description: URL of pact to verify
required: true

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
PACT_URL: ${{ github.event.client_payload.pact_url }}
GIT_COMMIT: ${{ github.event.client_payload.sha }}
GIT_BRANCH: ${{ github.event.client_payload.branch }}
DESCRIPTION: ${{ github.event.client_payload.message }}

jobs:
verify-contract-requiring-verification:
runs-on: ubuntu-latest
steps:
- name: checkout default branch if user manually provides pact URL
uses: actions/checkout@v3
if: ${{ github.event.inputs.PACT_URL }}
- name: checkout specific SHA if webhook providers pact URL
uses: actions/checkout@v3
if: ${{ github.event.client_payload.pact_url }}
with:
ref: ${{env.GIT_COMMIT}}
- uses: actions/setup-node@v3
with:
node-version: '16'
- run: docker pull pactfoundation/pact-cli:latest
- name: Install
run: npm i
- name: ${{env.DESCRIPTION}}
run: make ci_webhook
28 changes: 0 additions & 28 deletions .github/workflows/verify_changed_pact.yml

This file was deleted.

20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PACTICIPANT := "pactflow-example-provider-js-sns"
GITHUB_REPO := "pactflow/example-provider-js-sns"
PACT_CHANGED_WEBHOOK_UUID := "0278fe46-09be-4b9d-b037-559d2891f752"
CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID := "0278fe46-09be-4b9d-b037-559d2891f752"
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:latest"
AWS_CLI:="docker run --rm -it -e AWS_ACCESS_KEY_ID=1234 -e AWS_SECRET_ACCESS_KEY=1234 amazon/aws-cli --region ap-southeast-2"
AWS_SNS_ENDPOINT := http://localhost:4566
Expand Down Expand Up @@ -82,20 +82,20 @@ create_github_token_secret:

# NOTE: the github token secret must be created (either through the UI or using the
# `create_travis_token_secret` target) before the webhook is invoked.
create_or_update_pact_changed_webhook:
create_or_update_contract_requiring_verification_published_webhook:
"${PACT_CLI}" \
broker create-or-update-webhook \
"https://api.github.com/repos/${GITHUB_REPO}/dispatches" \
--header 'Content-Type: application/json' 'Accept: application/vnd.github.everest-preview+json' 'Authorization: Bearer $${user.githubToken}' \
--request POST \
--data '{ "event_type": "pact_changed", "client_payload": { "pact_url": "$${pactbroker.pactUrl}" } }' \
--uuid ${PACT_CHANGED_WEBHOOK_UUID} \
--consumer ${PACTICIPANT} \
--contract-content-changed \
--description "Pact content changed for ${PACTICIPANT}"

test_pact_changed_webhook:
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${PACT_CHANGED_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"
--data '{ "event_type": "contract_requiring_verification_published","client_payload": { "pact_url": "$${pactbroker.pactUrl}", "sha": "$${pactbroker.providerVersionNumber}", "branch":"$${pactbroker.providerVersionBranch}" , "message": "Verify changed pact for $${pactbroker.consumerName} version $${pactbroker.consumerVersionNumber} branch $${pactbroker.consumerVersionBranch} by $${pactbroker.providerVersionNumber} ($${pactbroker.providerVersionDescriptions})" } }' \
--uuid ${CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID} \
--provider ${PACTICIPANT} \
--contract-requiring-verification-published \
--description "contract_requiring_verification_published for ${PACTICIPANT}"

test_contract_requiring_verification_published_webhook:
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"

## ======================
## Misc
Expand Down
Loading

0 comments on commit 60ae049

Please sign in to comment.