99 required : true
1010 HMCTS_ADO_PAT :
1111 required : true
12+ PACT_BROKER_TOKEN :
13+ required : true
1214 inputs :
1315 is_release :
1416 required : false
2325 trigger_deploy :
2426 required : true
2527 type : boolean
28+ pacticipant :
29+ required : true
30+ type : string
31+ pact_env :
32+ required : true
33+ type : string
2634
2735jobs :
2836 Artefact-Version :
4957 outputs :
5058 repo_name : ${{ steps.repo_vars.outputs.repo_name }}
5159 artefact_name : ${{ steps.repo_vars.outputs.artefact_name }}
60+ env :
61+ PACT_BROKER_BASE_URL : " https://hmcts-dts.pactflow.io"
62+ PACT_ENV : " dev/pactTest"
63+
5264 steps :
5365 - name : Checkout source code
5466 uses : actions/checkout@v4
@@ -64,36 +76,12 @@ jobs:
6476 with :
6577 gradle-version : current
6678
67- - name : Gradle Build and Publish
79+ - name : Gradle Build
6880 env :
6981 ARTEFACT_VERSION : ${{ needs.Artefact-Version.outputs.artefact_version }}
70- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
71- AZURE_DEVOPS_ARTIFACT_USERNAME : ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
72- AZURE_DEVOPS_ARTIFACT_TOKEN : ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
7382 run : |
7483 echo "Building with ARTEFACT_VERSION=$ARTEFACT_VERSION"
75-
76- gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION
77-
78- if [ -z "AZURE_DEVOPS_ARTIFACT_USERNAME" ]; then
79- echo "::warning::AZURE_DEVOPS_ARTIFACT_USERNAME is null or not set"
80- fi
81-
82- if [ -z "$AZURE_DEVOPS_ARTIFACT_TOKEN" ]; then
83- echo "::warning::AZURE_DEVOPS_ARTIFACT_TOKEN is null or not set"
84- fi
85-
86- if [ "${{ inputs.is_publish }}" == "true" ]; then
87- echo "Publishing artefact for version: $ARTEFACT_VERSION"
88-
89- gradle publish \
90- -DARTEFACT_VERSION=$ARTEFACT_VERSION \
91- -DGITHUB_REPOSITORY=${{ github.repository }} \
92- -DGITHUB_ACTOR=${{ github.actor }} \
93- -DGITHUB_TOKEN=$GITHUB_TOKEN \
94- -DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \
95- -DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN
96- fi
84+ gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION
9785
9886 - name : Extract repo name
9987 id : repo_vars
@@ -108,8 +96,87 @@ jobs:
10896 name : app.jar
10997 path : build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar
11098
99+ Provider-Deploy :
100+ needs : [ Artefact-Version, Build ]
101+ runs-on : ubuntu-latest
102+ env :
103+ PACT_PROVIDER_VERSION : ${{ needs.Artefact-Version.outputs.artefact_version }}
104+ PACT_BROKER_URL : " https://hmcts-dts.pactflow.io"
105+ PACT_BROKER_TOKEN : ${{ secrets.PACT_BROKER_TOKEN }}
106+ PACT_ENV : ${{ inputs.pact_env }}
107+ PACTICIPANT : ${{ inputs.pacticipant }}
108+ steps :
109+ - name : Checkout source code
110+ uses : actions/checkout@v4
111+
112+ - name : Set up JDK
113+ uses : actions/setup-java@v4
114+ with :
115+ distribution : ' temurin'
116+ java-version : ' 21'
117+
118+ - name : Set up Gradle
119+ uses : gradle/actions/setup-gradle@v4
120+ with :
121+ gradle-version : current
122+
123+ # If the results are not published, the Pact Broker will not be able to find the version
124+ # NOTE: if the version is not found and verification step is successful, check that 'pact.verifier.publishResults' is set to true in the gradle task
125+ - name : Pact Provider Verification and Publish Results
126+ env :
127+ PACT_PROVIDER_BRANCH : ${{ github.ref_name }}
128+ PACT_VERIFIER_PUBLISH_RESULTS : true
129+ run : |
130+ echo "PACT_PROVIDER_VERSION=$PACT_PROVIDER_VERSION"
131+ echo "PACT_VERIFIER_PUBLISH_RESULTS=$PACT_VERIFIER_PUBLISH_RESULTS"
132+ echo "PACT_PROVIDER_BRANCH=$PACT_PROVIDER_BRANCH"
133+ echo "PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN"
134+ echo "PACT_BROKER_URL=$PACT_BROKER_URL"
135+ echo "PACT_ENV=$PACT_ENV"
136+
137+ gradle pactVerificationTest \
138+ -Dpact.provider.version="$PACT_PROVIDER_VERSION" \
139+ -Dpact.verifier.publishResults="$PACT_VERIFIER_PUBLISH_RESULTS" \
140+ -Dpact.provider.branch="$PACT_PROVIDER_BRANCH" \
141+ -Dpact.broker.token="$PACT_BROKER_TOKEN" \
142+ -Dpact.broker.url="$PACT_BROKER_URL" \
143+ -Dpact.env="$PACT_ENV"
144+
145+ - uses : hmcts/pact-can-i-deploy@main
146+ with :
147+ pact_broker_token : ${{ secrets.PACT_BROKER_TOKEN }}
148+ pacticipant : ${{ inputs.pacticipant }}
149+ pacticipant_version : ${{ env.PACT_PROVIDER_VERSION }}
150+ pact_env : ${{ env.PACT_ENV }}
151+
152+ - name : Gradle Publish
153+ if : ${{ inputs.is_publish }}
154+ env :
155+ ARTEFACT_VERSION : ${{ needs.Artefact-Version.outputs.artefact_version }}
156+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
157+ AZURE_DEVOPS_ARTIFACT_USERNAME : ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
158+ AZURE_DEVOPS_ARTIFACT_TOKEN : ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
159+ run : |
160+ if [ -z "AZURE_DEVOPS_ARTIFACT_USERNAME" ]; then
161+ echo "::warning::AZURE_DEVOPS_ARTIFACT_USERNAME is null or not set"
162+ fi
163+
164+ if [ -z "$AZURE_DEVOPS_ARTIFACT_TOKEN" ]; then
165+ echo "::warning::AZURE_DEVOPS_ARTIFACT_TOKEN is null or not set"
166+ fi
167+
168+ echo "Publishing artefact for version: $ARTEFACT_VERSION"
169+
170+ gradle publish \
171+ -DARTEFACT_VERSION=$ARTEFACT_VERSION \
172+ -DGITHUB_REPOSITORY=${{ github.repository }} \
173+ -DGITHUB_ACTOR=${{ github.actor }} \
174+ -DGITHUB_TOKEN=$GITHUB_TOKEN \
175+ -DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \
176+ -DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN
177+
111178 Build-Docker :
112- needs : [ Build, Artefact-Version ]
179+ needs : [ Provider-Deploy, Build, Artefact-Version ]
113180 if : ${{ inputs.trigger_docker }}
114181 runs-on : ubuntu-latest
115182 steps :
@@ -145,7 +212,7 @@ jobs:
145212 JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar
146213
147214 Deploy :
148- needs : [ Build, Artefact-Version ]
215+ needs : [ Provider-Deploy, Build, Artefact-Version ]
149216 if : ${{ inputs.trigger_deploy }}
150217 runs-on : ubuntu-latest
151218 steps :
@@ -163,4 +230,4 @@ jobs:
163230 "ARTIFACT_ID": "${{ env.REPO_NAME }}",
164231 "ARTIFACT_VERSION": "${{ needs.Artefact-Version.outputs.artefact_version }}",
165232 "TARGET_REPOSITORY": "${{ github.repository }}"
166- }
233+ }
0 commit comments