How to Publish Pacts to a Pact Broker or PactFlow
Publishing sends each pact to the broker under a consumer version equal to the git sha so provider verification and can-i-deploy can find it.
Use pact-broker publish with --consumer-app-version set to the commit sha and --branch set to the current branch. The broker stores the contract and its version metadata.
Steps
- Set
PACT_BROKER_BASE_URLandPACT_BROKER_TOKENas CI secrets. - Compute the short sha and current branch.
- Run
pact-broker publish ./pactswith--consumer-app-versionand--branch.
Publish step
.github/workflows/ci.yml
- name: Publish pacts
env:
PACT_BROKER_BASE_URL: ${{ vars.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
run: |
npx pact-broker publish ./pacts \
--consumer-app-version "${GITHUB_SHA}" \
--branch "${GITHUB_REF_NAME}"Gotchas
- Always version by an immutable identifier like the git sha, never a static string, or can-i-deploy cannot distinguish releases.
- Publishing the same version twice is idempotent as long as the content matches.
Related guides
How to Verify a Provider Against Pacts in CIRun provider verification in CI so the provider fetches consumer pacts from the broker, replays each interact…
How to Handle PACT_BROKER_TOKEN Secrets in CIStore the Pact Broker token as a GitHub Actions secret, expose it only to the steps that publish or verify, a…