For some reason, my github actions is ignoring my ...
# detekt
n
For some reason, my github actions is ignoring my baseline file. Github actions — Android.yml:
Copy code
name: Android CI

on:
  # Trigger on every pull request and push to the main branches.
  push:
    branches:
      - "1.0"
      - mo_ql
  pull_request:
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'
      - name: Grant execute permission for gradlew
        run: chmod +x gradlew
      - name: Detekt
        run: ./gradlew detektMain
      - name: Build with Gradle
        run: ./gradlew assemble
But when I run
./gradlew detektMain
locally, it works fine. The baselines are on Github in the same folders as seen in the screenshot. Also…
./gradlew detekt
runs real quickly, and outputs nothing detekt related. My config is the default generated one. What did I do wrong?
g
Hey 👋 So I think we’re mixing two things here.
Also…
./gradlew detekt
 runs real quickly, and outputs nothing detekt related.
This is fine. Detekt has no output if it’s green. If you want to really make sure that it works correctly add a
val answer = 42
to any of your source file.
./gradlew detekt
should fail with a
MagicNumber
.
But when I run 
./gradlew detektMain
locally, it works fine.
“works fine” == uses the baseline correctly, while the CI is sort of ignoring it, right?
If so, you should share your build.gradle file (at least the detekt config section).
n
AHHHHH everything works, it went so fast I thought I was doing something wrong
thanks for the reply/help
❤️ 1
g
The reason is “so fast” is because the plain
detekt
is not using type resolution, therefore doesn’t need to compile your source code. The
detektMain
task is running with type resolution and needs to compile your code to run more accurate and advanced analysis.
n
oh ok
👍
g
n
oh cool thanks
it’s not working actually 😞
github actions is still warning me about issues
Anything related to Detekt in my Gradle files: app/build.gradle
Copy code
apply plugin: "io.gitlab.arturbosch.detekt"
.... 
detekt {
    config = files("$rootDir/config/detekt/detekt.yml")
}
project build.gradle:
Copy code
buildscript {
....
    dependencies {
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.0-RC2"
     }
}
👍 1
g
So, have you called
./gradlew :app:detektBaseline
and verified that a baseline file gets created? If so have you verified that it works locally? If so have you checked that the baseline file is actually committed (you might have a
.gitignore
somewhere)?
n
It works locally. I’ve confirmed that the baselines are uploaded to github
(I tried commenting out the
config =
part to see if that would fix it too, but no dice.
g
Ok so, at this stage it’s hard to say what’s the problem. Could be a bug with detekt but I’m unsure. If you could provide some sort of reproducer that would be great 🙏 You can use this template to try to recreate your setup (it has detekt already configured): github.com/cortinico/kotlin-android-template/
n
ok i’ll try!
well, I checked out the base branch and created a new branch off of that, copied all detekt related code and github actions, pushed it, and now it works
🤷‍♀️
g
Awesome :)
n
ughhh i’m running into the same issue again 😞
g
I’m unsure how to help ¯\_(ツ)_/¯ If you can provide a reproducer I could look into it.
n
I forked/created this, with some tweaks (latest detekt, ability to set the baseline file), and am running into the same issue. With the same exact command (errr, not using the
.jar
rather just the executable) it works on my local machine, but in the container it fails. Any suggestions?
i wish i could flip my desk over but i need it to work 😞
g
┻━┻︵ \(°□°)/ ︵ ┻━┻
n
haha
g
Anyway, seems like there is no CI run: https://github.com/nachtien/Detekt-Action/actions
n
two desks!
i’m including that in a diff proj via this:
Copy code
name: Android CI

on:
  # Trigger on every pull request and push to the main branches.
  push:
    branches:
      - "1.0"
      - mo_ql
  pull_request:
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Grant execute permission for gradlew
        run: chmod +x gradlew
      - name: detekt
        uses: nachtien/Detekt-Action@1.22
        with:
          github_token: ${{ secrets.DETEKT_TOKEN }}
          detekt_config: config/detekt/detekt.yml
          detekt_baseline: app/detekt-baseline.xml
      - name: Build with Gradle
        run: ./gradlew assemble
so the CI runs in that project
g
Oh sorry, yeah I missunderstood
n
np i shoudla been more clear
g
So your problem is that you’re trying to build a GH Actions using Detekt
n
Detekt runs, but the baseline file is never read/parsed/used
g
Random question, is there a reason why you haven’t used one of the action that are already available? https://github.com/marketplace?type=actions&query=detekt+
n
the one i forked from uses review dog to leave comments, but didn’t use the baseline file.
g
I’m afraid the problem is a path problem of some form.
n
when i have an invalid path, it gives me an error
g
What you can do, is rebuild a local version of Detekt and use it, like adding some println (e.g. maybe you can print the content of Baseline file).
❤️ 1
n
ok i’ll try to cat it out
g
Yeah even. Also if you run
gradlew detekt --debug
you might see what’s going on
n
👍
Results are in 🦜 1. I was able to print out the
baseline
file (it appears normal) 2. I passed in
debug
, there doesn’t appear to be anything wrong 3. I’m using Act to run this locally, but am experiencing the same issue on Github 4. Command ran:
Copy code
java -jar /opt/detekt.jar --fail-fast --debug --config config/detekt/detekt.yml --report xml:detekt_report.xml --baseline app/detekt-baseline.xml --excludes '**/build/**,**/.idea/**' --plugins /opt/detekt-formatting.jar
Output: 547 weighted issues (I didn’t write this code 😄 ) 5. Locally in my terminal:
Copy code
./detekt-cli-1.18.0-RC2/bin/detekt-cli --fail-fast --debug --config config/detekt/detekt.yml --report xml:detekt_report.xml --baseline app/detekt-baseline.xml --excludes '**/build/**,**/.idea/**'
It prints the rule sets, extensions, and everything seems fine.
g
Can you try locally with
java -jar
Like with the same Jar you're using on CI
n
When I run that command with the baseline file locally, it completes with no warnings
Copy code
> java -jar /Users/nickachtien/Downloads/detekt-cli-1.18.0-RC2-all.jar --fail-fast --debug --config config/detekt/detekt.yml --report xml:detekt_report.xml --baseline app/detekt-baseline.xml --excludes '**/build/**,**/.idea/**'
Loaded extensions:

