AJ-1188 Add wds consumer tests against datarepo provider #840
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish contract tests | |
on: | |
pull_request: | |
branches: | |
- main | |
paths-ignore: [ '**.md' ] | |
push: | |
branches: | |
- main | |
paths-ignore: [ '**.md' ] | |
env: | |
WDS_RUN_ID: ${{ github.event.repository.name }}-${{ github.run_id }} | |
PUBLISH_CONTRACT_RUN_NAME: 'publish-contracts-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}' | |
WDS_PACTS_ARTIFACT: wds-pacts-${{ github.event.repository.name }}-${{ github.run_id }} | |
WDS_PACTS_OUTPUT_DIR: service/build/pacts/ | |
jobs: | |
init-github-context: | |
runs-on: ubuntu-latest | |
outputs: | |
sha-short: ${{ steps.extract-branch.outputs.sha-short }} | |
repo-branch: ${{ steps.extract-branch.outputs.repo-branch }} | |
repo-version: ${{ steps.extract-branch.outputs.repo-version }} | |
steps: | |
- uses: actions/checkout@v3 | |
- 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 }} | |
elif [[ "$GITHUB_EVENT_NAME" == "merge_group" ]]; then | |
GITHUB_REF=refs/heads/${{ github.head_ref }} | |
else | |
echo "Failed to extract branch information" | |
exit 1 | |
fi | |
echo "repo-branch=${GITHUB_REF/refs\/heads\//""}" >> $GITHUB_OUTPUT | |
echo "repo-version=${GITHUB_SHA}" >> $GITHUB_OUTPUT | |
- name: Echo repo and branch information | |
run: | | |
echo "repo-owner=${{ github.repository_owner }}" | |
echo "repo-name=${{ github.event.repository.name }}" | |
echo "repo-branch=${{ steps.extract-branch.outputs.repo-branch }}" | |
echo "repo-version=${{ steps.extract-branch.outputs.repo-version }}" | |
run-consumer-contract-tests: | |
runs-on: ubuntu-latest | |
needs: [ init-github-context ] | |
outputs: | |
pact-paths: ${{ steps.locate-pacts.outputs.pact-paths }} | |
steps: | |
- name: Checkout current code | |
uses: actions/checkout@v4 | |
- name: Set up JDK | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Run consumer tests | |
run: ./gradlew pactTests | |
- name: Locate all pact json files and output Base64-encoded pacts | |
id: locate-pacts | |
run: | | |
# Locate .json pact files in $pactOutputDir | |
pactPaths=($(find "${{ env.WDS_PACTS_OUTPUT_DIR }}" -type f -name "*.json")) | |
# Put the Base64-encoded pacts in JSON string | |
pactPathsJson="[" | |
# Loop through $pactPaths and encode the corresponding pact | |
for path in "${pactPaths[@]}"; do | |
pactPathsJson="${pactPathsJson}\"$path\", " | |
done | |
pactPathsJson="${pactPathsJson%, }]" | |
echo "pact-paths=$pactPathsJson" >> $GITHUB_OUTPUT | |
- name: Upload pact files to artifact | |
id: upload-pacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.WDS_PACTS_ARTIFACT }} | |
path: | | |
${{ env.WDS_PACTS_OUTPUT_DIR }} | |
retention-days: 1 | |
publish-pacts-job: | |
runs-on: ubuntu-latest | |
needs: [ init-github-context, run-consumer-contract-tests ] | |
strategy: | |
matrix: | |
pact_path: ${{ fromJson(needs.run-consumer-contract-tests.outputs.pact-paths) }} | |
steps: | |
- name: Download pact files from artifact | |
id: download-pacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.WDS_PACTS_ARTIFACT }} | |
path: | | |
${{ env.WDS_PACTS_OUTPUT_DIR }} | |
- name: Encode pact as non-breaking base64 string | |
id: encode-pact | |
run: | | |
nonBreakingB64=$(cat "${{ matrix.pact_path }}" | base64 -w 0) | |
echo "pact-b64=${nonBreakingB64}" >> $GITHUB_OUTPUT | |
- name: Dispatch to terra-github-workflows | |
uses: broadinstitute/[email protected] | |
with: | |
run-name: '${{ env.PUBLISH_CONTRACT_RUN_NAME }}-${{ matrix.pact_path }}' | |
workflow: .github/workflows/publish-contracts.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: '{ | |
"run-name": "${{ env.PUBLISH_CONTRACT_RUN_NAME }}-${{ matrix.pact_path }}", | |
"pact-b64": "${{ steps.encode-pact.outputs.pact-b64 }}", | |
"repo-owner": "${{ github.repository_owner }}", | |
"repo-name": "${{ github.event.repository.name }}", | |
"repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}" | |
}' |