jgo
jgo copied to clipboard
ktlint fails only on CI
When run locally the following works fine
jgo --add-opens java.base/java.lang=ALL-UNNAMED com.pinterest:ktlint --reporter=plain
When run in CI, I get
jgo.jgo.NoMainClassInManifest: /home/runner/.jgo/com.pinterest/ktlint/RELEASE/dc805df1f601e0abeb970faac1d7e1477254f7f5cc64b42aa88b1d0434ca8dc2/ktlint-reporter-sarif-0.48.2.jar manifest does not specify Main-Class
I dont see anything in https://repo1.maven.org/maven2/com/pinterest/ktlint/0.48.2/ktlint-0.48.2.pom which looks for envvar "CI" to similar to voodoo say it should use "ktlint-reporter-sarif", so I am confused as to how jgo can fail here.
I've found the problem.
https://mvnrepository.com/artifact/com.pinterest/ktlint ends up downloading the following files into the workspace
annotations-13.0.jar kotlin-script-runtime-1.9.10.jar ktlint-cli-reporter-baseline-1.0.0.jar ktlint-cli-reporter-sarif-1.0.0.jar mainClass
buildSuccess kotlin-stdlib-1.9.10.jar ktlint-cli-reporter-checkstyle-1.0.0.jar ktlint-cli-ruleset-core-1.0.0.jar picocli-4.7.5.jar
coordinates.txt kotlin-stdlib-common-1.9.0.jar ktlint-cli-reporter-core-1.0.0.jar ktlint-logger-1.0.0.jar poko-annotations-jvm-0.15.0.jar
ec4j-core-0.3.0.jar kotlin-stdlib-jdk7-1.9.10.jar ktlint-cli-reporter-format-1.0.0.jar ktlint-rule-engine-1.0.0.jar pom.xml
kotlin-compiler-embeddable-1.9.10.jar kotlin-stdlib-jdk8-1.9.10.jar ktlint-cli-reporter-html-1.0.0.jar ktlint-rule-engine-core-1.0.0.jar sarif4k-jvm-0.4.0.jar
kotlin-daemon-embeddable-1.9.10.jar kotlinx-serialization-core-jvm-1.4.1.jar ktlint-cli-reporter-json-1.0.0.jar ktlint-ruleset-standard-1.0.0.jar slf4j-api-2.0.4.jar
kotlin-logging-jvm-5.1.0.jar kotlinx-serialization-json-jvm-1.4.1.jar ktlint-cli-reporter-plain-1.0.0.jar logback-classic-1.3.5.jar trove4j-1.0.20200330.jar
kotlin-reflect-1.6.10.jar ktlint-cli-1.0.0.jar ktlint-cli-reporter-plain-summary-1.0.0.jar logback-core-1.3.5.jar
Then jgo tries to resolve the primary_endpoint.jar_name() which is ktlint-RELEASE.jar, so the glob becomes ktlint-*.jar and then it picks the first file that the glob returns.
The line where this becomes unpredictable is https://github.com/scijava/jgo/blob/fcaf307/src/jgo/jgo.py#L829
On my machine, the first entry in the glob result is always ktlint-cli-1.0.0.jar, but on CI the first result is always something else - currently it is ktlint-ruleset-standard-1.0.0.jar.
glob.glob uses https://docs.python.org/3/library/os.html#os.scandir , which returns files in arbitrary order. So picking the first one is non-deterministic.
The same occurs for https://mvnrepository.com/artifact/com.pinterest.ktlint/ktlint-cli , because again ktlint-cli-*.jar matches other files, in my case ktlint-cli-reporter-sarif-1.1.0.jar