diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index 7b02547..2cea32a 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -39,4 +39,5 @@ jobs: run: | mkdir -p src/test/resources echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties + echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties mvn clean verify sonar:sonar -Dsonar.qualitygate.wait=true diff --git a/.gitignore b/.gitignore index 667aaef..0f24cd9 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ build/ ### VS Code ### .vscode/ + +# Test configuration generated in CI +src/test/resources/application-test.properties diff --git a/README.md b/README.md index 02b7578..6ad18d6 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,28 @@ A GitHub Actions workflow is configured in: mvn clean verify sonar:sonar ``` +The CI command waits for the Quality Gate result: + +```bash +./mvnw clean verify sonar:sonar -Dsonar.qualitygate.wait=true +``` + +Before running tests, the workflow recreates: + +```bash +src/test/resources/application-test.properties +``` + +from a Base64-encoded GitHub secret. + +### Required GitHub Secrets + +- `SONAR_TOKEN` +- `SONAR_HOST_URL` +- `APPLICATION_TEST_PROPERTIES` (Base64-encoded `application-test.properties` content) + +> `GITHUB_TOKEN` is provided automatically by GitHub Actions. + ### Generate the JaCoCo coverage report locally Run: diff --git a/pom.xml b/pom.xml index bac59da..eddcf54 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,11 @@ ${project.build.directory}/site/jacoco/jacoco.xml + + com.h2database + h2 + test + org.springframework.boot spring-boot-starter-actuator diff --git a/src/test/java/com/xpeho/spring_boot_java_random_user/SpringBootJavaRandomUserApplicationTests.java b/src/test/java/com/xpeho/spring_boot_java_random_user/SpringBootJavaRandomUserApplicationTests.java index 367a822..21bcb10 100644 --- a/src/test/java/com/xpeho/spring_boot_java_random_user/SpringBootJavaRandomUserApplicationTests.java +++ b/src/test/java/com/xpeho/spring_boot_java_random_user/SpringBootJavaRandomUserApplicationTests.java @@ -2,9 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class SpringBootJavaRandomUserApplicationTests { @Test