question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Custom shell" (kotlin) should allow custom file name extension (`.main.kts`)

See original GitHub issue

Describe the enhancement Actions allows to define a custom shell in worflow runs. Kotlin has support for scripting. I’ve tried to make use of Kotlin for runninng a script in Actions. The issue is that kotlin expects a file name ending in .main.kts, but the runner creates a file without extensions for “shells” that are not hardcoded in https://github.com/actions/runner/blob/a2e32170fd83851569804fa7b27d2cae235a5225/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L38

File name construction: https://github.com/actions/runner/blob/a2e32170fd83851569804fa7b27d2cae235a5225/src/Runner.Worker/Handlers/ScriptHandler.cs#L233

I would need some way to provide a map of kotlin to .main.kts to ScriptHandlerHelpers.GetScriptFileExtension()

Code Snippet

Consider this example workflow:

name: CI
on:
  push:
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - uses: fwilhe2/setup-kotlin@main
      - run: |
            #!/usr/bin/env kotlin
            println("hello")
        shell: kotlin {0}

I would expect to be able to run the given script in kotlin (the cli compiler is installed on the runner via fwilhe2/setup-kotlin).

Additional information

Result of the given workflow script:

image

This is because kotlin requires the main.kts suffix to know this should be run as a script.

Compare to running the script locally with the right or the wrong filename

~$ 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

Did I overlook something? Is this already possible? If not, I’d be glad if some option to make this would be provided, as it would make the “custom shell” feature much more interesting.

Thanks!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
fwilhe2commented, Mar 18, 2022

Thanks for the contribution and sorry once again.

No worries, I was not working on this. Looking forward to have this available 💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow running "main.kts" script that does not end in ... - YouTrack
The issue is that GiHub will let me define the program to run, but it won't let me the "extension" of the file...
Read more >
Get started with Kotlin custom scripting – tutorial
In the module's build.gradle(.kts) file, remove the version of the Kotlin Gradle plugin. It is already in the root project's build script.
Read more >
Kotlin style guide
If a source file contains only a single top-level class, the file name should reflect the case-sensitive name plus the .kt extension.
Read more >
Execute kotlin files with extension other than kt
1 Answer 1 ... Where vFile.fileType is retrieved here based on the file extension, which is declared in KotlinFileType to be kt ....
Read more >
Customization
The built-in template will be used if you haven't provided a customized template. The kotlin generator defines the suffix as simply .kt ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found