Skip to content

GithubAction

The core interface that all WorkflowKt workflows must implement.

Source: core/src/main/kotlin/ir/amirroid/workflowkt/GithubAction.kt

Definition

interface GithubAction<C : ActionContext> {
    fun run(context: C, environment: GithubEnvironment): ActionResult
}

Type Parameter

Parameter Constraint Description
C ActionContext The type of event context this action handles

Method: run

Executes the action using the provided context and GitHub environment.

Parameters

Parameter Type Description
context C The typed event context derived from the GitHub event payload
environment GithubEnvironment The GitHub Actions runtime environment variables

Returns

ActionResult — either ActionResult.Success or ActionResult.Failure.

Usage

class MyAction : GithubAction<PushContext> {

    override fun run(context: PushContext, environment: GithubEnvironment): ActionResult {
        // Access typed event data
        val branch = context.ref
        val commits = context.commits

        // Access environment variables
        val sha = environment.sha
        val repo = environment.repository

        return ActionResult.Success()
    }
}

Supported Context Types

Context Type GitHub Event When It Fires
IssueContext issues Issue opened, edited, closed, etc.
PullRequestContext pull_request PR opened, synchronized, merged, etc.
PushContext push Code pushed to a branch
ReleaseContext release Release published or created
ScheduleContext schedule Cron-scheduled workflow runs
WorkflowDispatchContext workflow_dispatch Manually triggered workflow
CreateContext create Branch or tag created

Implementation Notes

  • Actions must have a no-arg constructor or be a Kotlin object
  • The framework uses reflection to instantiate and invoke actions
  • The context type is resolved at runtime from the generic type parameter
  • Actions are loaded via URLClassLoader for classpath isolation