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

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

Open
fwilhe2 opened this issue Nov 19, 2020 · 6 comments
Open
Assignees
Labels
enhancement New feature or request Runner Feature Feature scope to the runner

Comments

@fwilhe2
Copy link

fwilhe2 commented Nov 19, 2020

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

internal static string GetScriptFileExtension(string scriptType)

File name construction:

var scriptFilePath = Path.Combine(tempDirectory, $"{Guid.NewGuid()}{ScriptHandlerHelpers.GetScriptFileExtension(shellCommand)}");

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!

@fwilhe2 fwilhe2 added the enhancement New feature or request label Nov 19, 2020
@fwilhe2 fwilhe2 changed the title "Custom shell" (kotlin) should allow custom file name extension (main.kts) "Custom shell" (kotlin) should allow custom file name extension (.main.kts) Nov 19, 2020
@fwilhe2
Copy link
Author

fwilhe2 commented Nov 20, 2020

So I've tried the most naive way of fixing this by adding the values to the map as shown in fwilhe2@66b9071 and used that version of the runner self hosed which shows that it works in principle:

image

I doubt this would be an acceptable solution, but I'm not sure what could be an acceptable solution. I think there would need to be another optional field something like shell_script_pattern or something.

Any comments or suggestions/ guidance on the way to a PR would be welcome.

@fwilhe2
Copy link
Author

fwilhe2 commented Nov 23, 2020

For reference: I've also created an issue for Kotlin https://youtrack.jetbrains.com/issue/KT-43534

@fwilhe2
Copy link
Author

fwilhe2 commented Jan 18, 2021

Update: Kotlin 1.4.30-RC allows to "force" running as a script, so this is a workaround:

  build:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - uses: fwilhe2/setup-kotlin@main
        with:
          version: 1.4.30-RC
      - run: |
            #!/usr/bin/env kotlin
            java.io.File(".").listFiles().forEach {it -> println(it.getName().toString())}
        shell: kotlin -howtorun .main.kts {0}

Still, it might be more elegant if this was possible:

      - run: |
            #!/usr/bin/env kotlin
            java.io.File(".").listFiles().forEach {it -> println(it.getName().toString())}
        shell: kotlin {0}
        scriptFileExtension: .main.kts

@LouisCAD
Copy link

Related to actions/runner-images#3687

@ruvceskistefan ruvceskistefan added the Runner Feature Feature scope to the runner label Mar 18, 2022
@ruvceskistefan ruvceskistefan self-assigned this Mar 18, 2022
@ruvceskistefan
Copy link
Contributor

Hi @fwilhe2,
I'm sorry, I just saw that you wanted to create PR. I somehow missed this part of the text below the picture:

I doubt this would be an acceptable solution, but I'm not sure what could be an acceptable solution. I think there would need to be another optional field something like shell_script_pattern or something.

Any comments or suggestions/ guidance on the way to a PR would be welcome.

Thanks for the contribution and sorry once again.

@fwilhe2
Copy link
Author

fwilhe2 commented 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 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Runner Feature Feature scope to the runner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants