Pact - Verify Provider Contract #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A workflow that's triggered by a webhook from Pact Broker/PactFlow when a new `Consumer` contract version is published. | |
# The workflow runs the `Provider` contract tests against the new `Consumer` contract version, | |
# and publishes the verification results back to the Pact Broker/PactFlow. | |
name: Pact - Verify Provider Contract | |
on: | |
repository_dispatch: | |
types: | |
- 'Pact: Consumer contract requiring verification published' | |
workflow_dispatch: | |
inputs: | |
provider: | |
type: choice | |
description: Provider name | |
required: true | |
default: all | |
options: | |
- all | |
- customers__rest | |
- customers__sns | |
- frontend__graphql | |
- frontend__rest | |
- order_history__graphql | |
- order_history__sns | |
- orders__rest | |
- orders__sns | |
pact_url: | |
type: string | |
description: Pact URL to verify | |
required: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_BUILDKIT: 1 | |
GIT_BRANCH: ${{ github.event.client_payload.branch }} | |
GIT_COMMIT: ${{ github.event.client_payload.sha }} | |
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }} | |
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} | |
PACT_PROVIDER: ${{ inputs.provider || github.event.client_payload.pytest_selector }} | |
PACT_PUBLISH_VERIFICATION_RESULTS: true | |
PACT_URL: ${{ inputs.pact_url || github.event.client_payload.pact_url }} | |
POETRY_VIRTUALENVS_CREATE: false | |
PYTHONPATH: src | |
strategy: | |
max-parallel: 1 | |
matrix: | |
python-version: ['3.11'] | |
steps: | |
- name: Checkout default branch (user run) | |
uses: actions/checkout@v4 | |
if: ${{ inputs.provider }} | |
- name: Checkout specific commit (workflow dispatch) | |
uses: actions/checkout@v4 | |
if: ${{ github.event.client_payload.sha }} | |
with: | |
ref: ${{ github.event.client_payload.sha }} | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Set up Poetry cache for Python dependencies | |
uses: actions/cache@v3 | |
if: startsWith(runner.os, 'Linux') | |
with: | |
path: ~/.cache/pypoetry | |
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: ${{ runner.os }}-poetry- | |
- name: Install Poetry | |
run: | | |
curl -sSL https://install.python-poetry.org | POETRY_HOME="$HOME/.poetry" python - --yes | |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH | |
- name: Test Poetry installation | |
run: poetry --version | |
- name: Install dependencies | |
run: | | |
poetry install --no-interaction --with dev --all-extras | |
poetry show --tree | |
- name: Run Pact Provider contract tests for all Providers (user run) | |
run: pytest -m "provider and pactflow" | |
if: ${{ env.PACT_PROVIDER == 'all' }} | |
- name: ${{ github.event.client_payload.message || 'Run Pact Provider contract test (user run)' }} | |
run: pytest -m "provider and pactflow and ${{ env.PACT_PROVIDER }}" | |
if: ${{ env.PACT_PROVIDER != 'all' }} |