github-workflows-kt icon indicating copy to clipboard operation
github-workflows-kt copied to clipboard

[Core feature request] Outputs for jobs

Open krzema12 opened this issue 1 year ago • 5 comments

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

krzema12 avatar Aug 31 '22 08:08 krzema12

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 avatar Aug 31 '22 08:08 NikkyAI

@NikkyAI see https://github.com/krzema12/github-actions-kotlin-dsl/pull/432#discussion_r959311755

krzema12 avatar Aug 31 '22 08:08 krzema12

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

NikkyAI avatar Sep 01 '22 13:09 NikkyAI

Thanks, it's in my queue for spare time :) @jmfayard do you have capacity to review?

krzema12 avatar Sep 01 '22 15:09 krzema12

no, sorry

jmfayard avatar Sep 01 '22 16:09 jmfayard