Replies: 8 comments 2 replies
-
Hi Ben! I'm not quite sure I understand what you're trying to achieve. Could you elaborate, perhaps include some pseudocode of what you'd like to do? In general, the main way of using this library doesn't deal with build system, one can even use it outside of the JVM world. As helper questions: is what you want to do possible with Gradle or public repositories? |
Beta Was this translation helpful? Give feedback.
-
I want to template everything. I have different kinds of workflows (library, Microservices, lambda, infrastructure, ...). In my case, all workflows use the same programming language (kotlin) and therefore have some steps in common. I want to define now in a private library (private github maven package) steps. E.g. a default lambda deployment: @file:DependsOn("it.krzeminski:github-actions-kotlin-dsl:0.29.0")
@file:Repository("https://maven.pkg.github.com/my-company/github-actions-library") // needs credentials
@file:DependsOn("my.company:github-actions-library:1.0.0")
import my.company.github-actions-library.workflows.KotlinLambdaDeployWorkflow
...
KotlinLambdaDeployWorkflow(name = "foobar-lambda").writeToFile() a custom deployment: @file:DependsOn("it.krzeminski:github-actions-kotlin-dsl:0.29.0")
@file:Repository("https://maven.pkg.github.com/my-company/github-actions-library") // needs credentials
@file:DependsOn("my.company:github-actions-library:1.0.0")
import my.company.github-actions-library.jobs.KotlinTestJob
import my.company.github-actions-library.steps.KotlinBuildStep
...
workflow(
name = "build",
on = listOf(
Push(branches = listOf("main")),
PullRequest(),
),
sourceFile = __FILE__.toPath(),
) {
KotlinTestJob()
// basically how KotlinTestJob() could look like
job(id = "build", runsOn = UbuntuLatest) {
KotlinBuildStep()
KotlinTestStep()
}
job(id = "deploy-dev", runsOn = UbuntuLatest) {
TerraformDeploy(stage = "dev")
}
job(id = "deploy-live", runsOn = UbuntuLatest) {
TerraformDeploy(stage = "live")
}
}.writeToFile() |
Beta Was this translation helpful? Give feedback.
-
Ok, I think I understand what you want to do, but I don't understand what the problematic part is. Is it about authentication with your private Maven repo from a Kotlin script, as your inline comment says? |
Beta Was this translation helpful? Give feedback.
-
Yes, I didn't used kotlin script before and I'm unable to authenticate to the repo. Or in general, how would I extend your DSL? |
Beta Was this translation helpful? Give feedback.
-
How would I extend your library? I tried the following: import it.krzeminski.githubactions.actions.actions.CheckoutV3
import it.krzeminski.githubactions.domain.ExternalActionStep
import it.krzeminski.githubactions.domain.Job
import it.krzeminski.githubactions.domain.JobOutputs
import it.krzeminski.githubactions.domain.RunnerType
import it.krzeminski.githubactions.domain.triggers.Push
import it.krzeminski.githubactions.dsl.workflow
import it.krzeminski.githubactions.yaml.toYaml
import java.nio.file.Path
import java.nio.file.Paths
fun kotlinLambdaBuildWorkflow(sourceFile: Path) = workflow(
name = "Test workflow",
on = listOf(Push()),
sourceFile = sourceFile,
) {
job(id = "test_job", runsOn = RunnerType.UbuntuLatest) {
uses(name = "Check out", action = CheckoutV3())
checkoutStep()
run(name = "Print greeting", command = "echo 'Hello world!'")
}
kotlinCheckJob()
}
fun checkoutStep() = ExternalActionStep(
id = "checkout",
action = CheckoutV3(fetchDepth = CheckoutV3.FetchDepth.Value(0)),
)
fun kotlinCheckJob() = Job(
id = "check",
runsOn = RunnerType.UbuntuLatest,
steps = listOf(),
outputs = JobOutputs.EMPTY,
)
fun main(args: Array<String>) {
val sourceFile = Paths.get("").toAbsolutePath()
val workflow = kotlinLambdaBuildWorkflow(sourceFile = sourceFile)
println(workflow.toYaml(addConsistencyCheck = false))
} |
Beta Was this translation helpful? Give feedback.
-
We have two problems here:
|
Beta Was this translation helpful? Give feedback.
-
I have now this import it.krzeminski.githubactions.actions.actions.CheckoutV3
import it.krzeminski.githubactions.domain.JobOutputs
import it.krzeminski.githubactions.domain.RunnerType
import it.krzeminski.githubactions.domain.triggers.Push
import it.krzeminski.githubactions.dsl.JobBuilder
import it.krzeminski.githubactions.dsl.WorkflowBuilder
import it.krzeminski.githubactions.dsl.workflow
import it.krzeminski.githubactions.yaml.toYaml
import java.nio.file.Path
import java.nio.file.Paths
fun kotlinLambdaBuildWorkflow(sourceFile: Path) = workflow(
name = "Test workflow",
on = listOf(Push()),
sourceFile = sourceFile,
) {
kotlinCheckJob("check-1", "world")
kotlinCheckJob("check-2", "mars")
}
fun WorkflowBuilder.kotlinCheckJob(id: String = "check", text: String) {
job(id = id, runsOn = RunnerType.UbuntuLatest) {
checkoutStep()
helloStep(text)
}
}
fun JobBuilder<*>.checkoutStep() {
uses(action = CheckoutV3(fetchDepth = CheckoutV3.FetchDepth.Value(0)))
}
fun JobBuilder<*>.helloStep(text: String) {
run(name = "Print greeting", command = "echo 'Hello $text!'")
}
fun main(args: Array<String>) {
val sourceFile = Paths.get("").toAbsolutePath()
val workflow = kotlinLambdaBuildWorkflow(sourceFile = sourceFile)
println(workflow.toYaml(addConsistencyCheck = false))
} I have the feeling that it will get messy if I have a lot of extensions. Imagine 15 steps per technology and and platform (kotlin-lambda, rust-lambd, kotlin-ec2, rust-ec2, ...). Can I compose everything without the DSL? |
Beta Was this translation helpful? Give feedback.
-
@benkeil do you still need some help with using the private Maven repo? Could you share for future reference what code worked for you? If some answer did the job, please "Mark as answer". |
Beta Was this translation helpful? Give feedback.
-
Does someone has an example how to include a library with inside a private maven repository?
I want to add common tasks/actions I need for my workflows in a library.
Beta Was this translation helpful? Give feedback.
All reactions