Skip to content

Commit 3cef8c3

Browse files
authored
AJ-1234: Make WDS publish multiple pacts. (#399)
Make `publish_pacts` work with multiple pacts. This is based on #397 Co-authored-by: ichengchang Co-authored-by: calypsomatic
1 parent f5bc887 commit 3cef8c3

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

.github/workflows/publish-pacts.yml

+60-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
- main
1010
paths-ignore: [ '**.md' ]
1111

12+
env:
13+
WDS_PACTS_ARTIFACT: wds-pacts-${{ github.event.repository.name }}-${{ github.run_id }}
14+
WDS_PACTS_OUTPUT_DIR: service/build/pacts/
15+
PUBLISH_CONTRACT_RUN_NAME: 'publish-contracts-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
16+
1217
jobs:
1318
init-github-context:
1419
runs-on: ubuntu-latest
@@ -49,7 +54,7 @@ jobs:
4954
runs-on: ubuntu-latest
5055
needs: [ init-github-context ]
5156
outputs:
52-
pact-b64: ${{ steps.encode-pact.outputs.pact-b64 }}
57+
pact-paths: ${{ steps.locate-pacts.outputs.pact-paths }}
5358

5459
steps:
5560
- name: Checkout current code
@@ -62,24 +67,68 @@ jobs:
6267
distribution: 'temurin'
6368
- name: Run consumer tests
6469
run: ./gradlew pactTests
65-
- name: Output consumer contract as non-breaking base64 string
66-
id: encode-pact
70+
71+
- name: Locate all pact json files and output Base64-encoded pacts
72+
id: locate-pacts
6773
run: |
68-
NON_BREAKING_B64=$(cat service/build/pacts/wds-sam.json | base64 -w 0)
69-
echo "pact-b64=${NON_BREAKING_B64}" >> $GITHUB_OUTPUT
74+
# Locate .json pact files in $pactOutputDir
75+
pactPaths=($(find "${{ env.WDS_PACTS_OUTPUT_DIR }}" -type f -name "*.json"))
76+
77+
# Put the Base64-encoded pacts in JSON string
78+
pactPathsJson="["
7079
71-
publish-pact-job:
80+
# Loop through $pactPaths and encode the corresponding pact
81+
for path in "${pactPaths[@]}"; do
82+
pactPathsJson="${pactPathsJson}\"$path\", "
83+
done
84+
85+
pactPathsJson="${pactPathsJson%, }]"
86+
87+
echo "pact-paths=$pactPathsJson" >> $GITHUB_OUTPUT
88+
89+
- name: Upload pact files to artifact
90+
id: upload-pacts
91+
uses: actions/upload-artifact@v3
92+
with:
93+
name: ${{ env.WDS_PACTS_ARTIFACT }}
94+
path: |
95+
${{ env.WDS_PACTS_OUTPUT_DIR }}
96+
retention-days: 1
97+
98+
publish-pacts-job:
7299
runs-on: ubuntu-latest
73100
needs: [ init-github-context, run-consumer-contract-tests ]
74-
permissions:
75-
contents: 'read'
76-
id-token: 'write'
101+
strategy:
102+
matrix:
103+
pact_path: ${{ fromJson(needs.run-consumer-contract-tests.outputs.pact-paths) }}
104+
77105
steps:
106+
- name: Download pact files from artifact
107+
id: download-pacts
108+
uses: actions/download-artifact@v3
109+
with:
110+
name: ${{ env.WDS_PACTS_ARTIFACT }}
111+
path: |
112+
${{ env.WDS_PACTS_OUTPUT_DIR }}
113+
114+
- name: Encode pact as non-breaking base64 string
115+
id: encode-pact
116+
run: |
117+
nonBreakingB64=$(cat "${{ matrix.pact_path }}" | base64 -w 0)
118+
echo "pact-b64=${nonBreakingB64}" >> $GITHUB_OUTPUT
119+
78120
- name: Dispatch to terra-github-workflows
79-
uses: broadinstitute/workflow-dispatch@v3
121+
uses: broadinstitute/workflow-dispatch@v4.0.0
80122
with:
123+
run-name: '${{ env.PUBLISH_CONTRACT_RUN_NAME }}-${{ matrix.pact_path }}'
81124
workflow: .github/workflows/publish-contracts.yaml
82125
repo: broadinstitute/terra-github-workflows
83126
ref: refs/heads/main
84127
token: ${{ secrets.BROADBOT_TOKEN }} # github token for access to kick off a job in the private repo
85-
inputs: '{ "pact-b64": "${{ needs.run-consumer-contract-tests.outputs.pact-b64 }}", "repo-owner": "${{ github.repository_owner }}", "repo-name": "${{ github.event.repository.name }}", "repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}" }'
128+
inputs: '{
129+
"run-name": "${{ env.PUBLISH_CONTRACT_RUN_NAME }}-${{ matrix.pact_path }}",
130+
"pact-b64": "${{ steps.encode-pact.outputs.pact-b64 }}",
131+
"repo-owner": "${{ github.repository_owner }}",
132+
"repo-name": "${{ github.event.repository.name }}",
133+
"repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}"
134+
}'

0 commit comments

Comments
 (0)