diff --git a/.github/workflows/CI.yml b/.github/workflows/build.yml similarity index 63% rename from .github/workflows/CI.yml rename to .github/workflows/build.yml index 337e3ea..22d30fd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/build.yml @@ -1,54 +1,65 @@ -name: Build -on: - push: - branches: - - main # the name of your main branch - pull_request: - types: [opened, synchronize, reopened] -jobs: - build: - name: Build - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - pull-requests: write - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 23 - uses: actions/setup-java@v1 - with: - java-version: 23 - - name: Cache SonarQube packages - uses: actions/cache@v4 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Build and analyze - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - run: ./gradlew build - - name: Store HTML coverage report - uses: actions/upload-artifact@v4 - with: - name: coverage-report - path: "${{github.workspace}}/build/reports/jacoco/test/html/" - - name: Add coverage to PR - id: jacoco - uses: madrapps/jacoco-report@v1.7.1 - with: - paths: | - ${{ github.workspace }}/**/build/reports/jacoco/test/*.xml, - token: ${{ secrets.GITHUB_TOKEN }} - min-coverage-overall: 40 - min-coverage-changed-files: 60 \ No newline at end of file +name: Build +on: + push: + branches: + - "**" + +jobs: + build: + name: Build & Test (H2) + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + pull-requests: write + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensure full history for SonarQube analysis + + - name: Set up JDK 23 + uses: actions/setup-java@v1 + with: + java-version: 23 + + - name: Cache SonarQube packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: gradle-cache-${{ runner.os }}-${{ hashFiles('**/*.gradle') }} + restore-keys: gradle-cache-${{ runner.os }} + + - name: Run Tests (Using H2) + env: + SPRING_PROFILES_ACTIVE: test # Force use of H2 DB + run: ./gradlew test + + - name: Build and Analyze with SonarQube + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_SCANNER_OPTS: "-Dsonar.qualitygate.wait=true -Dsonar.pullrequest.github.summary_only=true" + run: ./gradlew build sonar --info + + - name: Store HTML coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: "${{github.workspace}}/build/reports/jacoco/test/html/" + + - name: Add coverage to PR + id: jacoco + uses: madrapps/jacoco-report@v1.7.1 + with: + paths: | + ${{ github.workspace }}/**/build/reports/jacoco/test/*.xml, + token: ${{ secrets.GITHUB_TOKEN }} + min-coverage-overall: 40 + min-coverage-changed-files: 60 diff --git a/build.gradle.kts b/build.gradle.kts index ff1cf44..2f039cf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,14 @@ plugins { id("org.sonarqube") version "6.0.1.5171" } +sonar { + properties { + property("sonar.projectKey", "frank-connolly_gymcore") + property("sonar.organization", "frank-connolly") + property("sonar.host.url", "https://sonarcloud.io") + } +} + group = "org.justjava" version = "0.0.1-SNAPSHOT" @@ -24,11 +32,11 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.flywaydb:flyway-core") implementation("org.flywaydb:flyway-database-postgresql") + implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0") // Version must be specified explicitly compileOnly("org.projectlombok:lombok") annotationProcessor("org.projectlombok:lombok") testCompileOnly("org.projectlombok:lombok") testAnnotationProcessor("org.projectlombok:lombok") - implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0") // Version must be specified explicitly developmentOnly("org.springframework.boot:spring-boot-devtools") runtimeOnly("org.postgresql:postgresql") testImplementation("org.springframework.boot:spring-boot-starter-test")