github-workflows-kt
github-workflows-kt copied to clipboard
[Core feature request] Outputs for jobs
What feature do you need? https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
Do you have an example usage? See above.
Is there a workaround for not having this feature? If yes, please describe it. It's possible to achieve it using https://krzema12.github.io/github-actions-kotlin-dsl/user-guide/compensating-librarys-missing-features/, but due to step IDs being controlled by the library, it's hard to maintain the outputs if the steps change.
Discussion: https://kotlinlang.slack.com/archives/C02UUATR7RC/p1661871851980409
i am still experimenting around with the api, but i propose such a API for registering output mappings and using them
creating references in the surrounding workflow block or such
val outputRef by JobOutputRef
// or
val outputRef = JobOutputRef("jobOutput")
registering output mappings
run(
name = "set output",
command = """echo "::set-output name=foo::bar"""",
).withOutputMapping(outputRef, "foo")
uses(SomeTaskWithOutputs())
.withOutputMapping(outputRef) { outputs -> outputs.someOutput }
using the references in a later step
// job(needs = listOf(someJob), ...) {
val outputExpression = expr { someJob.output(outputRef) }
run(
command = """echo $outputExpression""",
)
possible problems/improvements
it would also make sense to add add needs
references to the current job as outputs of a different step are used.. or at least verrifying that such relationship exists
just not sure how to do that right now without maing the API/DSL unreadable
not sure if using output references is overkill, technically plain strings will work fine (although bringing the problems of magic constants)
there is also no way to verify that a specific reference was used in another step right now
@NikkyAI see https://github.com/krzema12/github-actions-kotlin-dsl/pull/432#discussion_r959311755
took me a while to get the API close to the one you lined out and make detekt and ktlint and CI happy, but PR #432 is as ready as it can be for review
Thanks, it's in my queue for spare time :) @jmfayard do you have capacity to review?
no, sorry