Skip to content

Registering Actions

Actions must be registered in your Gradle build file before they can be executed.

Basic Registration

In your module's build.gradle.kts:

plugins {
    alias(libs.plugins.kotlin.jvm)
    alias(libs.plugins.workflowkt)
}

dependencies {
    implementation(project(":core"))
}

workflowkt {
    registerAction(
        key = "my_action",
        implementationClass = "com.example.MyAction"
    )
}

Parameters

Parameter Type Description
key String Unique identifier used with --key parameter
implementationClass String Fully qualified class name of the GithubAction implementation

Multiple Actions

Register multiple actions in a single workflowkt block:

workflowkt {
    registerAction(
        key = "validate_commits",
        implementationClass = "com.example.ValidateCommitsAction"
    )
    registerAction(
        key = "auto_label",
        implementationClass = "com.example.AutoLabelAction"
    )
    registerAction(
        key = "code_quality",
        implementationClass = "com.example.CodeQualityAction"
    )
    registerAction(
        key = "notify_release",
        implementationClass = "com.example.NotifyOnReleaseAction"
    )
}

Validation Rules

The registration enforces the following constraints:

  • Key must not be blank — empty or whitespace-only keys throw IllegalArgumentException
  • Implementation class must not be blank — empty class names throw IllegalArgumentException
  • Keys must be unique — duplicate keys throw IllegalArgumentException with a message indicating the existing class
// This will throw:
workflowkt {
    registerAction("hello", "com.example.Action1")
    registerAction("hello", "com.example.Action2")  // Error: key already registered
}

Example from the Sample Module

The sample module registers seven actions:

// sample/build.gradle.kts
workflowkt {
    registerAction("print_helloworld", "ir.amirroid.workflowkt.samples.PrintHelloWorldGithubAction")
    registerAction("auto_label", "ir.amirroid.workflowkt.samples.AutoLabelIssueAction")
    registerAction("code_quality", "ir.amirroid.workflowkt.samples.CodeQualityCheckAction")
    registerAction("validate_commits", "ir.amirroid.workflowkt.samples.ValidateCommitsAction")
    registerAction("notify_create", "ir.amirroid.workflowkt.samples.NotifyOnCreateAction")
    registerAction("notify_release", "ir.amirroid.workflowkt.samples.NotifyOnReleaseAction")
    registerAction("run_tests", "ir.amirroid.workflowkt.samples.RunTestsAndNotifyWithEmail")
}