Registered rule sets:
    io.gitlab.arturbosch.detekt.rules.complexity.ComplexityProvider@2cf92cc7
    io.gitlab.arturbosch.detekt.rules.coroutines.CoroutinesProvider@30ea8c23
    io.gitlab.arturbosch.detekt.rules.documentation.CommentSmellProvider@7b139eab
    io.gitlab.arturbosch.detekt.rules.empty.EmptyCodeProvider@4e76dac
    io.gitlab.arturbosch.detekt.rules.bugs.PotentialBugProvider@611df6e3
    io.gitlab.arturbosch.detekt.rules.exceptions.ExceptionsProvider@5f2f577
    io.gitlab.arturbosch.detekt.rules.naming.NamingProvider@6273c5a4
    io.gitlab.arturbosch.detekt.rules.performance.PerformanceProvider@5d465e4b
    io.gitlab.arturbosch.detekt.rules.style.StyleGuideProvider@53e211ee
Ignoring file '/Users/nickachtien/Projects/StructionSite_Android/app/build/generated/source/apollo/standardDebug/service/type/CustomType.kt'
Ignoring file '/Users/nickachtien/Projects/StructionSite_Android/app/build/generated/source/apollo/standardDebug/service/SignInMutation.kt'
Ignoring file '/Users/nickachtien/Projects/StructionSite_Android/app/build/generated/source/apollo/standardDebug/service/SignUpMutation.kt'
Loaded extensions:
    io.gitlab.arturbosch.detekt.rules.documentation.LicenceHeaderLoaderExtension@59c70ceb
    io.github.detekt.metrics.processors.ProjectSLOCProcessor@46f902e0
    io.github.detekt.metrics.processors.ProjectLOCProcessor@64f981e2
    io.github.detekt.metrics.processors.ProjectCLOCProcessor@361abd01
    io.github.detekt.metrics.processors.ProjectLLOCProcessor@575b5f7d
    io.github.detekt.metrics.processors.ProjectCognitiveComplexityProcessor@59bbb974
    io.github.detekt.metrics.processors.ProjectComplexityProcessor@7165d530
    io.github.detekt.metrics.processors.PropertyCountProcessor@12f49ca8
    io.github.detekt.metrics.processors.FunctionCountProcessor@1fd9893c
    io.github.detekt.metrics.processors.ClassCountProcessor@1b2df3aa
    io.github.detekt.metrics.processors.PackageCountProcessor@44be69aa
    io.github.detekt.metrics.processors.KtFileCountProcessor@7219ac49
Registered rule sets:
    io.gitlab.arturbosch.detekt.rules.complexity.ComplexityProvider@9b76b60
    io.gitlab.arturbosch.detekt.rules.coroutines.CoroutinesProvider@3fb9a67f
    io.gitlab.arturbosch.detekt.rules.documentation.CommentSmellProvider@127705e4
    io.gitlab.arturbosch.detekt.rules.empty.EmptyCodeProvider@5562c2c9
    io.gitlab.arturbosch.detekt.rules.bugs.PotentialBugProvider@673c4f6e
    io.gitlab.arturbosch.detekt.rules.exceptions.ExceptionsProvider@15c487a8
    io.gitlab.arturbosch.detekt.rules.naming.NamingProvider@3f36e8d1
    io.gitlab.arturbosch.detekt.rules.performance.PerformanceProvider@7c011174
    io.gitlab.arturbosch.detekt.rules.style.StyleGuideProvider@794366a5
Loaded extensions:
    io.gitlab.arturbosch.detekt.core.baseline.BaselineResultMapping@32ebfde1
Loaded extensions:
    io.github.detekt.report.sarif.SarifOutputReport@448a2c5d
    io.github.detekt.report.html.HtmlOutputReport@7054edda
    io.github.detekt.report.xml.XmlOutputReport@4a09a4df
    io.github.detekt.report.txt.TxtOutputReport@7de47f81
Loaded extensions:
    io.gitlab.arturbosch.detekt.core.reporting.console.FindingsReport@62885131
Phase LoadConfig took PT0.073S
Phase CreateSettings took PT0.013S
Phase ValidateConfig took PT0.041S
Phase Parsing took PT1.403S
Phase Binding took PT0.005S
Phase LoadingExtensions took PT0.01S
Phase Analyzer took PT2.611S
Phase Reporting took PT0.021S
g
I’m not so sure, but I believe the problem could be related to relative paths at this point 🤔
n
ok i’ll keep poking, thanks for helping ❤️
🙏 1
130 Views