I’ve been using workflows-kt for the first time an...
# github-workflows-kt
a
I’ve been using workflows-kt for the first time and I have some suggestions. I wanted to convert
Copy code
- name: Cache Kotlin Konan
        id: cache-kotlin-konan
        uses: actions/cache@v3
        with:
          path: |
            ~/.konan/**/*
          key: kotlin-konan-${{ runner.os }}
and it was pretty easy to do this.
Copy code
uses(
    name = "Cache Kotlin Konan",
    action = CacheV3(
        path = listOf(
            "~/.konan/**/*",
        ),
        key = "kotlin-konan-${expr { runner.os }}",
    ),
)
--- Having to use
listOf()
for the paths is a bit clunky, but this will be improved eventually https://youtrack.jetbrains.com/issue/KT-43871 --- I’m not a fan of the
expr {}
syntax to access the variables.
EDIT: continued in thread https://kotlinlang.slack.com/archives/C02UUATR7RC/p1685523040068749 --- Regenerating the yaml is a bit awkward. It would be nice for this to be more seamless. some ideas: • an IntelliJ plugin that will pop-up an option that I can click to re-generate the yaml • tighter integration with Gradle, so it will automatically re-gen the yaml. This could also have a task that runs on IntelliJ Gradle sync to re-gen the files • create a GitHub bot that will automatically create a code suggestion comment in a PR so I can click ‘apply’ and update the file in the web UI --- the README intro paragraph should be re-written → moved to issue https://github.com/typesafegithub/github-workflows-kt/issues/855)
j
Thanks for the feedback. A bit hard to respond to all of that but I will try
runner.os
alone would work only in the simple cases. you would be able to use incorrectly in other cases, and you wouldn’t be able to use in other cases
a
tell me which ones you’re interested in and I can make a GitHub issue/discussion for each separately :)
j
tight integration with Gradle is problematic because not everyone uses Gradle in our target users. in fact if the project becomes successfull, we may have users that usually program in typescript or python
improving the README is always a good idea, if you feel like proposing a rewrite, please open an issue
a
you’re right, tighter integration would be bad. I should rephrase that as “integration with build tools, so whether I’m using Gradle or NPM or whatever there will be a task I can run to regen the file.”
j
For a Gradle task that launch the Kotlin script, it is currently possible but surprisingly ugly. Ideally JetBrains would add support for that in the Kotlin Gradle plugin. I opened this ticket, feel free to comment and motivate them to work on it 🙂 https://youtrack.jetbrains.com/issue/KT-53707/The-Kotlin-Gradle-plugin-should-allow-to-wrap-a-Kotlin-script-inside-a-Gradle-task
_expr_ *{* "${github.repository_owner} == 'typesafegithub' || ${github.event_name} != 'schedule'" *}*
^^ here is an example of why accessing directly the variables wouldn’t work, there would be multiple
${{ }}
instead of just one. The expression makes only sense… inside an expression bloc. That’s what
expr { }
is modelling
a
ahh yes, I remember it was difficult to run a script directly, with all the dependencies. But can the .kts files be run just as a regular script though?
Copy code
val regenWorkflow by tasks.registering(Exec::class) {
    group = "workflows-kt"
    workingDir(layout.projectDirectory.dir(".github/workflows/"))
    executable("./build.main.kts")
}
Apparently I don’t have
kotlin
on my path, so it doesn’t work for me. But it should be possible to set up some Gradle magic to download it, adhoc.
alright, here’s a quickly hacked together way of regenerating the workflows on IntelliJ sync, or manually. It requires
kotlin
is installed, but it should be pretty simple to download it automatically.
actually, instead of integrating with a build tool, what about setting up a Git hook that runs a .kts that runs the workflow .kts files?
j
you can try and see if it makes sens, I personally dislike Git hooks, good idea bad experience :)
a
mmm yes, I think it could be complicated. Especially for a script that requires
kotlin
is present.
j
what about just a bash script that launches all the script, and you have an IntelliJ Run configuration that launch it?
a
plus1 that sounds like a good improvement!
v
Regarding regenning the files, foremost you should make GitHub consider https://github.com/orgs/community/discussions/15904, then manually generating the files and committing them is hopefully not necessary anymore. To actually do the regenning, you practically have at least 4 ways to do it conveniently, depending on situation and mood. If you are in a
sh
derivate like
bash
and have Kotlin installed and available in your
PATH
, you can just call the scripts like any other shellscript using:
Copy code
$ ./foo.main.kts
If you have Kotlin available somewhere (including the version that the IntelliJ plugin unpacks onto your disk in its plugins folder) you can just call it with the script as argument using:
Copy code
$ path/to/kotlin foo.main.kts
You can register a Gradle task that does the work for you and trigger it whenever you like like this which also supports `@file:Import`ed scripts: https://github.com/Vampire/setup-wsl/blob/master/gradle/build-logic/src/main/kotlin/net/kautler/github_actions.gradle.kts You can create an IntelliJ run configuration that executes the script and execute it using:
j
I have pinged GitHub’s director of product for Actions in the issue
@juliandunn now that we have clarified that we are not asking to get rid of YAML, but just for a simple mecanism to execute something like github-workflows-kt that will produce a valid YAML workflow, what do you think of the proposal?