Skip to content

Commit

Permalink
Github action for snapshot diktat
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Jun 9, 2023
1 parent 45e91ba commit 6f91540
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 2 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Run diKTat (release)

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
diktat_check:
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write

steps:
- name: This action is disabled until the release 2.0.0
run: |
echo "This action is disabled until the release 2.0.0"
# - uses: actions/checkout@v3
# - name: Set up JDK 11
# uses: actions/setup-java@v3
# with:
# java-version: 11
# distribution: temurin
# - uses: gradle/gradle-build-action@v2
# with:
# gradle-version: wrapper
# arguments: |
# diktatCheck
# mergeDiktatReports
# -Pdiktat.githubActions=true
# -Pdetekt.multiplatform.disabled=true
# --build-cache
# --continue
# -PgprUser=${{ github.actor }}
# -PgprKey=${{ secrets.GITHUB_TOKEN }}
# - name: Upload SARIF report to Github
# uses: github/codeql-action/upload-sarif@v2
# if: ${{ always() }}
# with:
# sarif_file: build/reports/diktat/diktat-merged.sarif
# - name: Upload SARIF artifacts
# uses: actions/upload-artifact@v3
# if: ${{ failure() }}
# with:
# name: sarif-reports
# path: "**/build/reports/diktat"
# retention-days: 1
28 changes: 27 additions & 1 deletion .github/workflows/diktat_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,40 @@ jobs:
:diktat-gradle-plugin:publishToMavenLocal
:generateLibsForDiktatSnapshot
-x detekt
-x diktatCheck
-x test
# FixMe: return after 2.0.0
# -x diktatCheck


- name: 'Override <gradle/libs.versions.toml>'
run: |
mv gradle/libs.versions.toml gradle/libs.versions.toml_current
mv build/diktat-snapshot/libs.versions.toml_snapshot gradle/libs.versions.toml
# FixMe: remove after 2.0.0
- name: 'Small hack to inject implementation and to run diktat properly from snapshot'
run: |
#!/bin/bash
line_number=26
file_path=gradle/plugins/build.gradle.kts
string_to_insert='implementation(libs.diktat.gradle.plugin) {
exclude("io.github.detekt.sarif4k", "sarif4k")
}'
# Escape the special characters in the string
escaped_string=$(sed 's/[\/&]/\\&/g' <<< "$string_to_insert")
# Create a temporary file
tmp_file=$(mktemp)
# Insert the string as multiple lines after the specified line number
sed "${line_number}r /dev/stdin" "$file_path" <<< "$escaped_string" > "$tmp_file"
# Move the temporary file to overwrite the original file
mv "$tmp_file" "$file_path"
echo "String inserted successfully."
# copied from .github/workflows/diktat.yml
- uses: gradle/gradle-build-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Main features of diktat are the following:

**OR** use `curl`:
```console
$ curl -sSLO https://github.com/saveourtool/diKTat/releases/download/v1.2.5/diktat-1.2.5.jar
$ curl -sSLO https://github.com/saveourtool/diKTat/releases/download/v1.2.5/diktat-1.2.5.jar && chmod a+x diktat
```

### Run diKTat
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ okio = "3.3.0"
kotlinx-datetime = "0.4.0"
kotlinx-coroutines = "1.6.4"
assertj = "3.24.2"
diktat = "2.0.0"
jgit = "6.5.0.202303070854-r"
mockito = "5.2.0"
mockito-kotlin = "4.1.0"
Expand Down Expand Up @@ -166,6 +167,7 @@ validation-api = { module = "jakarta.validation:jakarta.validation-api"}
annotation-api = { module = "jakarta.annotation:jakarta.annotation-api"}

# code quality
diktat-gradle-plugin = { module = "org.cqfn.diktat:diktat-gradle-plugin", version.ref = "diktat" }
detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
gradle-plugin-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
reckon-gradle-plugin = { module = "org.ajoberstar.reckon:reckon-gradle", version.ref = "reckon" }
4 changes: 4 additions & 0 deletions gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ dependencies {
implementation(libs.detekt.gradle.plugin) {
exclude("io.github.detekt.sarif4k", "sarif4k")
}
// FixMe: return after 2.0.0
/* implementation(libs.diktat.gradle.plugin) {
exclude("io.github.detekt.sarif4k", "sarif4k")
}*/
implementation(libs.sarif4k)
implementation(libs.gradle.plugin.spotless)
implementation(libs.publish.gradle.plugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ package com.saveourtool.diktat.buildutils

plugins {
id("com.saveourtool.diktat.buildutils.detekt-convention-configuration")
// FixMe: remove after 2.0.0
if (System.getenv("DIKTAT_SNAPSHOT") != null) {
id("com.saveourtool.diktat.buildutils.diktat-convention-configuration")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cqfn.diktat.buildutils


plugins {
id("org.cqfn.diktat.diktat-gradle-plugin")
}

diktat {
diktatConfigFile = rootProject.file("diktat-analysis.yml")
githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false
inputs {
// using `Project#path` here, because it must be unique in gradle's project hierarchy
if (path == rootProject.path) {
include("gradle/plugins/src/**/*.kt", "*.kts", "gradle/plugins/**/*.kts")
exclude("gradle/plugins/build/**")
} else {
include("src/**/*.kt", "**/*.kts")
exclude(
"src/test/**/*.kt",
"src/test/**/*.kts",
"src/*Test/**/*.kt",
"build/**/*.kts",
)
}
}
}

0 comments on commit 6f91540

Please sign in to comment.