fwilhe
11/20/2020, 7:26 AMmain.kts
script without the filename ending in .main.kts
? My use-case is that I want to use Kotlin as a script interpreter on GitHub Actions.
So would it be possible to make the kotlin foo
line work without control of the file name? Is there some --run-as-script
flag?
~$ cat foo.main.kts
#!/usr/bin/env kotlin
println("hello")
~$ kotlin foo.main.kts
hello
~$ mv foo.main.kts foo
~$ kotlin foo
error: could not find or load main class foo
I've described details of what the issue is here https://github.com/actions/runner/issues/813Vampire
11/20/2020, 8:17 AMsetup-kotlin
action create a kotlin-script
file that renames the file to the correct naming pattern and then invokes Kotlinfwilhe
11/20/2020, 8:33 AMfwilhe
11/20/2020, 8:33 AMVampire
11/20/2020, 8:37 AMkotlin-script {0}
as configure shell.fwilhe
11/20/2020, 8:49 AMVampire
11/20/2020, 10:03 AMNikky
11/22/2020, 4:00 AM-script
option but it might have been a kotlinc
argument.. i do not have a kotlin binary at hand to testilya.chernikov
11/23/2020, 8:55 AM.kts
script without extensions provided for .main.kts
scripts.
Or you need to create your own runner - you can find almost all you need here - https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/simple-main-kts/simple-main-kts-test/src/test/kotlin/org/jetbrains/kotlin/script/examples/simpleMainKts/test/SimpleMainKtsTest.kt#L21 - just replace the script definition template parameter and add a name with required extension to the .toScriptSource()
call
In any case it seems worth to add an issue to Kotlin YouTrack with a link to the runner issue. It seems like adding such a support is not really difficult.fwilhe
11/23/2020, 3:50 PMkotlin
(as opposed to kotlinc
) would do the trick.ilya.chernikov
11/23/2020, 4:20 PMkotlin -i < scriptfile
?fwilhe
11/23/2020, 4:21 PMfwilhe
11/23/2020, 4:21 PMfwilhe
11/23/2020, 4:22 PMfwilhe
11/23/2020, 4:22 PMVampire
11/23/2020, 4:22 PMkotlin -i scriptfile
and kotlin -i <scriptfile
or kotlin -i - <scriptfile
ilya.chernikov
11/23/2020, 4:23 PMfwilhe
11/23/2020, 4:24 PMVampire
11/23/2020, 4:26 PM#!/bin/kotlin -i
and then have the script named however you like, for example /usr/local/bin/my-nifty-script-that-does-not-need-the-suffix