Simple DSL to generate Github Actions YAML workflows in typesafe manner and makes it easier & simpler to build CI/CD pipelines from reusable blocks.
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))
A Gradle Plugin is also available to generate workflows right from your build definition: https://github.com/nefilim/gradle-github-actions-generator
Note: these are actions are generated and not committed to the source tree:
- CheckoutActionV3
- SetupJavaActionV3
- GradleBuildActionV2
- WrapperValidationActionV1
- SlackActionV1
- Docker
- BuildPushActionv2
- LoginActionV1
- MetadataActionV3
- SetupBuildxActionV1
- Google
- AuthActionV0
- DeployAppengineActionV0
- DeployCloudrunActionV0
- GetSecretmanagerSecretsV0
- SetupGcloudActionV0
- UploadCloudStorageActionV0
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.