9
9
- main
10
10
paths-ignore : [ '**.md' ]
11
11
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
+
12
17
jobs :
13
18
init-github-context :
14
19
runs-on : ubuntu-latest
49
54
runs-on : ubuntu-latest
50
55
needs : [ init-github-context ]
51
56
outputs :
52
- pact-b64 : ${{ steps.encode-pact .outputs.pact-b64 }}
57
+ pact-paths : ${{ steps.locate-pacts .outputs.pact-paths }}
53
58
54
59
steps :
55
60
- name : Checkout current code
@@ -62,24 +67,68 @@ jobs:
62
67
distribution : ' temurin'
63
68
- name : Run consumer tests
64
69
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
67
73
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="["
70
79
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 :
72
99
runs-on : ubuntu-latest
73
100
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
+
77
105
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
+
78
120
- name : Dispatch to terra-github-workflows
79
- uses : broadinstitute/workflow-dispatch@v3
121
+ uses : broadinstitute/workflow-dispatch@v4.0.0
80
122
with :
123
+ run-name : ' ${{ env.PUBLISH_CONTRACT_RUN_NAME }}-${{ matrix.pact_path }}'
81
124
workflow : .github/workflows/publish-contracts.yaml
82
125
repo : broadinstitute/terra-github-workflows
83
126
ref : refs/heads/main
84
127
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