Code Monkey home page Code Monkey logo

kts-exec's Introduction

Kotlin Script Github Action

Version Kotlin Script Test

Kotlin can also be used as a scripting language, which is safer, concise, and fun to write than bash or python. GitHub has recently enabled Kotlin on Github Action runners, which enables us to use Kotlin Script on GitHub Action out of the box. But using compiler plugins (eg: kotlinx-serialization) is not straightforward with Kotlin script and requires a bit of fiddling. kts-exec is a composite GitHub Action to execute the Kotlin Script (on mac/linux /windows) with a given kotlin compiler plugin and dependency caching.

Inputs

script

Required The Kotlin script to execute. Default script name is script.main.kts.

compiler-plugin

Optional Kotlin compiler plugin to use. Currently, supported values are

  • kotlinx-serialization (Default)
  • allopen
  • noarg
  • lombok
  • sam-with-receiver
  • kotlin-imports-dumper

cache

Optional Enable kotlin script dependencies caching. It is enabled (true) by default.

Outputs

plugin-path

Local path to the kotlin compiler-plugin. You may also access the path via ${{ env.PLUGIN_PATH }}.

kotlin-root

The kotlin installation path. You may also access the path via ${{ env.KOTLIN_ROOT }}.

Usage

Say, you want to execute the kotlin script with a Serializable data class for JSON processing

script.main.kts
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")

import kotlinx.serialization.*
import kotlinx.serialization.json.*

@Serializable
data class Lang(val name: String, val version: String)

val arg = args.firstOrNull() ?: "Kotlin"
println("Hello $arg!")

val serialized = Json.encodeToString(Lang("Kotlin", KotlinVersion.CURRENT.toString()))
println(serialized)

Add the kt-exec to your workflow and run your kotlin script.

jobs:
  build:
    runs-on: ubuntu-lastest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Run Kotlin Script
        uses: sureshg/[email protected]
        with:
          script: "script.main.kts"

kts-exec's People

Contributors

dependabot[bot] avatar sureshg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

alexrogalskiy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.