Skip to main content

Branches

From version 2.82.0 onwards, the Pact Broker supports repository branches as a first class concept. Previously, users were recommended to use version tags to represent the branch with which a particular pacticipant version was associated. Adding explict support for branches allows the Pact Broker to provide simpler documentation, better messaging and sensible defaults.

Domain model#

Branches in the Pact Broker are designed to model repository (git, svn etc) branches. A branch in the Pact Broker belongs to a pacticipant (application). A branch may have many pacticipant versions, and a pacticipant version may belong to many branches (but typically, it will belong to just one).

Remember that a pacticipant version in the Pact Broker should map 1:1 to a commit in your repository. To facilitate this, the version number used to publish pacts and verification results should either be or contain the commit.

When are branches created?#

Branches are automatically created and associated with a pacticipant version when pacts and verification results are published. Check the support section to see if your Pact library supports this feature yet.

Configuring the branch when publishing pacts#

See here for full docs.

pact-broker publish ./pacts --consumer-app-version $GIT_COMMIT --branch $GIT_BRANCH
# or
pact-broker publish ./pacts --auto-detect-version-properties

Configuring the branch when publishing verification results#

See here for full docs.

pact-provider-verifier \
--provider "Example API" \
--provider-app-version $GIT_COMMIT \
--provider-version-branch $GIT_BRANCH \
...

When are branches used?#

Branches are used to identify which pacts a provider should verify using consumer version selectors. Typically, the provider should be configured to verify the pacts belonging to the main branch of each consumer (amongst others - read more here). Branches are also used to calculate the pending status of a pact and identify work in progress pacts.

Automatic branch creation from first tag#

To assist in the migration from tags to branches, the Pact Broker from 2.82.0 supports the configuration option use_first_tag_as_branch. When set to true, the first tag applied to a pacticipant version (within a given timeframe) will be inferred to be the branch. To disable this, set use_first_tag_as_branch to false.

Pacticipant main branch property#

From version 2.82.0 onwards, the pacticipant resource supports a mainBranch property. This property is used to identify which versions to display first in the UI, and the branch for which a build should be run when the contract_requiring_verification_published webhook is triggered.

Automatic main branch detection#

To assist in the migration from tags to branches, the main branch will be automatically set for a pacticipant if a version is created with a branch or tag name matching one of develop, main, or master.

The main branch candidate names are configurable. To disable the automatic setting of the main branch, set auto_detect_main_branch to false.

Checking the main branch value#

Use describe-pacticipant to check if the main branch is configured.

pact-broker describe-pacticipant --name Foo

Setting the main branch manually#

To explicitly set the main branch of a pacticipant, use the Pact Broker Client create-or-update-pacticipant command.

pact-broker create-or-update-pacticipant --name Foo --main-branch dev

Support#

Support for publishing pacts and verification results with branches is currently (late 2021) being rolled out across the Pact client libraries.

  • Pact Ruby - v1.59.0
  • Ruby Dockerized pact-provider-verifier - v1.36.0
  • Pact JS - TBC
  • Pact Go - TBC
  • Pact Rust - TBC
  • Pact JVM - TBC
  • Pact NET - TBC
  • Pact Python - TBC
  • Pact Scala - TBC
  • Pact4s - TBC
  • Pact PHP - TBC

Migrating from tags to branches#

Note the Automatic branch creation feature mentioned above.

  • Upgrade to the latest version of your Pact client library (see the support section above).
  • Upgrade to Pact Broker version 2.82.0 or later.
  • If your main branch is called something other than develop, main or master, set the main branch manually
  • Set the branch property when publishing pacts and/or verification results.
  • In the provider, update the consumer version selectors from { "tag": "<branch_name>"} to { "branch": "<branch_name>"}

FAQ#

We never use feature branches - do I need to set the branch properties?#

Yes. Even if you only ever use one branch, it is recommended to set the branch property when publishing pacts and verification results, and to set the pacticipant's mainBranch property. This will allow the Pact Broker to distinguish between a poorly configured Pact Broker (where none of those are populated) and a trunk based workflow.

Last updated on by Beth Skurrie