Skip to content

Commit b6a1976

Browse files
committed
add in sonar task for hooking into SonarCloud
1 parent e9ea0fa commit b6a1976

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Build cwms-data-api-client
22
on:
3-
push:
43
pull_request:
54
branches:
65
- main
@@ -18,6 +17,12 @@ jobs:
1817
java-version: '21'
1918
java-package: jdk
2019
distribution: 'temurin'
20+
- name: Cache SonarCloud packages
21+
uses: actions/cache@v4.0.0
22+
with:
23+
path: ~/.sonar/cache
24+
key: ${{ runner.os }}-sonar
25+
restore-keys: ${{ runner.os }}-sonar
2126
- name: build and test
2227
id: thebuild
2328
run: ./gradlew build --info --init-script init.gradle
@@ -26,6 +31,11 @@ jobs:
2631
with:
2732
dotnet-version: 6.x
2833
dotnet-quality: 'ga'
34+
- name: Analyze
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
37+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
38+
run: ./gradlew sonar
2939
- name: ReportGenerator
3040
uses: danielpalme/ReportGenerator-GitHub-Action@5.3.6
3141
with:

build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024 Hydrologic Engineering Center
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
125
plugins {
226
id "com.palantir.git-version" version "3.1.0"
27+
id("org.sonarqube") version "5.0.0.4638"
328
}
429

530
def versionLabel(gitInfo) {
@@ -43,4 +68,22 @@ subprojects {
4368
html.outputLocation = layout.buildDirectory.dir('jacoco')
4469
}
4570
}
71+
sonarqube {
72+
properties {
73+
property "sonar.sources", "src/main/java"
74+
property "sonar.tests", "src/test/java"
75+
property 'sonar.coverage.jacoco.xmlReportPaths', "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
76+
}
77+
}
78+
}
79+
80+
sonar {
81+
properties {
82+
property "sonar.projectKey", "cwms_data_api_client"
83+
property "sonar.organization", "HydrologicEngineeringCenter"
84+
property "sonar.host.url", "https://sonarcloud.io"
85+
property "sonar.pullrequest.provider", "GitHub"
86+
property "sonar.pullrequest.github.repository", "HydrologicEngineeringCenter/cwms-data-api-client"
87+
property "sonar.projectVersion", versionDetails().lastTag + "+"
88+
}
4689
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#empty so that SonarCloud can pick up this directory

0 commit comments

Comments
 (0)