Publishing Drift Results to PactFlow
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.
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
Drift Installed: On your system or available in CI/CD
Test Results: From running
drift verifier
Setting Up Authentication
Set these environment variables in your CI/CD system:
export PACTFLOW_BASE_URL="https://your-workspace.pactflow.io" export PACTFLOW_TOKEN="your-api-token"
Finding your token: Log in to PactFlow → Settings → API Tokens → Copy token
How It Works
┌──────────────────┐
│ Run Drift Tests │
└────────┬─────────┘
│
├─ Executes drift verifier 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 │
└────────────────────────────┘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 verifier \ --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
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
View the results in PactFlow UI
After publishing the provider contract and Drift verification result, open the provider version in PactFlow to review the verification outcome, contract details, and BDCT status. Confirm that the published version is associated with the expected branch and application version, then use the PactFlow UI to inspect compatibility before release.
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 verifier \
--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:
PACTFLOW_BASE_URL: ${{ secrets.PACTFLOW_BASE_URL }}
PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: drift-results
path: output/Setup in GitHub
Go to repository → Settings → Secrets and variables → Actions.
Add PACTFLOW_BASE_URL and PACTFLOW_TOKEN.
Push to trigger the workflow.