Skip to content

Commit

Permalink
Update SonarCloud configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseDreki committed May 5, 2024
1 parent 73adc31 commit 6996ad2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
78 changes: 30 additions & 48 deletions .github/workflows/scan-sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,38 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow helps you trigger a SonarCloud analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# Free for open source project.

# 1. Login to SonarCloud.io using your GitHub account

# 2. Import your project on SonarCloud
# * Add your GitHub organization first, then add your repository as a new project.
# * Please note that many languages are eligible for automatic analysis,
# which means that the analysis will start automatically without the need to set up GitHub Actions.
# * This behavior can be changed in Administration > Analysis Method.
#
# 3. Follow the SonarCloud in-product tutorial
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
#
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
# (On SonarCloud, click on your avatar on top-right > My account > Security
# or go directly to https://sonarcloud.io/account/security/)

# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)

name: SonarCloud analysis

on:
# Only manual run for now as this integration is not scanning Kotlin files
workflow_dispatch:

permissions:
pull-requests: read
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
Analysis:
build:
name: Build and analyze
runs-on: ubuntu-latest

steps:
- name: Analyze with SonarCloud

# You can pin the exact commit or the version.
# uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
uses: SonarSource/sonarcloud-github-action@master
- uses: actions/checkout@v4
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 SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_TOKEN: ${{ secrets.PAT }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args:
-Dsonar.projectKey=NorseDreki_dogcat
-Dsonar.organization=norsedreki
-Dsonar.inclusions=**/*.kt
-Dsonar.language=kotlin
run: ./gradlew assemble sonar --info
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.spotless)
alias(libs.plugins.detekt)
alias(libs.plugins.sonar)
}

group = "com.norsedreki"
Expand Down Expand Up @@ -44,6 +45,16 @@ detekt {
}
}

sonar {
properties {
property("sonar.projectKey", "NorseDreki_dogcat")
property("sonar.organization", "norsedreki")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.inclusions", "**/*.kt")
property("sonar.language", "kotlin")
}
}

kotlin {
val hostOs = System.getProperty("os.name")
val isArm64 = System.getProperty("os.arch") == "aarch64"
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kotlinx-cli = "0.3.6"
spotless = "6.25.0"
ktfmt = "0.47"
detekt = "1.23.6"
sonar = "5.0.0.4638"
kotest-assertions-core = "5.6.2"
turbine = "1.0.0"
mockative = "1.4.1"
Expand All @@ -15,6 +16,7 @@ mockative = "1.4.1"
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
sonar = { id = "org.sonarqube", version.ref = "sonar" }

[libraries]
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
Expand Down

0 comments on commit 6996ad2

Please sign in to comment.