diff --git a/.github/workflows/detekt.yml b/.github/workflows/detekt.yml new file mode 100644 index 0000000000..2a1b66c777 --- /dev/null +++ b/.github/workflows/detekt.yml @@ -0,0 +1,51 @@ +# This workflow performs a static analysis of your Kotlin source code using detekt. +# +# Scans are triggered on every pull request targeting the main branch. + +name: detekt + +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + + # Triggers the workflow on pull request events targeting the main branch + pull_request: + branches: + - main + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "detekt" + detekt: + # The type of runner that the job will run on + runs-on: ubuntu-latest + steps: + # Checks out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: "checkout" + uses: actions/checkout@v2 + # Determines changed files + - name: "changed-files" + run: | + git fetch origin main:refs/remotes/origin/main + CHANGED_FILES=$(git --no-pager diff --name-only origin/main HEAD -- . ':!exposed-tests' | grep '\(.*.kt\|.*.kts\)$' | tr '\n' , | rev | cut -c 2- | rev) + echo "Changed files: $CHANGED_FILES" + echo "CHANGED_FILES=$CHANGED_FILES" >> "$GITHUB_ENV" + # Resolves and installs a specific version of detekt on to a GitHub Actions Runner if not already present in the tool cache + - name: "set-up-detekt" + uses: peter-murray/setup-detekt@v2 + with: + detekt_version: 1.21.0 + # Runs detekt on changed files + - name: "run-detekt" + run: | + echo "Running detekt check..." + DETEKT_ISSUES=$(detekt-cli --build-upon-default-config --config detekt/detekt-config.yml --plugins detekt/detekt-formatting-1.21.0.jar --input $CHANGED_FILES) + if [ -n "$DETEKT_ISSUES" ]; then + echo "***********************************************" + echo "$DETEKT_ISSUES" + echo "***********************************************" + echo " detekt failed " + echo " Please fix the above issues " + echo "***********************************************" + exit 1 + fi diff --git a/.idea/detekt.xml b/.idea/detekt.xml index 3c7a8e356b..a826e5b371 100644 --- a/.idea/detekt.xml +++ b/.idea/detekt.xml @@ -4,7 +4,7 @@ true true true - $PROJECT_DIR$/detekt.yml + $PROJECT_DIR$/detekt/detekt-config.yml @@ -13,7 +13,12 @@ + diff --git a/buildScripts/gradle/checkstyle.gradle.kts b/buildScripts/gradle/checkstyle.gradle.kts index 2793fa290d..997e95ad09 100644 --- a/buildScripts/gradle/checkstyle.gradle.kts +++ b/buildScripts/gradle/checkstyle.gradle.kts @@ -1,5 +1,5 @@ -import io.gitlab.arturbosch.detekt.extensions.DetektExtension import io.gitlab.arturbosch.detekt.DetektPlugin +import io.gitlab.arturbosch.detekt.extensions.DetektExtension apply() @@ -7,8 +7,8 @@ configure { ignoreFailures = false buildUponDefaultConfig = true config = files( - rootDir.resolve("detekt.yml").takeIf { it.isFile }, - projectDir.resolve("detekt.yml").takeIf { it.isFile } + rootDir.resolve("detekt/detekt-config.yml").takeIf { it.isFile }, + projectDir.resolve("detekt/detekt-config.yml").takeIf { it.isFile } ) reports { xml.enabled = true diff --git a/detekt.yml b/detekt/detekt-config.yml similarity index 100% rename from detekt.yml rename to detekt/detekt-config.yml diff --git a/detekt/detekt-formatting-1.21.0.jar b/detekt/detekt-formatting-1.21.0.jar new file mode 100644 index 0000000000..df92689c22 Binary files /dev/null and b/detekt/detekt-formatting-1.21.0.jar differ