github-workflows-kt icon indicating copy to clipboard operation
github-workflows-kt copied to clipboard

Allow running arbitrary Kotlin code

Open krzema12 opened this issue 2 years ago • 8 comments

krzema12 avatar Mar 17 '22 13:03 krzema12

See PoC at https://github.com/krzema12/github-actions-kotlin-dsl/blob/136-runKotlin-PoC/.github/workflows/script-with-server.main.kts

krzema12 avatar Mar 27 '22 13:03 krzema12

See discussion at https://kotlinlang.slack.com/archives/C02UUATR7RC/p1648387696252109?thread_ts=1648387696.252109&cid=C02UUATR7RC

krzema12 avatar Mar 27 '22 19:03 krzema12

How about

run(
    // language=kotlin
    command = """
        println("Hello from action logic! (works already)")
    """.trimIndent(),
    _customArguments = mapOf(
        "shell" to StringCustomValue("kotlin -howtorun .main.kts {0}")
    )
)

?

Vampire avatar Jun 17 '22 14:06 Vampire

@Vampire it's not ideal - no compile time verification of the Kotlin code, no syntax highlighting outside of IntelliJ. But yeah, what you showed is already something, even better if #286 is done. We could also have

runKotlin(
    // language=kotlin
    "println("Hello from action logic! (works already)")"
)

where runKotlin would have shell = "kotlin -howtorun .main.kts {0}" built-in + try to validate Kotlin code in workflow compile time. I'd go this way as first iteration and see how it works in practice.

krzema12 avatar Jun 17 '22 18:06 krzema12

Maybe runMainKts to make it clear it runs as *.main.kts and you can for example use @Depends and so on.

Vampire avatar Jun 17 '22 22:06 Vampire

Why not just running a normal kotlin script?

Le ven. 17 juin 2022 à 20:09, Piotr Krzemiński @.***> a écrit :

@Vampire https://github.com/Vampire it's not ideal - no compile time verification of the Kotlin code, no syntax highlighting outside of IntelliJ. But yeah, what you showed is already something, even better if #286 https://github.com/krzema12/github-actions-kotlin-dsl/issues/286 is done. We could also have

runKotlin( // language=kotlin "println("Hello from action logic! (works already)")" )

where runKotlin would have shell = "kotlin -howtorun .main.kts {0}" built-in + try to validate Kotlin code in workflow compile time. I'd go this way as first iteration and see how it works in practice.

— Reply to this email directly, view it on GitHub https://github.com/krzema12/github-actions-kotlin-dsl/issues/136#issuecomment-1159120301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQFSGFCDSVFMCWPAFPKI3VPS5NXANCNFSM5Q672EUA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jmfayard avatar Oct 11 '22 07:10 jmfayard

Experimenting with a much simpler approach, WIP on https://github.com/typesafegithub/github-workflows-kt/tree/136-allow-putting-Kotlin-logic-in-lambda

krzema12 avatar Dec 25 '23 18:12 krzema12

The experimental implementation is on its way, let's gather feedback. https://kotlinlang.slack.com/archives/C02UUATR7RC/p1704404385924819 https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1704465156657579?thread_ts=1704465156.657579&cid=C0BJ0GTE2

krzema12 avatar Jan 03 '24 06:01 krzema12