Skip to content

Commit 0e2db20

Browse files
authored
Merge pull request #24 from hmcts/chore/amp-187-api_tests
AMP-187 Trigger api test as downstream of building docker image(push to main)
2 parents 0ecfdc0 + f62ae26 commit 0e2db20

File tree

11 files changed

+357
-42
lines changed

11 files changed

+357
-42
lines changed

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

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
7575
run: |
7676
echo "Building with ARTEFACT_VERSION=$ARTEFACT_VERSION"
77-
gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION
77+
./gradlew build -DARTEFACT_VERSION=$ARTEFACT_VERSION
7878
7979
- name: Extract repo name
8080
id: repo_vars
@@ -89,7 +89,7 @@ jobs:
8989
name: app-jar
9090
path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar
9191

92-
api-test:
92+
API-Test-PR:
9393
if: ${{ inputs.run_api_test }}
9494
needs: [Build]
9595
runs-on: ubuntu-latest
@@ -114,13 +114,13 @@ jobs:
114114
- name: Run API Tests
115115
run: |
116116
cd apiTest
117-
gradle test
117+
../gradlew test
118118
119119
- name: Upload test reports
120120
if: always()
121121
uses: actions/upload-artifact@v6
122122
with:
123-
name: api-test-reports
123+
name: api-test-pr-reports
124124
path: |
125125
apiTest/build/reports/tests/test/
126126
apiTest/build/test-results/test/
@@ -162,7 +162,7 @@ jobs:
162162
163163
echo "Publishing artefact for version: $ARTEFACT_VERSION"
164164
165-
gradle publish \
165+
./gradlew publish \
166166
-DARTEFACT_VERSION=$ARTEFACT_VERSION \
167167
-DGITHUB_REPOSITORY=${{ github.repository }} \
168168
-DGITHUB_ACTOR=${{ github.actor }} \
@@ -206,6 +206,74 @@ jobs:
206206
BASE_IMAGE=openjdk:21-jdk-slim
207207
JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar
208208
209+
API-Test-Main:
210+
if: ${{ inputs.trigger_docker }}
211+
needs: [Build-Docker, Artefact-Version]
212+
runs-on: ubuntu-latest
213+
steps:
214+
- name: Checkout repository
215+
uses: actions/checkout@v6
216+
217+
- name: Set up JDK
218+
uses: actions/setup-java@v5
219+
with:
220+
distribution: 'temurin'
221+
java-version: '21'
222+
223+
- name: Set up Gradle
224+
uses: gradle/actions/setup-gradle@v5
225+
with:
226+
gradle-version: current
227+
228+
- name: Set up Docker Buildx
229+
uses: docker/setup-buildx-action@v3
230+
231+
- name: Log in to GitHub Packages
232+
uses: docker/login-action@v3
233+
with:
234+
registry: ghcr.io
235+
username: ${{ github.actor }}
236+
password: ${{ secrets.GITHUB_TOKEN }}
237+
238+
- name: Run API Tests against published Docker image
239+
env:
240+
DOCKER_IMAGE: ghcr.io/${{ github.repository }}:${{ needs.Artefact-Version.outputs.artefact_version }}
241+
run: |
242+
cd apiTest
243+
# DOCKER_IMAGE is set via env, so docker-compose will use the image instead of building
244+
# Pull the image first to ensure it's available
245+
docker pull $DOCKER_IMAGE
246+
247+
# Start containers using the published image
248+
docker compose up -d
249+
250+
echo "Waiting for health endpoint..."
251+
for i in {1..30}; do
252+
if curl -s http://localhost:8082/actuator/health > /dev/null; then
253+
echo "App is healthy"
254+
break
255+
fi
256+
echo "Waiting for app to be healthy ($i)..."
257+
sleep 2
258+
done
259+
260+
# Run tests (containers already running via docker compose)
261+
# Skip composeUp and composeDown since we manage containers manually
262+
../gradlew testClasses
263+
../gradlew --no-daemon test -x composeUp -x composeDown
264+
265+
# Clean up containers manually
266+
docker compose down
267+
268+
- name: Upload test reports
269+
if: always()
270+
uses: actions/upload-artifact@v6
271+
with:
272+
name: api-test-main-reports
273+
path: |
274+
apiTest/build/reports/tests/test/
275+
apiTest/build/test-results/test/
276+
209277
Deploy:
210278
needs: [ Provider-Deploy, Build, Artefact-Version ]
211279
if: ${{ inputs.trigger_deploy }}

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
- name: Gradle Build
5050
run: |
51-
gradle build cyclonedxBom -x test
51+
./gradlew build cyclonedxBom -x test
5252
5353
# ℹ️ Command-line programs to run using the OS shell.
5454
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -89,7 +89,7 @@ jobs:
8989
gradle-version: current
9090

