kotlin icon indicating copy to clipboard operation
kotlin copied to clipboard

Issue Setting Up Danger on Github Actions

Open aliumujib opened this issue 2 years ago • 3 comments

I'm having problems with setting up Danger kotlin on Github actions, I have no idea on what could be wrong but I think I may be missing a step in the setup process. Here's what I've done:

I have a workflow on_pr_changed.yml that is as follows:

name: Validate code

on:
  push: ## to be deleted
  pull_request:
    types: [ opened, reopened, edited, synchronize ]
    paths:
      - .github/workflows/android-lint.yml
      - '*/src/**'
      - gradle/**
      - '**.gradle'
      - gradle.properties
      - gradlew*

jobs:

  lint:
    runs-on: [ ubuntu-latest ]
    steps:
      - uses: actions/checkout@v2

      - name: Setup up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: 11
          distribution: 'temurin'

      - 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 }}

In the root directory of my project, I have a Dangerfile.df.kts:

@file:Repository("https://repo.maven.apache.org")
@file:DependsOn("org.apache.commons:commons-text:1.6")

import systems.danger.kotlin.*

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")
        }
    }
}

When I run my actions with this setup, the following error comes up in my logs:

Run docker://ghcr.io/danger/danger-kotlin:1.0.0
/usr/bin/docker run --name ghcriodangerdangerkotlin100_396447 --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 24


kotlinx.serialization.MissingFieldException: Fields [issue, pr, commits, reviews, requested_reviewers] are required for type with serial name 'systems.danger.kotlin.models.github.GitHub', but they were missing

	at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
	at systems.danger.kotlin.models.github.GitHub.<init>(GitHub.kt:13)
	at systems.danger.kotlin.models.github.GitHub$$serializer.deserialize(GitHub.kt:13)
	at systems.danger.kotlin.models.github.GitHub$$serializer.deserialize(GitHub.kt:13)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:32)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeNullableSerializableElement(AbstractDecoder.kt:79)
	at systems.danger.kotlin.models.danger.DangerDSL$$serializer.deserialize(DangerDSL.kt:14)
	at systems.danger.kotlin.models.danger.DangerDSL$$serializer.deserialize(DangerDSL.kt:14)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:32)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
	at systems.danger.kotlin.models.danger.DSL$$serializer.deserialize(DangerDSL.kt:9)
	at systems.danger.kotlin.models.danger.DSL$$serializer.deserialize(DangerDSL.kt:9)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:32)
	at kotlinx.serialization.json.Json.decodeFromString(Json.kt:95)
	at systems.danger.kotlin.MainDangerRunner.<init>(MainDangerRunner.kt:131)
	at systems.danger.kotlin.MainScriptKt.Danger(MainScript.kt:49)
	at Dangerfile_df.<init>(Dangerfile.df.kts:32)

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

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 (0x7f86460f5b97)
    at  (0x405031)
    at  ((nil))

Danger: ⅹ Failing the build, there is 1 fail.
## Failures
`danger-kotlin` failed.
## Markdowns
### Log


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 24
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 (0x7f86460f5b97)
    at  (0x405031)
    at  ((nil))

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 (0x7fc88debcb97)
    at  (0x405031)
    at  ((nil))

Any help with fixing this would be appreciated.

aliumujib avatar Nov 12 '21 19:11 aliumujib

Hey! :) I see this is running on push, that would probably explain why the needed items are missing from the GitHub response

f-meloni avatar Nov 12 '21 19:11 f-meloni

Thanks @f-meloni . It ran successfully after I deleted the push line. I am still a bit confused. I found out about danger kotlin at Droidcon London a few weeks back, and I am trying to install my first plugin. Is there some good documentation or recording of talks you can point me to?

aliumujib avatar Nov 12 '21 21:11 aliumujib

Hey @aliumujib for the plugin development you can have a look https://github.com/danger/kotlin/blob/master/docs/tutorials/plugin_development.html.md

let me know if you have any issues with that! nice to have some feedbacks!

gianluz avatar Nov 15 '21 11:11 gianluz