-
Notifications
You must be signed in to change notification settings - Fork 2
97 lines (92 loc) · 3.38 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
88
89
90
91
92
93
94
95
96
97
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@v4
with:
persist-credentials: false
- uses: actions/setup-java@v4
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_DEFAULT_REF}"
GITHUB_SHA="${GITHUB_DEFAULT_SHA}"
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
GITHUB_REF="refs/heads/${GITHUB_HEAD_REF}"
GITHUB_SHA="${GITHUB_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
env:
GITHUB_DEFAULT_SHA: ${{ github.sha }}
GITHUB_DEFAULT_REF: ${{ github.ref }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
- name: Echo branch information
run: |
echo "${BRANCH_REF}"
echo "${BRANCH_SHA}"
echo "${BRANCH_SHA_SHORT}"
echo "${BRANCH_NAME}"
env:
BRANCH_REF: ${{ steps.extract-branch.outputs.ref }}
BRANCH_SHA: ${{ steps.extract-branch.outputs.sha }}
BRANCH_SHA_SHORT: ${{ steps.extract-branch.outputs.sha-short }}
BRANCH_NAME: ${{ 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'
steps:
- name: Dispatch to terra-github-workflows
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 #commit sha for v4.0.0
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 }}" }'