Skip to content
Latchkey

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_URL and PACT_BROKER_TOKEN as CI secrets.
  • Compute the short sha and current branch.
  • Run pact-broker publish ./pacts with --consumer-app-version and --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

Run this faster and cheaper on Latchkey managed runners. Start free →