Skip to main content

Publishing Drift Results to PactFlow

Working example

The example-bi-directional-provider-drift repository demonstrates a complete BDCT setup with Drift. Use it as a reference alongside this guide.

For a browser-based, interactive walkthrough, try the Killercoda BDCT tutorial.

After running Drift tests against your API, you can publish the results to PactFlow. This integrates your provider verification with PactFlow's Bi-Directional Contract Testing (BDCT) feature, giving you a complete picture of contract adherence across your system.

What You'll Learn

By the end of this guide, you'll be able to:

  • Run Drift tests and capture results
  • Publish verification results to PactFlow
  • View results in the PactFlow UI
  • Enable BDCT for comprehensive contract testing

Prerequisites

Before publishing to PactFlow, you need:

  • PactFlow Account: Sign up for a free account
  • API Token: From your PactFlow account settings
  • Drift Installed: On your system or available in CI/CD
  • OpenAPI Specification: Published in your repository
  • Test Results: From running drift verify

Setting Up Authentication

Set these environment variables in your CI/CD system:

export PACT_BROKER_BASE_URL="https://your-pact-broker.example.com"
export PACT_BROKER_TOKEN="your-api-token"

Finding your token: Log in to PactFlow → Settings → API Tokens → Copy token

How It Works

┌──────────────────┐
│ Run Drift Tests │
└────────┬─────────┘

├─ Executes drift verify with --generate-result

├─ Generates PactFlow-specific verification bundle
│ (output/results/verification.{timestamp}.result)


┌──────────────────────────────┐
│ Publish to PactFlow │
│ pactflow publish-provider... │
└────────┬─────────────────────┘

├─ Sends OpenAPI spec

├─ Sends verification results

├─ Associates with provider version


┌────────────────────────────┐
│ PactFlow BDCT Dashboard │
│ - Contract verification │
│ - Coverage insights │
│ - Consumer/Provider view │
└────────────────────────────┘

Step 1: Run Drift Tests generating a PactFlow Verification Result Bundle

First, run your Drift tests with the --generate-result flag to generate a PactFlow-specific verification bundle:

drift verify \
--test-files drift.yaml \
--server-url http://localhost:8080 \
--output-dir ./output \
--generate-result

The --generate-result flag tells Drift to generate a special report format for PactFlow integration. This creates a verification result file with a timestamp in the name:

output/results/verification.20260211221227.result

The file follows the pattern: verification.{timestamp}.result where the timestamp is in YYYYMMDDHHmmss format.

Check that the bundle was generated:

ls -la output/results/verification.*.result

Step 2: Publish Results to PactFlow

After Drift tests complete, publish the results using the pactflow CLI. You'll need to reference the generated verification bundle file:

# Capture the exit code from Drift
EXIT_CODE=$?

# Find the generated verification bundle
VERIFICATION_FILE=$(ls output/results/verification.*.result | head -n 1)

# Publish to PactFlow
pactflow publish-provider-contract \
openapi.yaml \
--provider "my-product-api" \
--provider-app-version "$(git rev-parse --short HEAD)" \
--branch "$(git rev-parse --abbrev-ref HEAD)" \
--content-type application/yaml \
--verification-exit-code $EXIT_CODE \
--verification-results "$VERIFICATION_FILE" \
--verification-results-content-type application/vnd.smartbear.drift.result \
--verifier drift

Key parameters:

  • --provider - Unique name for your API (e.g., product-api, auth-service)
  • --provider-app-version - Version identifier (commit SHA, tag, build number)
  • --branch - Git branch name for tracking across versions
  • --content-type application/yaml - Your OpenAPI spec format
  • --verification-exit-code - Exit code from Drift (0 = success)
  • --verification-results - Path to the generated verification bundle file (e.g., output/results/verification.20260211221227.result)
  • --verification-results-content-type application/vnd.smartbear.drift.result - Must be this exact value
  • --verifier drift - Identifies Drift as the verification tool

Step 3: View the results in PactFlow UI

TBC

Example Github Workflow

Create .github/workflows/contract-tests.yml:

name: Contract Tests

on:
push:
branches:
- main
- develop
pull_request:

jobs:
contract-tests:
runs-on: ubuntu-latest

services:
# Your API server (if needed)
api:
image: your-api:latest
ports:
- 8080:8080

steps:
- uses: actions/checkout@v3

- name: Install Drift
run: |
wget -O - https://download.pactflow.io/drift/latest/linux-x86_64.tgz | tar xz -C /usr/local/bin
drift --version

- name: Install PactFlow CLI
run: |
npm install -g @pactfoundation/pact-cli

- name: Run Drift Tests
run: |
drift verify \
--test-files drift.yaml \
--server-url http://localhost:8080 \
--output-dir ./output \
--generate-result
continue-on-error: true # Continue even if tests fail, to publish results

- name: Publish Results to PactFlow
if: always() # Run even if tests failed
run: |
export EXIT_CODE=${{ job.status == 'success' && '0' || '1' }}
export VERIFICATION_FILE=$(ls output/results/verification.*.result | head -n 1)

pactflow publish-provider-contract \
openapi.yaml \
--provider "my-product-api" \
--provider-app-version "${{ github.sha }}" \
--branch "${{ github.ref_name }}" \
--content-type application/yaml \
--verification-exit-code $EXIT_CODE \
--verification-results "$VERIFICATION_FILE" \
--verification-results-content-type application/vnd.smartbear.drift.result \
--verifier drift
env:
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: drift-results
path: output/

Setup in GitHub:

  1. Go to repository → Settings → Secrets and variables → Actions
  2. Add PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN
  3. Push to trigger the workflow