From 693d766a4c96fa5970702eb7dbbd95cf86bc2d99 Mon Sep 17 00:00:00 2001 From: wikijito7 Date: Sun, 23 Mar 2025 19:11:30 +0100 Subject: [PATCH 1/5] Added templates and actions --- .github/ISSUE_TEMPLATE/bug_report.md | 27 +++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 23 +++++++++++ .github/ISSUE_TEMPLATE/other-issue.md | 17 ++++++++ .github/PULL_REQUEST_TEMPLATE.md | 30 ++++++++++++++ .github/workflows/ktlint.yaml | 28 +++++++++++++ .github/workflows/sonarcloud-analysis.yaml | 46 ++++++++++++++++++++++ 6 files changed, 171 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/other-issue.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ktlint.yaml create mode 100644 .github/workflows/sonarcloud-analysis.yaml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..29d3192 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG] Your title about the bug" +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Media** +If applicable, add screenshots or a video to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..73e7360 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[Suggestion] Your title here" +labels: suggestion +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. + +**Media** +Media to further explain this suggestion diff --git a/.github/ISSUE_TEMPLATE/other-issue.md b/.github/ISSUE_TEMPLATE/other-issue.md new file mode 100644 index 0000000..9e2166d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other-issue.md @@ -0,0 +1,17 @@ +--- +name: Other issue +about: Other issue not related to Bug report or Feature request +title: "[Other] Your title here" +labels: help wanted +assignees: '' + +--- + +**Other issue? Please describe.** +A clear and concise description of what the problem is. + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Media** +Media to further explain this issue. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..e1d62dd --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,30 @@ + +Solves #issue1, #issue2, #issuen. + +## 📋 Changelist Summary +Small description of this PR. + +## đŸ’Ŧ Description +A longer description of this PR. + + + +## 🐞 Steps to reproduce bug +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +## 📷 Media +Add media if applies. + + + + +## â„šī¸ Extra info +Extra information of this PR, if any. \ No newline at end of file diff --git a/.github/workflows/ktlint.yaml b/.github/workflows/ktlint.yaml new file mode 100644 index 0000000..f5d886b --- /dev/null +++ b/.github/workflows/ktlint.yaml @@ -0,0 +1,28 @@ +name: ktlint + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +on: [pull_request] +jobs: + ktlint: + name: Check Code Quality + runs-on: ubuntu-latest + + permissions: + checks: write + contents: read + pull-requests: write + + steps: + - name: Clone repo + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: ktlint + uses: ScaCap/action-ktlint@master + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + fail_on_error: true diff --git a/.github/workflows/sonarcloud-analysis.yaml b/.github/workflows/sonarcloud-analysis.yaml new file mode 100644 index 0000000..ffe31ed --- /dev/null +++ b/.github/workflows/sonarcloud-analysis.yaml @@ -0,0 +1,46 @@ +name: SonarCloud +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY }} + SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + 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.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew build sonar --info \ No newline at end of file From 2cd515e50e0f5b374f5dcf6deabfdb9c214f027c Mon Sep 17 00:00:00 2001 From: wikijito7 Date: Sun, 23 Mar 2025 19:16:38 +0100 Subject: [PATCH 2/5] gradlew as executable --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From a0a13f1238bec63c9b641c7692bd88b96cb4bff0 Mon Sep 17 00:00:00 2001 From: wikijito7 Date: Sun, 23 Mar 2025 19:28:54 +0100 Subject: [PATCH 3/5] Configured sonar & jacoco --- build.gradle.kts | 48 ++++++++++++++++++++++++++++++++++++--- gradle/libs.versions.toml | 8 +++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 33cfad9..a5fc69e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,10 @@ plugins { application - kotlin("jvm") version "2.1.20" - id("io.ktor.plugin") version "3.1.1" + alias(libs.plugins.kotlin.jvm) + jacoco + alias(libs.plugins.sonarqube) + alias(libs.plugins.plugin.serialization) + alias(libs.plugins.ktor.plugin) } group = "es.wokis" @@ -69,4 +72,43 @@ ktor { fatJar { archiveFileName.set("${rootProject.name}-${rootProject.version}.jar") } -} \ No newline at end of file +} + +tasks.test { + useJUnitPlatform() + finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run +} + +jacoco { + toolVersion = libs.versions.jacoco.get() + reportsDirectory = layout.buildDirectory.dir("customJacocoReportDir") +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) // tests are required to run before generating the report + reports { + xml.required = true + xml.outputLocation.set(file("build/reports/jacoco/test-results/jacocoTestReport.xml")) + csv.required = false + html.outputLocation = layout.buildDirectory.dir("jacocoHtml") + } +} + +sonar { + properties { + val projectKey = System.getenv("SONAR_PROJECT_KEY") + val organization = System.getenv("SONAR_ORGANIZATION") + val exclusions = listOf( + "**/*BO.kt", + "**/*DTO.kt", + "**/*Exception.kt", + "src/main/kotlin/es/wokis/Application.kt", + "*.kts", + "**/di/*.kt", + ) + property("sonar.projectKey", projectKey) + property("sonar.organization", organization) + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.coverage.exclusions", exclusions) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9796ebb..635b033 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,8 @@ javamail-api = "2.1.3" javamail = "2.0.1" bcrypt = "0.4" slf4j = "2.0.17" +sonarqube = "6.0.1.5171" +jacoco = "0.8.12" [libraries] # Ktor dependencies @@ -60,3 +62,9 @@ kotlin-onetimepassword = { module = "dev.turingcomplete:kotlin-onetimepassword", # Commons Codec commons-codec = { module = "commons-codec:commons-codec", version.ref = "commons-codec" } + +[plugins] +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" } +ktor-plugin = { id = "io.ktor.plugin", version.ref = "ktor" } From 814be606c00429dee8078d7aed59c2b4568ab85a Mon Sep 17 00:00:00 2001 From: wikijito7 Date: Sun, 23 Mar 2025 19:36:58 +0100 Subject: [PATCH 4/5] Fixed sonar launching error --- build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index a5fc69e..5d5a28b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,6 +74,10 @@ ktor { } } +tasks.shadowJar { + dependsOn.addAll(listOf("compileJava", "compileKotlin", "processResources", "distTar", "distZip")) +} + tasks.test { useJUnitPlatform() finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run From 26b640daf674f9438ff933f33f60102a52d7f0a1 Mon Sep 17 00:00:00 2001 From: wikijito7 Date: Sun, 23 Mar 2025 19:38:50 +0100 Subject: [PATCH 5/5] editor config --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dc2c1e1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +[*.{kt,kts}] +ktlint_experimental = disabled +ktlint_code_style = intellij_idea +ktlint_standard_trailing-comma-on-call-site = disabled +ktlint_standard_trailing-comma-on-declaration-site = disabled +ktlint_standard_function-signature = disabled +ktlint_standard_multiline-expression-wrapping = disabled +ktlint_standard_no-wildcard-imports = disabled +ktlint_standard_class-signature = disabled \ No newline at end of file