generated from hmcts/service-hmcts-crime-springboot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
256 lines (229 loc) · 8.41 KB
/
ci-build-publish.yml
File metadata and controls
256 lines (229 loc) · 8.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
name: CI Build and Publish
on:
workflow_call:
secrets:
AZURE_DEVOPS_ARTIFACT_USERNAME:
required: true
AZURE_DEVOPS_ARTIFACT_TOKEN:
required: true
HMCTS_CP_ADO_PAT:
required: true
PACT_BROKER_TOKEN:
required: true
inputs:
environment:
required: true
type: string
default: dev
is_release:
required: false
type: boolean
default: false
is_publish:
required: true
type: boolean
trigger_docker:
required: true
type: boolean
trigger_deploy:
required: true
type: boolean
pacticipant:
required: true
type: string
pact_env:
required: true
type: string
jobs:
Artefact-Version:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
outputs:
artefact_version: ${{ inputs.is_release && steps.artefact.outputs.release_version || steps.artefact.outputs.draft_version }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Generate Artefact Version
id: artefact
uses: hmcts/artefact-version-action@v1
with:
release: ${{ inputs.is_release }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Build:
needs: [Artefact-Version]
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
outputs:
repo_name: ${{ steps.repo_vars.outputs.repo_name }}
artefact_name: ${{ steps.repo_vars.outputs.artefact_name }}
env:
PACT_BROKER_BASE_URL: "https://hmcts-dts.pactflow.io"
PACT_ENV: "dev/pactTest"
steps:
- name: Checkout source code
uses: actions/checkout@v5
- name: Set up JDK
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: current
- name: Gradle Build
env:
ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
run: |
echo "Building with ARTEFACT_VERSION=$ARTEFACT_VERSION"
gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION
- name: Extract repo name
id: repo_vars
run: |
repo_name=${GITHUB_REPOSITORY##*/}
echo "repo_name=${repo_name}" >> $GITHUB_OUTPUT
echo "artefact_name=${repo_name}-${{ needs.Artefact-Version.outputs.artefact_version }}" >> $GITHUB_OUTPUT
- name: Upload JAR Artefact
uses: actions/upload-artifact@v4
with:
name: app.jar
path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar
Provider-Deploy:
needs: [ Artefact-Version, Build ]
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
env:
PACT_PROVIDER_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
PACT_BROKER_URL: "https://hmcts-dts.pactflow.io"
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
PACT_ENV: ${{ inputs.pact_env }}
PACTICIPANT: ${{ inputs.pacticipant }}
steps:
- name: Checkout source code
uses: actions/checkout@v5
- name: Set up JDK
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: current
# If the results are not published, the Pact Broker will not be able to find the version
# 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
- name: Pact Provider Verification and Publish Results
env:
PACT_PROVIDER_BRANCH: ${{ github.ref_name }}
PACT_VERIFIER_PUBLISH_RESULTS: true
run: |
echo "PACT_PROVIDER_VERSION=$PACT_PROVIDER_VERSION"
echo "PACT_VERIFIER_PUBLISH_RESULTS=$PACT_VERIFIER_PUBLISH_RESULTS"
echo "PACT_PROVIDER_BRANCH=$PACT_PROVIDER_BRANCH"
echo "PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN"
echo "PACT_BROKER_URL=$PACT_BROKER_URL"
echo "PACT_ENV=$PACT_ENV"
gradle pactVerificationTest \
-Dpact.provider.version="$PACT_PROVIDER_VERSION" \
-Dpact.verifier.publishResults="$PACT_VERIFIER_PUBLISH_RESULTS" \
-Dpact.provider.branch="$PACT_PROVIDER_BRANCH" \
-Dpact.broker.token="$PACT_BROKER_TOKEN" \
-Dpact.broker.url="$PACT_BROKER_URL" \
-Dpact.env="$PACT_ENV"
- uses: hmcts/pact-can-i-deploy@main
with:
pact_broker_token: ${{ secrets.PACT_BROKER_TOKEN }}
pacticipant: ${{ inputs.pacticipant }}
pacticipant_version: ${{ env.PACT_PROVIDER_VERSION }}
pact_env: ${{ env.PACT_ENV }}
- name: Gradle Publish
if: ${{ inputs.is_publish }}
env:
ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
AMP_BACKEND_URL: ${{ secrets.AMP_BACKEND_URL }}
CP_BACKEND_URL: ${{ secrets.CP_BACKEND_URL }}
CJSCPPUID: ${{ secrets.CJSCPPUID }}
ENVIRONMENT: ${{ inputs.environment }}
run: |
echo "Active environment=$ENVIRONMENT"
if [ -z "AZURE_DEVOPS_ARTIFACT_USERNAME" ]; then
echo "::warning::AZURE_DEVOPS_ARTIFACT_USERNAME is null or not set"
fi
if [ -z "$AZURE_DEVOPS_ARTIFACT_TOKEN" ]; then
echo "::warning::AZURE_DEVOPS_ARTIFACT_TOKEN is null or not set"
fi
echo "Publishing artefact for version: $ARTEFACT_VERSION"
gradle publish \
-DARTEFACT_VERSION=$ARTEFACT_VERSION \
-DGITHUB_REPOSITORY=${{ github.repository }} \
-DGITHUB_ACTOR=${{ github.actor }} \
-DGITHUB_TOKEN=$GITHUB_TOKEN \
-DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN \
-DAMP_BACKEND_URL=$AMP_BACKEND_URL \
-DCP_BACKEND_URL=$CP_BACKEND_URL \
-DCJSCPPUID=$CJSCPPUID
Build-Docker:
needs: [ Provider-Deploy, Build, Artefact-Version ]
if: ${{ inputs.trigger_docker }}
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout Code
uses: actions/checkout@v5
- name: Download JAR Artefact
uses: actions/download-artifact@v6
with:
name: app.jar
path: build/libs
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image to GitHub
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ needs.Artefact-Version.outputs.artefact_version }}
build-args: |
BASE_IMAGE=openjdk:21-jdk-slim
JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar
AMP_BACKEND_URL=${{ secrets.AMP_BACKEND_URL }}
CP_BACKEND_URL=${{ secrets.CP_BACKEND_URL }}
CJSCPPUID=${{ secrets.CJSCPPUID }}
Deploy:
needs: [ Provider-Deploy, Build, Artefact-Version ]
if: ${{ inputs.trigger_deploy }}
runs-on: ubuntu-latest
steps:
- name: Extract repo name
run: echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
- name: Trigger ADO pipeline
uses: hmcts/trigger-ado-pipeline@v1
with:
pipeline_id: 460
ado_pat: ${{ secrets.HMCTS_CP_ADO_PAT }}
template_parameters: >
{
"GROUP_ID": "uk.gov.hmcts.cp",
"ARTIFACT_ID": "${{ env.REPO_NAME }}",
"ARTIFACT_VERSION": "${{ needs.Artefact-Version.outputs.artefact_version }}",
"TARGET_REPOSITORY": "${{ github.repository }}"
}