From d3821df9f47054e778ba4b3b97d0d04a10f8dfdc Mon Sep 17 00:00:00 2001 From: andrii-hryniv Date: Tue, 13 Jun 2023 14:46:38 +0200 Subject: [PATCH] Add Codacy implementation --- .github/workflows/codacy-build.yml | 32 +++++++++++++++ .github/workflows/sonar-build.yml | 12 +++--- pom.xml | 65 +++++++++++++++--------------- sonar-project.properties | 13 ++++++ 4 files changed, 84 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/codacy-build.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/codacy-build.yml b/.github/workflows/codacy-build.yml new file mode 100644 index 000000000..4de09226a --- /dev/null +++ b/.github/workflows/codacy-build.yml @@ -0,0 +1,32 @@ +name: SonarCloud +on: + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'zulu' # Alternative distribution options are available. + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build and run tests + run: mvn -B verify + - name: Generate JaCoCo XML report + run: mvn jacoco:report -Djacoco.report.failureOnViolation=false + - name: Upload JaCoCo XML report to Codacy + run: | + bash <(curl -Ls https://coverage.codacy.com/get.sh) + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} diff --git a/.github/workflows/sonar-build.yml b/.github/workflows/sonar-build.yml index 6f3d6647c..063cde8f9 100644 --- a/.github/workflows/sonar-build.yml +++ b/.github/workflows/sonar-build.yml @@ -1,10 +1,10 @@ name: SonarCloud -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] +#on: +# push: +# branches: +# - main +# pull_request: +# types: [opened, synchronize, reopened] jobs: build: name: Build and analyze diff --git a/pom.xml b/pom.xml index 44b1df7c1..d3919fd95 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,14 @@ andrii-hryniv_spring-petclinic https://sonarcloud.io target/classes + jacoco + reuseReports + ${project.basedir}/../target/jacoco.exec + java + + target/site/jacoco/jacoco.xml, + build/reports/jacoco/test/jacocoTestReport.xml + @@ -141,7 +149,11 @@ jakarta.xml.bind jakarta.xml.bind-api - + + org.jacoco + jacoco-maven-plugin + 0.8.7 + @@ -279,6 +291,26 @@ false + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + package + + report + + + + @@ -328,37 +360,6 @@ - - coverage - - - - org.jacoco - jacoco-maven-plugin - 0.8.7 - - - prepare-agent - - prepare-agent - - - - report - - report - - - - XML - - - - - - - - css diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..1306cc211 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,13 @@ +sonar.projectKey=andrii-hryniv_${rootProject.name} +sonar.projectName=${rootProject.name} +sonar.organization=andrii-hryniv +sonar.java.binaries=target/classes +sonar.host.url=https://sonarcloud.io +sonar.java.coveragePlugin=jacoco +sonar.dynamicAnalysis=reuseReports +sonar.jacoco.reportPaths=${project.basedir}/../target/jacoco.exec +sonar.sources=src/main +sonar.exclusions=**/resources/**/* +sonar.tests=src/test +sonar.test.exclusions=**/resources/**/* +sonar.java.libraries=/home/vsts/.gradle/**/lombok/**/*.jar