diff --git a/.github/workflows/halo.yaml b/.github/workflows/halo.yaml index 3c61b7650..b4304e2a0 100644 --- a/.github/workflows/halo.yaml +++ b/.github/workflows/halo.yaml @@ -33,6 +33,12 @@ jobs: distribution: 'temurin' cache: 'gradle' java-version: 17 + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar - uses: dorny/paths-filter@v2 id: changes with: @@ -43,6 +49,12 @@ jobs: run: ./gradlew check - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 + - name: Analyze code + if: ${{ github.event_name == 'push' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed. + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew sonar --info - name: Setup console environment if: steps.changes.outputs.console == 'true' uses: halo-sigs/actions/admin-env-setup@main diff --git a/api/build.gradle b/api/build.gradle index 102a50883..c04f50aad 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java-library' id 'halo.publish' + id 'jacoco' id "io.freefair.lombok" version "8.4" } @@ -80,4 +81,12 @@ java { tasks.named('test') { useJUnitPlatform() + finalizedBy jacocoTestReport +} + +tasks.named('jacocoTestReport') { + reports { + xml.required = true + html.required = false + } } diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..d87dd7583 --- /dev/null +++ b/build.gradle @@ -0,0 +1,13 @@ +plugins { + id "org.sonarqube" version "4.4.1.3373" +} + +group = "run.halo.app" + +sonar { + properties { + property "sonar.projectKey", "halo-dev_halo" + property "sonar.organization", "halo-dev" + property "sonar.host.url", "https://sonarcloud.io" + } +}