Skip to content

add in sonar task for hooking into SonarCloud #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
name: Build cwms-data-api-client
name: "Build and Static Code Analysis"
on:
push:
branches: [ main ]
pull_request:
branches:
- main
branches: [ main ]
schedule:
- cron: '0 0 * * 0'


jobs:
build:
name: build and test
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: checkout code
- name: Checkout repository
uses: actions/checkout@v4
with:
# Disabling shallow clone is needed for Sonar reporting
fetch-depth: 0

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: 'java'
- name: setup java
uses: actions/setup-java@v4
with:
java-version: '21'
java-package: jdk
distribution: 'temurin'
- name: build and test
id: thebuild
run: ./gradlew build --info --init-script init.gradle
- name: Setup .NET Core # Required to execute ReportGenerator
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.x
dotnet-quality: 'ga'
- name: ReportGenerator
uses: danielpalme/ReportGenerator-GitHub-Action@5.3.6
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.4.2
with:
reports: cwms-aaa-client/build/reports/jacoco/test/jacocoTestReport.xml;cwms-http-client/build/reports/jacoco/test/jacocoTestReport.xml;cwms-radar-client/build/reports/jacoco/test/jacocoTestReport.xml
targetdir: .github/coveragereport
reporttypes: Html;MarkdownSummaryGithub;Badges
- name: Upload coverage report artifact
uses: actions/upload-artifact@v4.3.3
dependency-graph: generate-and-submit
- name: Cache SonarCloud packages
uses: actions/cache@v4.0.0
with:
name: CoverageReport # Artifact name
path: .github/coveragereport # Directory containing files to upload
- name: Commit and push Badges
if: github.event_name != 'pull_request' && github.ref != 'refs/heads/main'
run: |
cd .github/coveragereport
if [[ `git status --porcelain badge_*coverage.svg` ]]; then
git config --global user.name 'builduser'
git config --global user.email 'builduser@rmanet.com'
git add badge_*coverage.svg
git commit -m "Autogenerated JaCoCo coverage badge" badge_*coverage.svg
git push
fi
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: build and test
id: build
run: ./gradlew build --info --init-script init.gradle
- name: CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: SonarCloud Analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar
37 changes: 0 additions & 37 deletions .github/workflows/codeql.yml

This file was deleted.

43 changes: 43 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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", "HydrologicEngineeringCenter_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 + "+"
}
}
1 change: 1 addition & 0 deletions cwms-radar-model/src/test/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#empty so that SonarCloud can pick up this directory
Loading