Skip to content

Commit f2ddb6c

Browse files
committed
fix(use_h2_sonarqube): update readme
1 parent f6096e9 commit f2ddb6c

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

.github/workflows/sonar.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ jobs:
3838
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
3939
run: |
4040
mkdir -p src/test/resources
41-
echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties
42-
echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties
43-
mvn clean verify sonar:sonar -Dsonar.qualitygate.wait=true
41+
if [ -n "${{ secrets.APPLICATION_TEST_PROPERTIES }}" ]; then
42+
if printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 --decode > src/test/resources/application-test.properties 2>/dev/null; then
43+
echo "Loaded APPLICATION_TEST_PROPERTIES as base64"
44+
else
45+
printf '%s\n' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" > src/test/resources/application-test.properties
46+
echo "Loaded APPLICATION_TEST_PROPERTIES as raw text"
47+
fi
48+
else
49+
: > src/test/resources/application-test.properties
50+
fi
51+
{
52+
echo "spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
53+
echo "spring.datasource.driver-class-name=org.h2.Driver"
54+
echo "spring.datasource.username=sa"
55+
echo "spring.datasource.password="
56+
echo "spring.sql.init.mode=never"
57+
} >> src/test/resources/application-test.properties
58+
./mvnw clean verify sonar:sonar -Dsonar.qualitygate.wait=true

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ Run unit and integration tests:
123123
./mvnw test
124124
```
125125

126-
Tests use **Testcontainers** to spin up ephemeral Docker containers for external dependencies (e.g. PostgreSQL).
126+
`SpringBootJavaRandomUserApplicationTests` uses the `test` profile (`application-test.properties`).
127+
In CI, this file is generated by the Sonar workflow and overridden to use H2 in-memory settings.
127128

128-
> **Prerequisite for tests**: Docker must be installed and running.
129+
> **Note**: Docker is only required for tests that explicitly use Testcontainers.
129130
130131
---
131132

@@ -136,7 +137,10 @@ A GitHub Actions workflow is configured in:
136137
```bash
137138
.github/workflows/sonar.yaml
138139
```
139-
140+
You need to add your own :
141+
```bash
142+
src/test/resources/application-test.properties
143+
```
140144
### Workflow triggers
141145

142146
- `push` on all branches
@@ -147,12 +151,6 @@ A GitHub Actions workflow is configured in:
147151
- Java 25 setup (Temurin)
148152
- Maven build + tests + SonarQube analysis:
149153

150-
```bash
151-
mvn clean verify sonar:sonar
152-
```
153-
154-
The CI command waits for the Quality Gate result:
155-
156154
```bash
157155
./mvnw clean verify sonar:sonar -Dsonar.qualitygate.wait=true
158156
```
@@ -162,14 +160,20 @@ Before running tests, the workflow recreates:
162160
```bash
163161
src/test/resources/application-test.properties
164162
```
163+
spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
164+
spring.datasource.driver-class-name=org.h2.Driver
165+
spring.datasource.username=<your_username>
166+
spring.datasource.password=
167+
spring.sql.init.mode=never
165168

166-
from a Base64-encoded GitHub secret.
169+
and also a github secret named APPLICATION_TEST_PROPERTIES
170+
with the content of your application-test.properties encoded in base64
167171

168172
### Required GitHub Secrets
169173

170174
- `SONAR_TOKEN`
171175
- `SONAR_HOST_URL`
172-
- `APPLICATION_TEST_PROPERTIES` (Base64-encoded `application-test.properties` content)
176+
- `APPLICATION_TEST_PROPERTIES` (`application-test.properties` content, Base64 or raw text)
173177

174178
> `GITHUB_TOKEN` is provided automatically by GitHub Actions.
175179

0 commit comments

Comments
 (0)