Skip to content

Commit 0955d6d

Browse files
authored
Merge branch 'master' into automate-release
2 parents 5d48c5c + 73419e6 commit 0955d6d

File tree

5 files changed

+330
-6
lines changed

5 files changed

+330
-6
lines changed

.github/workflows/build.yml

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
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: |
152+
chmod +x dump_docker_logs.sh
153+
./dump_docker_logs.sh
154+
working-directory: ./scripts
155+
shell: bash
156+
157+
- name: Collect Artifacts
158+
if: always()
159+
run: |
160+
mkdir -p artifacts
161+
cp -r ./service/build/reports ./artifacts
162+
cp -r ./scripts/logs ./artifacts
163+
164+
- name: Upload Artifacts
165+
uses: actions/upload-artifact@v4
166+
if: always()
167+
with:
168+
name: 'Integration Test Reports & Docker Logs'
169+
path: ./artifacts/**
170+
compression-level: 9
171+
172+
- name: Stop Docker Dependencies
173+
if: always()
174+
run: |
175+
docker compose down --rmi=local --volumes --remove-orphans
176+
docker compose rm
177+
docker network rm 111network
178+
working-directory: ./docker
179+
180+
- name: Temporary Artifacts Cleanup
181+
run: rm -rf ./artifacts
182+
183+
generate-build-id:
184+
name: Generate Build ID
185+
runs-on: ubuntu-latest
186+
needs: [unit-tests, integration-tests]
187+
outputs:
188+
build-id: ${{ steps.generate.outputs.buildId }}
189+
steps:
190+
- name: Checkout Repository
191+
uses: actions/checkout@v4
192+
193+
- id: generate
194+
working-directory: ./scripts
195+
shell: bash
196+
run: |
197+
chmod +x ./create_build_id.sh
198+
199+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
200+
GIT_BRANCH=PR
201+
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/master" ]]; then
202+
GIT_BRANCH=master
203+
fi
204+
205+
BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }})
206+
echo "Generated the build tag: $BUILD_ID"
207+
echo "buildId=$BUILD_ID" >> $GITHUB_OUTPUT
208+
209+
210+
build-and-publish-docker-images:
211+
name: Build & Publish Docker Images
212+
runs-on: ubuntu-latest
213+
needs: [unit-tests, integration-tests, generate-build-id]
214+
permissions:
215+
id-token: write
216+
contents: read
217+
strategy:
218+
matrix:
219+
config:
220+
- directory: service
221+
repository: 111
222+
build-context: .
223+
- directory: nginx
224+
repository: 111-nginx
225+
build-context: .
226+
227+
if: github.actor != 'dependabot[bot]'
228+
steps:
229+
- name: Checkout Repository
230+
uses: actions/checkout@v4
231+
232+
- name: Configure AWS Credentials
233+
uses: aws-actions/configure-aws-credentials@v4
234+
with:
235+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }}
236+
role-session-name: 111_github_action_build_workflow
237+
aws-region: ${{ secrets.AWS_REGION || 'eu-west-2' }}
238+
239+
- name: Build Docker Image
240+
run: |
241+
# Create Docker Tag
242+
DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
243+
DOCKER_TAG="$DOCKER_REGISTRY/${{ matrix.config.repository }}:${{ needs.generate-build-id.outputs.build-id }}"
244+
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
245+
246+
# Build Image
247+
docker build -f ./docker/${{ matrix.config.directory }}/Dockerfile -t $DOCKER_TAG ${{ matrix.config.build-context }}
248+
249+
- name: Login to AWS ECR
250+
run: |
251+
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
252+
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $DOCKER_REGISTRY
253+
254+
- name: Publish image to ECR
255+
run: docker push $DOCKER_TAG
256+
257+
- name: Logout of AWS ECR (Clean up Credentials)
258+
if: always()
259+
run: |
260+
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
261+
docker logout $DOCKER_REGISTRY
262+
263+
comment:
264+
if: github.event_name == 'pull_request'
265+
name: "Create Build ID Comment"
266+
needs: [generate-build-id]
267+
continue-on-error: true
268+
permissions: write-all
269+
runs-on: [ ubuntu-latest ]
270+
steps:
271+
- name: Check out code
272+
uses: actions/checkout@v4
273+
- name: Comment PR
274+
uses: thollander/actions-comment-pull-request@v3
275+
with:
276+
message: |
277+
Images built and published to ECR using a Build Id of ${{ needs.generate-build-id.outputs.build-id }}
278+
comment_tag: images-built
279+
mode: upsert
280+

docker/service/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ RUN mkdir /app
1313

1414
COPY --from=build /home/gradle/service/build/libs/integration-adaptor-111.jar /app/integration-adaptor-111.jar
1515

16-
ENTRYPOINT ["java", "-cp", "/app/integration-adaptor-111.jar", "-Dloader.main=uk.nhs.adaptors.oneoneone.OneOneOneApplication", "org.springframework.boot.loader.PropertiesLauncher"]
16+
ENTRYPOINT ["java", "-cp", "/app/integration-adaptor-111.jar", "-Dloader.main=uk.nhs.adaptors.oneoneone.OneOneOneApplication", "org.springframework.boot.loader.launch.PropertiesLauncher"]

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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
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'
@@ -27,17 +28,16 @@ dependencies {
2728
implementation 'org.springframework:spring-jms'
2829
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:5.7.2'
2930
implementation 'uk.nhs.connect.iucds:iucds-schema:3.0.RC1.2'
30-
implementation 'jaxen:jaxen:1.2.0'
3131
implementation 'org.apache.xmlbeans:xmlbeans:3.1.0'
3232
implementation 'com.rabbitmq.jms:rabbitmq-jms:3.4.0'
3333

3434
testImplementation 'org.mockito:mockito-core:4.4.0'
35-
testImplementation 'org.assertj:assertj-core:3.27.0'
35+
testImplementation 'org.assertj:assertj-core:3.27.1'
3636
testImplementation 'org.springframework.boot:spring-boot-starter-test'
37-
testImplementation 'io.rest-assured:rest-assured:5.0.1'
38-
testImplementation 'io.rest-assured:json-path:5.0.1'
37+
testImplementation 'io.rest-assured:rest-assured:5.5.0'
38+
testImplementation 'io.rest-assured:json-path:5.5.0'
3939
testImplementation 'io.rest-assured:xml-path:5.5.0'
40-
testImplementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-dstu3:5.7.2'
40+
testImplementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-dstu3:7.6.1'
4141
testImplementation 'pl.pragmatists:JUnitParams:1.1.1'
4242
}
4343

@@ -66,6 +66,13 @@ test {
6666
useJUnitPlatform()
6767
}
6868

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

0 commit comments

Comments
 (0)