Skip to content

Commit fbc639d

Browse files
Merge pull request #49 from hmcts/standardise-pact
apply the standardised CI pact flow
2 parents f17aa7e + 7132d48 commit fbc639d

File tree

14 files changed

+177
-271
lines changed

14 files changed

+177
-271
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
* @hmcts/platform-operations @hmcts/developer-enablement
2-
3-
# Ignore files updated by Renovate
4-
gradle/wrapper/gradle-wrapper.properties
5-
Dockerfile
6-
build.gradle
7-
charts/**/Chart.yaml
8-
.github/workflows/*.yaml
1+
* @hmcts/cp-x-cjs-data-api

.github/workflows/ci-build-publish.yml

Lines changed: 96 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
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
@@ -23,6 +25,12 @@ on:
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

2735
jobs:
2836
Artefact-Version:
@@ -49,6 +57,10 @@ jobs:
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+
}

.github/workflows/ci-draft.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ jobs:
1717
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
1818
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
1919
HMCTS_ADO_PAT: ${{ secrets.HMCTS_ADO_PAT }}
20+
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
2021
with:
2122
is_publish: ${{ github.event_name == 'push' }}
2223
trigger_docker: ${{ github.event_name == 'push' }}
2324
trigger_deploy: ${{ github.event_name == 'push' }}
24-
25+
pacticipant: CPCourtScheduleProvider
26+
pact_env: dev/pactTest

.github/workflows/ci-released.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ jobs:
1212
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
1313
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
1414
HMCTS_ADO_PAT: ${{ secrets.HMCTS_ADO_PAT }}
15+
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
1516
with:
1617
is_release: true
1718
is_publish: true
1819
trigger_docker: true
1920
trigger_deploy: true
21+
pacticipant: CPCourtScheduleProvider
22+
pact_env: dev/pactTest

.github/workflows/codeql.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
languages: ${{ matrix.language }}
3737
queries: security-extended
3838

39-
4039
- uses: actions/setup-java@v4
4140
with:
4241
distribution: 'temurin'
@@ -47,14 +46,9 @@ jobs:
4746
with:
4847
gradle-version: current
4948

50-
- name: Gradle Build and Publish
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
- name: Gradle Build
5350
run: |
54-
gradle build cyclonedxBom -x test \
55-
-DGITHUB_REPOSITORY=${{ github.repository }} \
56-
-DGITHUB_ACTOR=${{ github.actor }} \
57-
-DGITHUB_TOKEN=$GITHUB_TOKEN
51+
gradle build cyclonedxBom -x test
5852
5953
# ℹ️ Command-line programs to run using the OS shell.
6054
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

.github/workflows/publish-pact-verification.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44

55
Further documentation see the [HMCTS Marketplace Springboot template readme](https://github.com/hmcts/service-hmcts-marketplace-springboot-template/blob/main/README.md).
66

7-
### Run pact provider test and publish verification report to pact broker locally
7+
## Pact Provider Test
88

9-
update .env file with below details
10-
PACT_BROKER_URL= <<PactFlow broker url>>
11-
PACT_BROKER_HOST=<<PactFlow broker url excluding https://>>
12-
PACT_BROKER_TOKEN= <<Your PactFlow broker token>>
13-
PACT_ENV= << This is the environment in PactFlow broker to which we tag the contracts>
14-
PACT_VERIFIER_PUBLISH_RESULTS=true
15-
run ./publish-pacts.sh
9+
Run pact provider test and publish verification report to pact broker locally
10+
11+
Update .env file with below details (replacing placeholders with actual values):
12+
```bash
13+
export PACT_BROKER_URL="https://hmcts-dts.pactflow.io"
14+
export PACT_BROKER_TOKEN="YOUR_PACTFLOW_BROKER_TOKEN"
15+
export PACT_ENV="local" # or value based on the environment you are testing against
16+
export PACT_VERIFIER_PUBLISH_RESULTS=true
17+
```
18+
Run Pact tests:
19+
```bash
20+
gradle pactVerificationTest
21+
```
1622

1723
## License
1824

0 commit comments

Comments
 (0)