-
Notifications
You must be signed in to change notification settings - Fork 5
359 lines (311 loc) · 11.1 KB
/
build_workflow.yml
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
name: GP2GP Build Workflow
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
push:
branches:
- main
jobs:
checkstyle:
name: Checkstyle
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Checkstyle
run: |
./gradlew checkStyleMain --parallel
./gradlew checkstyleTest --parallel
working-directory: ./service
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Checkstyle Reports'
path: ./artifacts/**
compression-level: 9
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
spotbugs:
name: Spotbugs
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Spotbugs
run: |
./gradlew spotbugsMain --parallel
./gradlew spotbugsTest --parallel
working-directory: ./service
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Spotbugs Reports'
path: ./artifacts/**
compression-level: 9
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
needs: [checkstyle, spotbugs]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# Disabling shallow clone is recommended for improving relevancy of Sonar reporting
fetch-depth: 0
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Execute Unit Tests
run: |
if [[ $GITHUB_ACTOR == 'dependabot[bot]' ]]; then
./gradlew test jacocoTestReport --parallel --build-cache
else
./gradlew test jacocoTestReport sonar --parallel --build-cache
fi
working-directory: ./service
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Unit Test Reports'
path: ./artifacts/**
compression-level: 9
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: [checkstyle, spotbugs]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Start Docker Dependencies
env:
GPC_SUPPLIER_ODS_CODE: "XYZ222"
GP2GP_SERVER_PORT: "8080"
GP2GP_AMQP_BROKERS: "amqp://activemq:5672"
GP2GP_MONGO_URI: "mongodb://mongodb:27017"
GP2GP_MONGO_DATABASE_NAME: "gp2gp"
GP2GP_MHS_OUTBOUND_URL: "http://mock-mhs-adaptor:8081/mock-mhs-endpoint/accept-only"
GP2GP_GPC_GET_URL: "http://gpcc:8090/@ODS_CODE@/STU3/1/gpconnect"
GP2GP_LARGE_ATTACHMENT_THRESHOLD: "4500000"
GP2GP_LARGE_EHR_EXTRACT_THRESHOLD: "4500000"
GPC_CONSUMER_SERVER_PORT: "8090"
GPC_CONSUMER_SDS_URL: "http://wiremock:8080/spine-directory/"
GPC_CONSUMER_SDS_APIKEY: "anykey"
GP2GP_LOGGING_LEVEL: DEBUG
GPC_CONSUMER_LOGGING_LEVEL: DEBUG
run: |
docker network create commonforgp2gp
docker compose build
docker compose up mock-mhs-adaptor mongodb activemq wiremock gpcc gp2gp --detach
working-directory: ./docker
- name: Execute Integration Tests
run: ./gradlew integrationTest
working-directory: ./service
- name: Dump Docker Logs
if: always()
run: |
chmod +x dump_docker_logs.sh
./dump_docker_logs.sh
working-directory: ./scripts
shell: bash
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
cp -r ./scripts/logs ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Integration Test Reports & Docker Logs'
path: ./artifacts/**
compression-level: 9
- name: Stop Docker Dependencies
if: always()
run: |
docker compose down --rmi=local --remove-orphans
docker compose rm
docker network rm commonforgp2gp
working-directory: ./docker
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
end-to-end-tests:
name: End-to-End Testing
runs-on: ubuntu-latest
needs: [checkstyle, spotbugs]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Run E2E Tests
env:
GP2GP_SERVER_PORT: "8080"
GP2GP_BASE_URL: "http://gp2gp:8080"
GP2GP_AMQP_BROKERS: "amqp://activemq:5672"
GP2GP_MONGO_URI: "mongodb://mongodb:27017"
GP2GP_MONGO_DATABASE_NAME: "gp2gp"
GP2GP_MHS_MOCK_BASE_URL: "http://mock-mhs-adaptor:8081"
GP2GP_MHS_OUTBOUND_URL: "http://mock-mhs-adaptor:8081/mock-mhs-endpoint"
GP2GP_GPC_GET_URL: "http://gpcc:8090/@ODS_CODE@/STU3/1/gpconnect"
GP2GP_LARGE_ATTACHMENT_THRESHOLD: "31216"
GP2GP_LARGE_EHR_EXTRACT_THRESHOLD: "31216"
GP2GP_GPC_CLIENT_MAX_BACKOFF_ATTEMPTS: 0
GP2GP_MHS_CLIENT_MAX_BACKOFF_ATTEMPTS: 0
GPC_CONSUMER_SERVER_PORT: "8090"
GPC_CONSUMER_SDS_URL: "http://wiremock:8080/spine-directory/"
GPC_CONSUMER_SDS_APIKEY: "anykey"
GPC_CONSUMER_LOGGING_LEVEL: "DEBUG"
GPC_SUPPLIER_ODS_CODE: "XYZ222"
GP2GP_LOGGING_LEVEL: "DEBUG"
MHS_MOCK_REQUEST_JOURNAL_ENABLED: "true"
run: |
docker network create commonforgp2gp
docker compose -f docker-compose.yml -f docker-compose-e2e-tests.yml up --build --exit-code-from gp2gp-e2e-tests mongodb activemq gp2gp wiremock gpcc gp2gp-e2e-tests
working-directory: ./docker
- name: Dump Docker Logs
if: always()
run: |
chmod +x dump_docker_logs.sh
./dump_docker_logs.sh
working-directory: ./scripts
shell: bash
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
docker cp e2e-tests:/home/gradle/e2e-tests/build/reports ./artifacts
cp -r ./scripts/logs ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'End-to-End Test Results & Docker Logs'
path: ./artifacts/**
compression-level: 9
- name: Stop Docker Dependencies
if: always()
run: |
docker compose -f docker-compose.yml -f docker-compose-e2e-tests.yml down
docker network rm commonforgp2gp
working-directory: ./docker
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
build-and-publish-docker-images:
name: Build & Publish Docker Images
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, end-to-end-tests]
permissions:
id-token: write
contents: read
strategy:
matrix:
config:
- directory: service
repository: gp2gp
build-context: .
- directory: wiremock
repository: gp2gp-wiremock
build-context: .
- directory: mock-mhs-adaptor
repository: gp2gp-mock-mhs
build-context: .
- directory: gpcc-mock
repository: gp2gp-gpcc-mock
build-context: ./docker/gpcc-mock
- directory: gpc-api-mock
repository: gp2gp-gpc-api-mock
build-context: ./docker/gpc-api-mock
- directory: sds-api-mock
repository: gp2gp-sds-api-mock
build-context: ./docker/sds-api-mock
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: gp2gp_github_action_build_workflow
aws-region: ${{ secrets.AWS_REGION }}
- name: Generate Build ID
run: |
chmod +x ./create_build_id.sh
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
GIT_BRANCH=PR
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
GIT_BRANCH=main
fi
BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }})
echo "Generated the build tag: $BUILD_ID"
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV
working-directory: ./scripts
shell: bash
- name: Build Docker Image
run: |
# Create Docker Tag
DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
DOCKER_TAG="$DOCKER_REGISTRY/${{ matrix.config.repository }}:$BUILD_ID"
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
# Build Image
docker build -f ./docker/${{ matrix.config.directory }}/Dockerfile -t $DOCKER_TAG ${{ matrix.config.build-context }}
- name: Login to AWS ECR
run: |
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $DOCKER_REGISTRY
- name: Publish image to ECR
run: docker push $DOCKER_TAG
- name: Logout of AWS ECR (Clean up Credentials)
if: always()
run: |
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
docker logout $DOCKER_REGISTRY