I wanted to run a script regularly and didn't really want to run it on my local machine each time. So it turns out you can run scripts regularly on GitHub Actions. What's even better is its super simple to setup. Of course there are some limits to how many minutes you can run per GitHub's billing page. Currently this is 2000 minutes.
First I created a fresh repository with one single file in it. I named that file Test.main.kts
and added the following contents:
val helloName = "Bob"
println("Hello $helloName from the kotlin script")
I commit that to my repo and then create a GitHub Action, this can be named whatever you want, mine is named main.yml
here are the contents:
name: Just a test
# configure manual trigger
on:
workflow_dispatch:
jobs:
just-a-test:
name: Run a Kotlin script
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- name: Run Kotlin script
run: kotlinc -script ./Test.main.kts
This checks out your repo onto a ubuntu runner and runs your script. Super simple and this will run whenever you manually execute it using the web control in GitHub. Of course you can schedule this if needed.
The slight complication comes when you want imports, this is where you need to balance local setup and GitHub with scripts. I have been using IntelliJ and INtelliJ with scripts don't seem to play super well yet, maybe I'm missing something. You can add imports into the script file using @file:DependsOn()
but how you get this into your project locally is still a bit confusing to me. It might be that IntelliJ doesn't really support this lightweight type of script based project yet.