Use whenever two services (a frontend and an API, or two microservices) keep breaking each other's API: set up Pact consumer-driven contract tests, publish pacts to a broker, verify the provider and gate deploys with can-i-deploy.
91%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
A complete CI flow per side wires publish, provider verification, and the
can-i-deploy gate into the pipeline. Both sides read PACT_BROKER_BASE_URL
and PACT_BROKER_TOKEN from CI secrets.
- name: Run consumer tests + publish pact
env:
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
run: |
npm test # writes ./pacts/<consumer>-<provider>.json
npx pact-broker publish ./pacts \
--consumer-app-version=$GITHUB_SHA \
--branch=${GITHUB_REF##*/}
- name: Can I deploy?
env:
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
run: |
pact-broker can-i-deploy \
--pacticipant=web-app \
--version=$GITHUB_SHA \
--to-environment=production- name: Verify pacts from broker
env:
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
run: |
npm run start:provider &
npx wait-on http://localhost:8081
npm run verify:pact # publishVerificationResult: true
- name: Can I deploy?
env:
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
run: |
pact-broker can-i-deploy \
--pacticipant=pet-service \
--version=$GITHUB_SHA \
--to-environment=productioncan-i-deploy is the actual gate - pact verification happens in step 1, but a
green verification alone doesn't prove every paired version is compatible.