-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (81 loc) · 2.98 KB
/
consumer_contract_tests.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Consumer contract tests
# The purpose of this workflow is to validate the service level contract using the Pact framework.
on:
pull_request:
branches:
- develop
paths-ignore:
- 'README.md'
push:
branches:
- develop
paths-ignore:
- 'README.md'
merge_group:
branches:
- develop
paths-ignore:
- 'README.md'
jobs:
consent-contract-tests:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
outputs:
sha-short: ${{ steps.extract-branch.outputs.sha-short }}
pact-b64: ${{ steps.encode-pact.outputs.pact-b64 }}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Extract branch
id: extract-branch
run: |
GITHUB_EVENT_NAME=${{ github.event_name }}
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
GITHUB_REF=${{ github.ref }}
GITHUB_SHA=${{ github.sha }}
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
GITHUB_REF=refs/heads/${{ github.head_ref }}
GITHUB_SHA=${{ github.event.pull_request.head.sha }}
else
echo "Failed to extract branch information"
exit 1
fi
echo "ref=$GITHUB_REF" >> $GITHUB_OUTPUT
echo "sha=$GITHUB_SHA" >> $GITHUB_OUTPUT
echo "sha-short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF/refs\/heads\//""}" >> $GITHUB_OUTPUT
- name: Echo branch information
run: |
echo ${{ steps.extract-branch.outputs.ref }}
echo ${{ steps.extract-branch.outputs.sha }}
echo ${{ steps.extract-branch.outputs.sha-short }}
echo ${{ steps.extract-branch.outputs.branch }}
- name: Run consumer tests
run: mvn clean test -Ppact-tests
- name: Output consumer contract as non-breaking base64 string
id: encode-pact
run: |
NON_BREAKING_B64=$(cat target/pacts/consent-sam.json | base64 -w 0)
echo "pact-b64=${NON_BREAKING_B64}" >> $GITHUB_OUTPUT
publish-pact:
runs-on: ubuntu-latest
needs: [consent-contract-tests]
permissions:
contents: 'read'
id-token: 'write'
if: github.actor != 'dependabot[bot]'
steps:
- name: Dispatch to terra-github-workflows
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 #commit sha for v2.1.1
with:
workflow: publish-pacts.yaml
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ secrets.BROADBOT_TOKEN }} # github token for access to kick off a job in the private repo
inputs: '{ "consumer-name": "consent", "consumer-version": "${{ needs.consent-contract-tests.outputs.sha-short }}", "provider-name": "sam", "pact-b64": "${{ needs.consent-contract-tests.outputs.pact-b64 }}" }'