diff --git a/.github/workflows/code-analyze-pr.yml b/.github/workflows/code-analyze-pr.yml new file mode 100644 index 00000000..08f369c6 --- /dev/null +++ b/.github/workflows/code-analyze-pr.yml @@ -0,0 +1,49 @@ +name: Code Analyze Pull Request + +run-name: Run code analyze triggered with pull request by ${{github.actor}} + +on: + pull_request: + types: [opened, reopened, synchronize] + branches: + - main + - dev + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'temurin' # Alternative distribution options are available. + - 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 with tests + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} + continue-on-error: true + run: ./gradlew build --info + + - name: SonarQube Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + run: ./gradlew sonar --info diff --git a/.github/workflows/code-analyze-push.yml b/.github/workflows/code-analyze-push.yml new file mode 100644 index 00000000..900bcde7 --- /dev/null +++ b/.github/workflows/code-analyze-push.yml @@ -0,0 +1,46 @@ +name: Code Analyze Push + +run-name: Run code analyze triggered with push by ${{github.actor}} + +on: + push: + branches: + - dev +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'temurin' # Alternative distribution options are available. + - 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 with tests + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} + continue-on-error: true + run: ./gradlew build --info + + - name: SonarQube Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + run: ./gradlew sonar --info \ No newline at end of file diff --git a/build.gradle b/build.gradle index de636ea2..3a6710c0 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.4.5' id 'io.spring.dependency-management' version '1.1.7' + id "org.sonarqube" version "6.0.1.5171" id 'jacoco' } @@ -64,4 +65,27 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy jacocoTestReport } + +jacocoTestReport { + reports { + xml.required = true + html.required = true + } + dependsOn test +} + +sonar { + properties { + property "sonar.projectKey", "CleanEngine_cleanengine-be_2b6f2f63-fa39-426c-b9c7-8aa127fd14d8" + property "sonar.projectName", "cleanengine-be" + property "sonar.host.url", System.getenv('SONAR_HOST_URL') ?: 'http://localhost:9000' + property "sonar.token", System.getenv('SONAR_TOKEN') ?: '' + property "sonar.java.source", '21' + property "sonar.java.target", '21' + property "sonar.sourceEncoding", "UTF-8" + property "sonar.java.coveragePlugin", "jacoco" + property "sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml" + } +} \ No newline at end of file