9191
- name: Gradle Build
92-
run: gradle build -x test
92+
run: ./gradlew build -x test
9393

9494
- name: Set up Docker Buildx
9595
uses: docker/setup-buildx-action@v3

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
gradle/wrapper
21
bin/*
32
!bin/run-in-docker.sh
43
.gradle
54
/build/
6-
/gradlew
75
/gradlew.bat
86
!gradle/wrapper/gradle-wrapper.properties
97
*.class

apiTest/apiTest_README.md

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@ Before running the tests, ensure you have the following installed and configured
4040
cd apiTest
4141

4242
# Run all tests
43-
gradle test
43+
../gradlew test
4444

4545
# Run tests with more verbose output
46-
gradle test --info
46+
../gradlew test --info
4747

4848
# Run tests with debug output
49-
gradle test --debug
49+
../gradlew test --debug
5050
```
5151

5252
### From the apiTest Directory
5353

5454
```bash
55-
# If you're already in the apiTest directory
56-
gradle test
55+
# If you're already in the apiTest directory, you can use either:
56+
./gradlew test # Uses apiTest's own Gradle wrapper
57+
# or
58+
../gradlew test # Uses root project's Gradle wrapper
5759
```
5860

5961
### What Happens When You Run Tests
@@ -71,10 +73,10 @@ gradle test
7173

7274
```bash
7375
# Run a specific test class
74-
gradle test --tests "RootApiTest"
76+
../gradlew test --tests "RootApiTest"
7577

7678
# Run a specific test method
77-
gradle test --tests "RootApiTest.root_endpoint_should_be_ok"
79+
../gradlew test --tests "RootApiTest.root_endpoint_should_be_ok"
7880
```
7981

8082
## Test Reports
@@ -102,15 +104,15 @@ These XML reports are useful for CI/CD integration.
102104
### Issue: "Could not start Gradle Test Executor 1: Failed to load JUnit Platform"
103105

104106
**Solution:** This should be resolved with the current configuration. If you see this error:
105-
1. Clean the build: `gradle clean`
106-
2. Rebuild: `gradle build`
107+
1. Clean the build: `../gradlew clean`
108+
2. Rebuild: `../gradlew build`
107109

108110
### Issue: "no main manifest attribute, in /app/apiTest-0.0.999.jar"
109111

110112
**Solution:** This means the Docker build context is wrong. Ensure:
111113
1. The `docker-compose.yml` has `context: ..` (builds from root directory)
112114
2. The root project's `bootJar` is built before Docker build
113-
3. Run: `gradle buildRootBootJar` manually if needed
115+
3. Run: `../gradlew buildRootBootJar` manually if needed
114116

115117
### Issue: Container exits with code 1
116118

@@ -152,26 +154,6 @@ lsof -i :5432
152154
- Check database logs: `docker-compose -f docker-compose.yml logs db`
153155
- Verify connection string in `docker-compose.yml` matches database configuration
154156

155-
## Manual Container Management
156-
157-
If you need to manually manage containers:
158-
159-
```bash
160-
# Start containers without running tests
161-
docker-compose -f docker-compose.yml up -d
162-
163-
# Stop containers
164-
docker-compose -f docker-compose.yml down
165-
166-
# View container logs
167-
docker-compose -f docker-compose.yml logs -f app
168-
169-
# Check container status
170-
docker-compose -f docker-compose.yml ps
171-
172-
# Rebuild containers
173-
docker-compose -f docker-compose.yml build --no-cache
174-
```
175157

176158
## Test Configuration
177159

@@ -186,6 +168,6 @@ Tests use the following default configuration:
186168

187169
You can override the application URL:
188170
```bash
189-
gradle test -Dapp.baseUrl=http://localhost:8080
171+
../gradlew test -Dapp.baseUrl=http://localhost:8080
190172
```
191173

apiTest/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ dockerCompose {
7979
tasks.register('buildRootBootJar', Exec) {
8080
description = "Builds the root project's bootJar"
8181
workingDir = projectDir.parent
82-
executable = "gradle"
82+
executable = "./gradlew"
8383
args = ['bootJar']
8484
}
8585

apiTest/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ services:
99
- "5432:5432"
1010

1111
app:
12+
# If DOCKER_IMAGE environment variable is set, it will use that image
13+
# Otherwise, it will use the build section below
14+
image: ${DOCKER_IMAGE}
1215
build:
1316
context: ..
1417
dockerfile: Dockerfile
@@ -33,4 +36,3 @@ services:
3336
command:
3437
- "--global-response-templating"
3538
- "--verbose"
36-
44.4 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

gradle/wrapper/gradle-wrapper.jar

44.4 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)