From b6a19768dd48d9b88dd453d16d2202857ba8d2e4 Mon Sep 17 00:00:00 2001 From: Adam Korynta Date: Thu, 13 Jun 2024 12:07:17 -0700 Subject: [PATCH] add in sonar task for hooking into SonarCloud --- .github/workflows/build.yml | 12 ++++++- build.gradle | 43 +++++++++++++++++++++++ cwms-radar-model/src/test/java/.gitignore | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 cwms-radar-model/src/test/java/.gitignore diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0752b688..b9bd86ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,5 @@ name: Build cwms-data-api-client on: - push: pull_request: branches: - main @@ -18,6 +17,12 @@ jobs: java-version: '21' java-package: jdk distribution: 'temurin' + - name: Cache SonarCloud packages + uses: actions/cache@v4.0.0 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar - name: build and test id: thebuild run: ./gradlew build --info --init-script init.gradle @@ -26,6 +31,11 @@ jobs: with: dotnet-version: 6.x dotnet-quality: 'ga' + - name: Analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew sonar - name: ReportGenerator uses: danielpalme/ReportGenerator-GitHub-Action@5.3.6 with: diff --git a/build.gradle b/build.gradle index 17f7b11c..64a86148 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,30 @@ +/* + * MIT License + * + * Copyright (c) 2024 Hydrologic Engineering Center + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + plugins { id "com.palantir.git-version" version "3.1.0" + id("org.sonarqube") version "5.0.0.4638" } def versionLabel(gitInfo) { @@ -43,4 +68,22 @@ subprojects { html.outputLocation = layout.buildDirectory.dir('jacoco') } } + sonarqube { + properties { + property "sonar.sources", "src/main/java" + property "sonar.tests", "src/test/java" + property 'sonar.coverage.jacoco.xmlReportPaths', "${buildDir}/reports/jacoco/test/jacocoTestReport.xml" + } + } +} + +sonar { + properties { + property "sonar.projectKey", "cwms_data_api_client" + property "sonar.organization", "HydrologicEngineeringCenter" + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.pullrequest.provider", "GitHub" + property "sonar.pullrequest.github.repository", "HydrologicEngineeringCenter/cwms-data-api-client" + property "sonar.projectVersion", versionDetails().lastTag + "+" + } } \ No newline at end of file diff --git a/cwms-radar-model/src/test/java/.gitignore b/cwms-radar-model/src/test/java/.gitignore new file mode 100644 index 00000000..bc9aba79 --- /dev/null +++ b/cwms-radar-model/src/test/java/.gitignore @@ -0,0 +1 @@ +#empty so that SonarCloud can pick up this directory \ No newline at end of file