Skip to content

Commit b4596ae

Browse files
authored
Merge branch 'master' into dependabot/gradle/service/org.mockito-mockito-core-5.15.2
2 parents 8498ca8 + ec2cb93 commit b4596ae

File tree

5 files changed

+330
-6
lines changed

5 files changed

+330
-6
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ updates:
33
- package-ecosystem: "gradle"
44
directories:
55
- "/service"
6+
schedule:
7+
interval: "weekly"
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
610
schedule:
711
interval: "weekly"

.github/workflows/build.yml

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
2+
name: 111 Adaptor Build Workflow
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches:
7+
- master
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
checkstyle:
14+
name: Checkstyle
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Java 21 LTS
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: 21
24+
distribution: 'temurin'
25+
26+
- name: Checkstyle
27+
run: |
28+
./gradlew checkStyleMain checkstyleTest checkstyleIntegrationTest --parallel
29+
working-directory: ./service
30+
31+
- name: Collect Artifacts
32+
if: always()
33+
run: |
34+
mkdir -p artifacts
35+
cp -r ./service/build/reports ./artifacts
36+
37+
- name: Upload Artifacts
38+
uses: actions/upload-artifact@v4
39+
if: always()
40+
with:
41+
name: 'Checkstyle Reports'
42+
path: ./artifacts/**
43+
compression-level: 9
44+
45+
- name: Temporary Artifacts Cleanup
46+
run: rm -rf ./artifacts
47+
48+
spotbugs:
49+
name: Spotbugs
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout Repository
53+
uses: actions/checkout@v4
54+
55+
- name: Setup Java 21 LTS
56+
uses: actions/setup-java@v4
57+
with:
58+
java-version: 21
59+
distribution: 'temurin'
60+
61+
- name: Spotbugs
62+
run: |
63+
./gradlew spotbugsMain spotbugsTest spotbugsIntegrationTest --parallel
64+
working-directory: ./service
65+
66+
- name: Collect Artifacts
67+
if: always()
68+
run: |
69+
mkdir -p artifacts
70+
cp -r ./service/build/reports ./artifacts
71+
72+
- name: Upload Artifacts
73+
uses: actions/upload-artifact@v4
74+
if: always()
75+
with:
76+
name: 'Spotbugs Reports'
77+
path: ./artifacts/**
78+
compression-level: 9
79+
80+
- name: Temporary Artifacts Cleanup
81+
run: rm -rf ./artifacts
82+
83+
unit-tests:
84+
name: Unit Tests
85+
runs-on: ubuntu-latest
86+
needs: [ checkstyle, spotbugs ]
87+
steps:
88+
- name: Checkout Repository
89+
uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 0
92+
- name: Setup Java 21 LTS
93+
uses: actions/setup-java@v4
94+
with:
95+
java-version: 21
96+
distribution: 'temurin'
97+
98+
- name: Execute Unit Tests
99+
run: ./gradlew test jacocoTestReport --parallel --build-cache
100+
working-directory: ./service
101+
102+
- name: Collect Artifacts
103+
if: always()
104+
run: |
105+
mkdir -p artifacts
106+
cp -r ./service/build/reports ./artifacts
107+
108+
- name: Upload Artifacts
109+
uses: actions/upload-artifact@v4
110+
if: always()
111+
with:
112+
name: 'Unit Test Reports'
113+
path: ./artifacts/**
114+
compression-level: 9
115+
116+
- name: Temporary Artifacts Cleanup
117+
run: rm -rf ./artifacts
118+
119+
integration-tests:
120+
name: Integration Tests
121+
runs-on: ubuntu-latest
122+
needs: [ checkstyle, spotbugs ]
123+
steps:
124+
- name: Checkout Repository
125+
uses: actions/checkout@v4
126+
127+
- name: Setup Java 21 LTS
128+
uses: actions/setup-java@v4
129+
with:
130+
java-version: 21
131+
distribution: 'temurin'
132+
133+
- name: Start Docker Dependencies
134+
env:
135+
PEM111_AMQP_BROKER: "amqp://activemq:5672"
136+
PEM111_AMQP_PORT: "5672"
137+
PEM111_ITK_EXTERNAL_CONFIGURATION_URL: "http://wiremock:8080/configuration/ods-dos"
138+
LOG_LEVEL: DEBUG
139+
run: |
140+
docker network create 111network
141+
docker compose build
142+
docker compose up activemq wiremock --detach
143+
working-directory: ./docker
144+
145+
- name: Execute Integration Tests
146+
run: ./gradlew integrationTest
147+
working-directory: ./service
148+
149+
- name: Dump Docker Logs
150+
if: always()
151+
run: ./dump_docker_logs.sh
152+
working-directory: ./scripts
153+
shell: bash
154+
155+
- name: Collect Artifacts
156+
if: always()
157+
run: |
158+
mkdir -p artifacts
159+
cp -r ./service/build/reports ./artifacts
160+
cp -r ./scripts/logs ./artifacts
161+
162+
- name: Upload Artifacts
163+
uses: actions/upload-artifact@v4
164+
if: always()
165+
with:
166+
name: 'Integration Test Reports & Docker Logs'
167+
path: ./artifacts/**
168+
compression-level: 9
169+
170+
- name: Stop Docker Dependencies
171+
if: always()
172+
run: |
173+
docker compose down --rmi=local --volumes --remove-orphans
174+
docker compose rm
175+
docker network rm 111network
176+
working-directory: ./docker
177+
178+
- name: Temporary Artifacts Cleanup
179+
run: rm -rf ./artifacts
180+
181+
generate-build-id:
182+
name: Generate Build ID
183+
runs-on: ubuntu-latest
184+
needs: [unit-tests, integration-tests]
185+
outputs:
186+
build-id: ${{ steps.generate.outputs.buildId }}
187+
steps:
188+
- name: Checkout Repository
189+
uses: actions/checkout@v4
190+
191+
- id: generate
192+
working-directory: ./scripts
193+
shell: bash
194+
run: |
195+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
196+
GIT_BRANCH=PR
197+
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/master" ]]; then
198+
GIT_BRANCH=master
199+
fi
200+
201+
BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }})
202+
echo "Generated the build tag: $BUILD_ID"
203+
echo "buildId=$BUILD_ID" >> $GITHUB_OUTPUT
204+
205+
206+
build-and-publish-docker-images:
207+
name: Build & Publish Docker Images
208+
runs-on: ubuntu-latest
209+
needs: [unit-tests, integration-tests, generate-build-id]
210+
permissions:
211+
id-token: write
212+
contents: read
213+
strategy:
214+
matrix:
215+
config:
216+
- directory: service
217+
repository: 111
218+
build-context: .
219+
- directory: nginx
220+
repository: 111-nginx
221+
build-context: .
222+
223+
if: github.actor != 'dependabot[bot]'
224+
steps:
225+
- name: Checkout Repository
226+
uses: actions/checkout@v4
227+
228+
- name: Configure AWS Credentials
229+
uses: aws-actions/configure-aws-credentials@v4
230+
with:
231+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }}
232+
role-session-name: 111_github_action_build_workflow
233+
aws-region: ${{ secrets.AWS_REGION || 'eu-west-2' }}
234+
235+
- name: Build Docker Image
236+
run: |
237+
# Create Docker Tag
238+
DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
239+
DOCKER_TAG="$DOCKER_REGISTRY/${{ matrix.config.repository }}:${{ needs.generate-build-id.outputs.build-id }}"
240+
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
241+
242+
# Build Image
243+
docker build -f ./docker/${{ matrix.config.directory }}/Dockerfile -t $DOCKER_TAG ${{ matrix.config.build-context }}
244+
245+
- name: Login to AWS ECR
246+
run: |
247+
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
248+
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $DOCKER_REGISTRY
249+
250+
- name: Publish image to ECR
251+
run: docker push $DOCKER_TAG
252+
253+
- name: Logout of AWS ECR (Clean up Credentials)
254+
if: always()
255+
run: |
256+
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
257+
docker logout $DOCKER_REGISTRY
258+
259+
comment:
260+
if: github.event_name == 'pull_request'
261+
name: "Create Build ID Comment"
262+
needs: [generate-build-id]
263+
continue-on-error: true
264+
permissions: write-all
265+
runs-on: [ ubuntu-latest ]
266+
steps:
267+
- name: Check out code
268+
uses: actions/checkout@v4
269+
- name: Comment PR
270+
uses: thollander/actions-comment-pull-request@v3
271+
with:
272+
message: |
273+
Images built and published to ECR using a Build Id of ${{ needs.generate-build-id.outputs.build-id }}
274+
comment_tag: images-built
275+
mode: upsert
276+

scripts/create_build_id.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
clean_tag_element() {
4+
local tag_element="$1"
5+
echo "${tag_element//\//-}"
6+
}
7+
8+
generate_tag() {
9+
local clean_branch_name=$(clean_tag_element "$1")
10+
local clean_build_id=$(clean_tag_element "$2")
11+
local git_hash="$3"
12+
13+
local tag="${clean_branch_name}-${clean_build_id}-${git_hash:0:7}"
14+
15+
echo "$tag"
16+
}
17+
18+
if [[ $# -ne 3 ]]; then
19+
echo "Usage: $0 branch_name build_id git_hash"
20+
exit 1
21+
fi
22+
23+
branch_name="$1"
24+
build_id="$2"
25+
git_hash="$3"
26+
27+
generate_tag "$branch_name" "$build_id" "$git_hash"

scripts/dump_docker_logs.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
mkdir -p ./logs
4+
5+
container_names=$(docker ps -a --format '{{.Names}}')
6+
7+
for container in $container_names; do
8+
docker logs "$container" > ./logs/"$container".log
9+
echo "Logs saved for container: $container"
10+
done

service/build.gradle

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.3.7'
3+
id 'org.springframework.boot' version '3.4.1'
44
id 'io.spring.dependency-management' version '1.1.7'
55
id "io.freefair.lombok" version "8.11"
66
id "checkstyle"
77
id "com.github.spotbugs" version "6.0.27"
8+
id "jacoco"
89
}
910

1011
apply plugin: 'java'
@@ -29,14 +30,13 @@ dependencies {
2930
implementation 'uk.nhs.connect.iucds:iucds-schema:3.0.RC1.2'
3031
implementation 'org.apache.xmlbeans:xmlbeans:3.1.0'
3132
implementation 'com.rabbitmq.jms:rabbitmq-jms:3.4.0'
32-
3333
testImplementation 'org.mockito:mockito-core:5.15.2'
34-
testImplementation 'org.assertj:assertj-core:3.27.1'
34+
testImplementation 'org.assertj:assertj-core:3.27.2'
3535
testImplementation 'org.springframework.boot:spring-boot-starter-test'
36-
testImplementation 'io.rest-assured:rest-assured:5.0.1'
37-
testImplementation 'io.rest-assured:json-path:5.0.1'
36+
testImplementation 'io.rest-assured:rest-assured:5.5.0'
37+
testImplementation 'io.rest-assured:json-path:5.5.0'
3838
testImplementation 'io.rest-assured:xml-path:5.5.0'
39-
testImplementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-dstu3:5.7.2'
39+
testImplementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-dstu3:7.6.1'
4040
testImplementation 'pl.pragmatists:JUnitParams:1.1.1'
4141
}
4242

@@ -65,6 +65,13 @@ test {
6565
useJUnitPlatform()
6666
}
6767

68+
jacocoTestReport {
69+
reports {
70+
xml.required = true
71+
}
72+
dependsOn test // tests are required to run before generating the report
73+
}
74+
6875
task integrationTest(type: Test) {
6976
useJUnitPlatform() {
7077
description = 'Runs integration tests.'

0 commit comments

Comments
 (0)