diff --git a/.github/workflows/scan-sonarcloud.yml b/.github/workflows/scan-sonarcloud.yml index 7c47a83..19c7382 100644 --- a/.github/workflows/scan-sonarcloud.yml +++ b/.github/workflows/scan-sonarcloud.yml @@ -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 \ No newline at end of file + run: ./gradlew assemble sonar --info \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index dcd9d31..e457a0b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" @@ -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" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 93f3dd4..035c7d5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -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" }