Skip to content

Latest commit

 

History

History
94 lines (78 loc) · 3.65 KB

README.md

File metadata and controls

94 lines (78 loc) · 3.65 KB

Kotlin version

Kotlin DSL for Github Actions

Simple DSL to generate Github Actions YAML workflows in typesafe manner and makes it easier & simpler to build CI/CD pipelines from reusable blocks.

Usage

Include the following dependencies:

  • io.github.nefilim.githubactions:kotlin-dsl-core:<latest>
  • io.github.nefilim.githubactions:kotlin-dsl-actions:<latest>

If you wish to generate additional actions from metadata, also include:

  • io.github.nefilim.githubactions:kotlin-dsl-action-generator:<latest>

Define your workflow, example:

val wf = workflow("CI Build") {
    triggers {
        push {
            branches = listOf("main")
            pathsIgnore = listOf("**.md")
        }
        pullRequest {
            branchesIgnore = listOf("renovate/*")
            pathsIgnore = listOf("**.md")
        }
        workflowDispatch {
            inputString("deploymentFilename", "Deployment descriptor name", "deployment.yaml", false)
        }
    }
    concurrency("ci-build-${githubRef("ref")}", true)
    env {
        "NEXUS_USER" to secretRef("NEXUS_USER")
        "NEXUS_PASS" to secretRef("NEXUS_PASS")
    }
    jobs {
        "ci-build" to Job(
            runsOn = listOf("linux", "self-hosted"),
            steps = listOf(
                CheckoutAction(
                    path = "source",
                    repository = "nefilim/gradle-github-actions-generator",
                    ref = "main",
                ).toStep(Step.StepID("my-checkout"), "Checkout Source", CheckoutAction.Uses),
                GradleBuildAction(
                    buildRootDirectory = "source",
                    arguments = "clean build"
                ).toStep()
            ),
        )
    }
}

Generate the corresponding YAML using KotlinX Serialization & YAML:

    println(GitHubActionsYAML.encodeToString(Workflow.serializer(), wf))

Gradle Integration

A Gradle Plugin is also available to generate workflows right from your build definition: https://github.com/nefilim/gradle-github-actions-generator

Bundled Actions

Note: these are actions are generated and not committed to the source tree:

To add additional type safe GitHub Actions, please implement the GithubAction interface or better yet, use the code generator, an example can be seen here.

If you want to see any additional actions bundled, please open an issue or PR, given the code generator it should be quick to add additional actions.