Replies: 6 comments 10 replies
-
Yes please! GitHub actions is an incredibly useful service, but it's being hold back by the poor developer experience of writing YAML workflows. We need something like a typescript compiler well integrated in the IDE that outputs JavaScript, which is what libraries like And if GitHub makes the small step proposed by krzema12, we can imagine similar libraries popping up in other modern programming languages. |
Beta Was this translation helpful? Give feedback.
-
Friendly ping - dear GitHub, is it something you would be interested to introduce? |
Beta Was this translation helpful? Give feedback.
-
Hey there, to provide some more feedback from the Actions team, this is a really cool idea, and appreciate the hard work and thought that went into this! Just to set expectations, we do not have plans to implement this request at this time. It is unlikely we will work on this in the next year. Support for DSL is not on the priority list right now unfortunately. |
Beta Was this translation helpful? Give feedback.
-
CircleCI has a feature that lets one achieve something close to what is described in this thread. It's called dynamic configuration: https://circleci.com/docs/dynamic-config/. It still requires some YAML to be present, but then it can generate an arbitrary YAML on the fly and say "this is the actual pipeline" by using a feature called pipeline continuation. Pretty powerful. |
Beta Was this translation helpful? Give feedback.
-
Problem statement
Currently the only way of defining a workflow is using YAML. It has its drawbacks: lack of typing, no way to extract a common piece of logic, no way to programatically generate a workflow, indent-sensitivity, no auto-complete regarding e.g. actions' inputs, and more. While it works fine with simple workflows, it becomes unmaintainable with more complex ones.
To address it, I came up with an idea to use a general-purpose language to describe the workflows. To leverage the current Actions' API, it could be anything that can produce a YAML. I'm the creator and co-maintainer of GitHub Actions Kotlin DSL library (repo, docs). It works by having Kotlin scripts using the DSL to generate the YAML, and during job runtime the script and the YAML are compared to ensure they are in sync. An example workflow looks like this:
(source: https://github.com/krzema12/github-actions-kotlin-dsl/blob/fa02380f2b3c7a684ff52831a75f7fabf92284c1/.github/workflows/check-if-wrappers-up-to-date.main.kts)
The DSL library generates the following YAML:
(source: https://github.com/krzema12/github-actions-kotlin-dsl/blob/fa02380f2b3c7a684ff52831a75f7fabf92284c1/.github/workflows/check-if-wrappers-up-to-date.yaml)
It does fix several issues that one can experience with YAML, but it's not comfortable to integrate with GitHub. Having to maintain both Kotlin scripts and YAMLs introduces friction and complicates the library. It's like one would have to maintain both an application written in Java and the resulting bytecode next to it.
Analogical DSLs could exist in Python, Ruby, JS/TS or whatever language one can think of and find most comfortable. The possibilities this approach opens finally bring fun and flexibility into creating the workflows. Compare it with e.g. Jenkins which adopted Groovy as their pipelines description language.
Proposed approach
From the users' perspective, they wouldn't probably want to be aware there's some YAML under the hood. That's why, to enable GitHub detect scripts that are workflow generators, GitHub could look at
.workflow.
part in the name, plus the fact that the file is executable. If the conditions are met, treat it as a workflow generator i.e. an executable file that produces the YAML to the standard output:Now there's a question when the workflow generator script should be executed to produce the YAML. I propose having a separate job created implicitly by GitHub that other jobs would depend on. Regarding workers usage quota, it would count as any other job ran by the user. The job would print out the resulting YAML for debugging purposes:
An alternative approach would be to have a single entry point for generating YAMLs, e.g.
.github/workflows/init.sh
, where the users could produce the YAMLs to files:The advantage is that there's no convention on the naming of individual workflow files (
.workflow.
inside is not necessary), which can be understood as a good or bad thing. The exact API here would also depend on when the workflows are now accessed by GitHub, e.g. to evaluate the triggers.The bottom line is that such generic API makes it very easy to use virtually any programming language - even if not a full-fledged DSL, then a simple script that would e.g. generate repeated piece of YAML. The API is backward-compatible as the standard YAMLs would still be supported.
Please let me know what you think, and what could be a feasible solution from your point of view.
Beta Was this translation helpful? Give feedback.
All reactions