Skip to content

Commit

Permalink
chore: Integrate detekt with GitHub Actions (#1765)
Browse files Browse the repository at this point in the history
* chore: Integrate detekt with GitHub Actions

-rename detekt.yml to detekt-config.yml
-add GitHub Actions detekt workflow file, titled detekt.yml, which sets up detekt and runs it only on changed files in a PR
-add detekt-formatting-1.21.0.jar file

* chore: Fix detekt issue in checkstyle.gradle.kts

* chore: Adjust path to detekt config file in detekt.xml

* chore: Exclude exposed-tests directory from detekt GitHub Action

* chore: Add path to detekt plugin JAR file in detekt.xml
  • Loading branch information
joc-a authored Jul 18, 2023
1 parent 7b4929e commit 0bb3ca1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions .idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions buildScripts/gradle/checkstyle.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension

apply<DetektPlugin>()

configure<DetektExtension> {
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
Expand Down
File renamed without changes.
Binary file added detekt/detekt-formatting-1.21.0.jar
Binary file not shown.

0 comments on commit 0bb3ca1

Please sign in to comment.