Skip to content

Pact-Consumer

Pact-Consumer #7

Workflow file for this run

name: Pact-Consumer
on:
workflow_dispatch:
env:
PACT_FLOW_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_FLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }}
GIT_COMMIT: ${{ github.sha }}
GIT_REF: ${{ github.ref }}
GIT_BRANCH: ${{ github.ref_name }}
CONSUMER: "bookClient"
jobs:
run_contract_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Run tests
run: ./gradlew runConsumerTest
- name: Publish Pact to Pactflow if tests pass
run: |
GIT_BRANCH=${GITHUB_REF#refs/heads/}
docker run --rm \
-e PACT_BROKER_BASE_URL=$PACT_FLOW_BASE_URL \
-e PACT_BROKER_TOKEN=$PACT_FLOW_TOKEN \
-e GIT_COMMIT=$GIT_COMMIT \
-e GIT_BRANCH=$GIT_BRANCH \
-e PACT_DO_NOT_TRACK=true \
-v ${PWD}/build/pacts:/pacts \
pactfoundation/pact-cli:latest \
publish /pacts \
--consumer-app-version $GIT_COMMIT \
--branch $GIT_BRANCH \
--tag $GIT_BRANCH
- name: can-I-deploy
run: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$PACT_FLOW_BASE_URL \
-e PACT_BROKER_TOKEN=$PACT_FLOW_TOKEN \
pactfoundation/pact-cli:latest \
pact-broker can-i-deploy --pacticipant $CONSUMER --latest
- name: Deploy to Test
run: echo "Deploy to TEST Environment"
- name: Record Deployment for TEST
run: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$PACT_FLOW_BASE_URL \
-e PACT_BROKER_TOKEN=$PACT_FLOW_TOKEN \
pactfoundation/pact-cli:latest \
pact-broker record-deployment --broker-base-url=$PACT_FLOW_BASE_URL --broker-token=$PACT_FLOW_TOKEN --pacticipant $CONSUMER --version $GIT_COMMIT --environment 'test'