Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probable Bug with the plugin? #9

Open
aliumujib opened this issue Nov 13, 2021 · 1 comment
Open

Probable Bug with the plugin? #9

aliumujib opened this issue Nov 13, 2021 · 1 comment

Comments

@aliumujib
Copy link

Hey there, I am trying to setup klint for Danger kotlin on my project and I've run into a slight problem 🌚 . The plugin seems to throw a number format exception because some elements in the xml output for my project don't contain a line attribute.

Here's the relevant section of github workflow:

- name: Run Android Lint
        run: ./gradlew lint

      - uses: yutailang0119/action-android-lint@v1 ## Trying this to ensure that the .xml report is actually valid
        with:
          xml_path: app/build/reports/*.xml # Support glob patterns by https://www.npmjs.com/package/@actions/glob

      - name: Run Danger
        uses: docker://ghcr.io/danger/danger-kotlin:1.0.0
        with:
          args: --failOnErrors --no-publish-check
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Here's my Dangerfile.kts:

@file:Repository("https://repo.maven.apache.org")
@file:DependsOn("org.apache.commons:commons-text:1.6")
@file:DependsOn("com.gianluz:danger-kotlin-android-lint-plugin:0.1.0")
@file:DependsOn("io.github.ackeecz:danger-kotlin-detekt:0.1.4")

import systems.danger.kotlin.*
import com.gianluz.dangerkotlin.androidlint.AndroidLint
import io.github.ackeecz.danger.detekt.DetektPlugin

import java.nio.file.Files
import java.nio.file.Paths
import java.util.function.BiPredicate
import java.util.stream.Collectors

register plugin AndroidLint
register plugin DetektPlugin

danger(args) {

    val allSourceFiles = git.modifiedFiles + git.createdFiles
    val changelogChanged = allSourceFiles.contains("CHANGELOG.md")
    val sourceChanges = allSourceFiles.firstOrNull { it.contains("src") }

    onGitHub {
        val isTrivial = pullRequest.title.contains("#trivial")

        // Changelog
        if (!isTrivial && !changelogChanged && sourceChanges != null) {
            warn("Any changes to library code should be reflected in the Changelog.\n\nPlease consider adding a note there and adhere to the [Changelog Guidelines](https://github.com/Moya/contributors/blob/master/Changelog%20Guidelines.md).")
        }

        // Big PR Check
        if ((pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0) > 300) {
            warn("Big PR, try to keep changes smaller if you can")
        }

        // Work in progress check
        if (pullRequest.title.contains("WIP", false)) {
            warn("PR is classed as Work in Progress")
        }
    }

    AndroidLint.report("app/build/reports/lint-results-debug.xml")

    val detektReports = Files.find(Paths.get(""), 10, BiPredicate { path, attributes ->
        val fileName = path.toFile().name
        fileName.endsWith("detekt.xml")
    }).map { it.toFile() }.collect(Collectors.toList())

    DetektPlugin.parseAndReport(*detektReports.toTypedArray())
}

Here's the error from Github actions:

Run docker://ghcr.io/danger/danger-kotlin:1.0.0
/usr/bin/docker run --name ghcriodangerdangerkotlin100_5b9aab --label e28490 --workdir /github/workspace --rm -e JAVA_HOME -e GITHUB_TOKEN -e INPUT_ARGS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/inflow-android/inflow-android":"/github/workspace" ghcr.io/danger/danger-kotlin:1.0.0 --failOnErrors --no-publish-check
Executing $(which danger) ci --process danger-kotlin --passURLForDSL --failOnErrors --no-publish-check - pid 1
Executing kotlinc -script-templates systems.danger.kts.DangerFileScript -cp /usr/local/lib/danger/danger-kotlin.jar -script Dangerfile.df.kts /tmp/danger-dsl.json danger_out.json - pid 26

java.lang.NumberFormatException: For input string: ""

	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:592)
	at java.lang.Integer.parseInt(Integer.java:615)
	at com.gianluz.dangerkotlin.androidlint.AndroidLint.asInt(AndroidLint.kt:148)

	at com.gianluz.dangerkotlin.androidlint.AndroidLint.report(AndroidLint.kt:99)
	at com.gianluz.dangerkotlin.androidlint.AndroidLint.report(AndroidLint.kt:76)
	at Dangerfile_df.<init>(Dangerfile.df.kts:43)
warning: some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
/usr/local/lib/danger/danger-kotlin.jar: warning: library has Kotlin runtime bundled into it
Dangerfile.df.kts:45:75: warning: parameter 'attributes' is never used, could be renamed to _
    val detektReports = Files.find(Paths.get(""), 10, BiPredicate { path, attributes ->
                                                                          ^
Uncaught Kotlin exception: kotlin.Exception: Command kotlinc -script-templates systems.danger.kts.DangerFileScript -cp /usr/local/lib/danger/danger-kotlin.jar -script Dangerfile.df.kts /tmp/danger-dsl.json danger_out.json exited with code 768

    at kfun:systems.danger.cmd.Cmd.exec#internal (0x41d751)
    at kfun:systems.danger.cmd.dangerfile.DangerFile#execute(kotlin.String;kotlin.String){} (0x41e271)
    at kfun:systems.danger.DangerKotlin#run(){} (0x41c68f)
    at kfun:#main(kotlin.Array<kotlin.String>){} (0x41b6f7)
    at Init_and_run_start (0x44c656)
    at __libc_start_main (0x7fd727beeb97)
    at  (0x405031)
    at  ((nil))

Failing the build, there is 1 fail.
Request failed [403]: https://api.github.com/user
Response: {
  "message": "Resource not accessible by integration",
  "documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"
}
Request failed [403]: https://api.github.com/user
Response: {
  "message": "Resource not accessible by integration",
  "documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"
}
Feedback: https://github.com/inflow-app/inflow-android/pull/98#issuecomment-967718498
Uncaught Kotlin exception: kotlin.Exception: Command $(which danger) ci --process danger-kotlin --passURLForDSL --failOnErrors --no-publish-check exited with code 256
    at kfun:systems.danger.cmd.Cmd.exec#internal (0x41d751)
    at kfun:systems.danger.cmd.dangerjs.DangerJS#process(systems.danger.cmd.Command;kotlin.String;kotlin.collections.List<kotlin.String>){} (0x41f2bb)
    at kfun:#main(kotlin.Array<kotlin.String>){} (0x41b95b)
    at Init_and_run_start (0x44c656)
    at __libc_start_main (0x7f90dcfa9b97)
    at  (0x405031)
    at  ((nil))

I hope the issue was descriptive enough. Any help would be appreciated. Also please point me to the video for your talk at droidcon london. I feel like I'd be able to do much more if I could just watch that talk again 😢

@DavidBrunow
Copy link

DavidBrunow commented Jul 26, 2022

I’m seeing that same issue. For me it is related to binary files, like images, that don’t have a line number in the location XML. Here is what such an issue entry looks like:

…
    <issue
        id="IconLocation"
        severity="Warning"
        message="Found bitmap drawable `res/drawable/example.webp` in densityless folder"
        category="Usability:Icons"
        priority="5"
        summary="Image defined in density-independent drawable folder"
        explanation="The res/drawable folder is intended for density-independent graphics such as shapes defined in XML. For bitmaps, move it to `drawable-mdpi` and consider providing higher and lower resolution versions in `drawable-ldpi`, `drawable-hdpi` and `drawable-xhdpi`. If the icon **really** is density independent (for example a solid color) you can place it in `drawable-nodpi`."
        url="https://developer.android.com/guide/practices/screens_support.html"
        urls="https://developer.android.com/guide/practices/screens_support.html">
        <location
            file="example/src/main/res/drawable/example.webp"/>
    </issue>
…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants