Skip to content

Commit 09fa7f6

Browse files
Vampirekrzema12
andauthored
feat(library): make outputs accessible for all steps (#1589)
fixes #1587 Co-authored-by: Piotr Krzemiński <3110813+krzema12@users.noreply.github.com>
1 parent 33dee38 commit 09fa7f6

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

github-workflows-kt/api/github-workflows-kt.api

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class io/github/typesafegithub/workflows/domain/AbstractResult$Stat
1818
public static fun values ()[Lio/github/typesafegithub/workflows/domain/AbstractResult$Status;
1919
}
2020

21-
public class io/github/typesafegithub/workflows/domain/ActionStep : io/github/typesafegithub/workflows/domain/Step, io/github/typesafegithub/workflows/domain/WithOutputs {
21+
public class io/github/typesafegithub/workflows/domain/ActionStep : io/github/typesafegithub/workflows/domain/Step {
2222
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lio/github/typesafegithub/workflows/domain/actions/Action;Ljava/util/Map;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Integer;Lio/github/typesafegithub/workflows/domain/actions/Action$Outputs;Ljava/util/Map;)V
2323
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Lio/github/typesafegithub/workflows/domain/actions/Action;Ljava/util/Map;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Integer;Lio/github/typesafegithub/workflows/domain/actions/Action$Outputs;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2424
public fun getAction ()Lio/github/typesafegithub/workflows/domain/actions/Action;
@@ -28,7 +28,6 @@ public class io/github/typesafegithub/workflows/domain/ActionStep : io/github/ty
2828
public fun getId ()Ljava/lang/String;
2929
public fun getName ()Ljava/lang/String;
3030
public fun getOutputs ()Lio/github/typesafegithub/workflows/domain/actions/Action$Outputs;
31-
public synthetic fun getOutputs ()Ljava/lang/Object;
3231
public fun getTimeoutMinutes ()Ljava/lang/Integer;
3332
public fun get_customArguments ()Ljava/util/Map;
3433
}
@@ -444,14 +443,15 @@ public final class io/github/typesafegithub/workflows/domain/Shell$Sh : io/githu
444443
}
445444

446445
public abstract class io/github/typesafegithub/workflows/domain/Step : io/github/typesafegithub/workflows/dsl/HasCustomArguments {
447-
public synthetic fun <init> (Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Integer;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
448-
public synthetic fun <init> (Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Integer;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
446+
public synthetic fun <init> (Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Integer;Lio/github/typesafegithub/workflows/domain/actions/Action$Outputs;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
447+
public synthetic fun <init> (Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Integer;Lio/github/typesafegithub/workflows/domain/actions/Action$Outputs;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
449448
public final fun getConclusion ()Lio/github/typesafegithub/workflows/domain/Step$Conclusion;
450449
public fun getCondition ()Ljava/lang/String;
451450
public fun getContinueOnError ()Ljava/lang/Boolean;
452451
public fun getEnv ()Ljava/util/Map;
453452
public fun getId ()Ljava/lang/String;
454453
public final fun getOutcome ()Lio/github/typesafegithub/workflows/domain/Step$Outcome;
454+
public fun getOutputs ()Lio/github/typesafegithub/workflows/domain/actions/Action$Outputs;
455455
public fun getTimeoutMinutes ()Ljava/lang/Integer;
456456
public fun get_customArguments ()Ljava/util/Map;
457457
}
@@ -480,10 +480,6 @@ public final class io/github/typesafegithub/workflows/domain/VolumeMapping {
480480
public fun toString ()Ljava/lang/String;
481481
}
482482

483-
public abstract interface class io/github/typesafegithub/workflows/domain/WithOutputs {
484-
public abstract fun getOutputs ()Ljava/lang/Object;
485-
}
486-
487483
public final class io/github/typesafegithub/workflows/domain/Workflow : io/github/typesafegithub/workflows/dsl/HasCustomArguments {
488484
public fun <init> (Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/io/File;Ljava/lang/String;Lio/github/typesafegithub/workflows/yaml/ConsistencyCheckJobConfig;Lio/github/typesafegithub/workflows/domain/Concurrency;Ljava/util/Map;Ljava/util/List;Ljava/util/Map;)V
489485
public synthetic fun <init> (Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/io/File;Ljava/lang/String;Lio/github/typesafegithub/workflows/yaml/ConsistencyCheckJobConfig;Lio/github/typesafegithub/workflows/domain/Concurrency;Ljava/util/Map;Ljava/util/List;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V

github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/domain/Job.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public data class Job<OUTPUT : JobOutputs>(
88
val id: String,
99
val name: String? = null,
1010
val runsOn: RunnerType,
11-
val steps: List<Step>,
11+
val steps: List<Step<*>>,
1212
val needs: List<Job<*>> = emptyList(),
1313
val outputs: OUTPUT,
1414
val env: Map<String, String> = mapOf(),

github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/domain/Step.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import io.github.typesafegithub.workflows.domain.contexts.Contexts
66
import io.github.typesafegithub.workflows.dsl.HasCustomArguments
77
import kotlinx.serialization.Contextual
88

9-
public sealed class Step(
9+
@Suppress("LongParameterList")
10+
public sealed class Step<out OUTPUTS : Outputs>(
1011
public open val id: String,
1112
public open val env: Map<String, String> = mapOf(),
1213
public open val condition: String? = null,
1314
public open val continueOnError: Boolean? = null,
1415
public open val timeoutMinutes: Int? = null,
16+
public open val outputs: OUTPUTS,
1517
override val _customArguments: Map<String, @Contextual Any?> = emptyMap(),
1618
) : HasCustomArguments {
1719
public inner class Conclusion : AbstractResult("steps.$id.conclusion")
@@ -22,10 +24,6 @@ public sealed class Step(
2224
public val outcome: Outcome get() = Outcome()
2325
}
2426

25-
public interface WithOutputs<out T> {
26-
public val outputs: T
27-
}
28-
2927
public data class CommandStep(
3028
override val id: String,
3129
val name: String? = null,
@@ -37,12 +35,13 @@ public data class CommandStep(
3735
val shell: Shell? = null,
3836
val workingDirectory: String? = null,
3937
override val _customArguments: Map<String, @Contextual Any?> = emptyMap(),
40-
) : Step(
38+
) : Step<Outputs>(
4139
id = id,
4240
condition = condition,
4341
continueOnError = continueOnError,
4442
timeoutMinutes = timeoutMinutes,
4543
env = env,
44+
outputs = Outputs(id),
4645
_customArguments = _customArguments,
4746
)
4847

@@ -58,12 +57,13 @@ public data class KotlinLogicStep(
5857
val workingDirectory: String? = null,
5958
override val _customArguments: Map<String, @Contextual Any?> = emptyMap(),
6059
val logic: Contexts.() -> Unit,
61-
) : Step(
60+
) : Step<Outputs>(
6261
id = id,
6362
condition = condition,
6463
continueOnError = continueOnError,
6564
timeoutMinutes = timeoutMinutes,
6665
env = env,
66+
outputs = Outputs(id),
6767
_customArguments = _customArguments,
6868
)
6969

@@ -78,12 +78,12 @@ public open class ActionStep<out OUTPUTS : Outputs>(
7878
override val timeoutMinutes: Int? = null,
7979
override val outputs: OUTPUTS,
8080
override val _customArguments: Map<String, @Contextual Any?> = emptyMap(),
81-
) : Step(
81+
) : Step<OUTPUTS>(
8282
id = id,
8383
condition = condition,
8484
continueOnError = continueOnError,
8585
timeoutMinutes = timeoutMinutes,
8686
env = env,
87+
outputs = outputs,
8788
_customArguments = _customArguments,
88-
),
89-
WithOutputs<OUTPUTS>
89+
)

github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/StepsToYaml.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import io.github.typesafegithub.workflows.domain.Shell.Python
1313
import io.github.typesafegithub.workflows.domain.Shell.Sh
1414
import io.github.typesafegithub.workflows.domain.Step
1515

16-
internal fun List<Step>.stepsToYaml(): List<Map<String, Any?>> = this.map { it.toYaml() }
16+
internal fun List<Step<*>>.stepsToYaml(): List<Map<String, Any?>> = this.map { it.toYaml() }
1717

18-
private fun Step.toYaml() =
18+
private fun Step<*>.toYaml() =
1919
when (this) {
2020
is ActionStep<*> -> toYaml()
2121
is CommandStep -> toYaml()

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/domain/StepTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import io.kotest.matchers.shouldBe
99
class StepTest :
1010
FunSpec({
1111
test("step.outcome") {
12-
val step0: Step = CommandStep(id = "step-0", command = "ls")
12+
val step0: Step<*> = CommandStep(id = "step-0", command = "ls")
1313
step0.outcome.toString() shouldBe "steps.step-0.outcome"
1414
step0.outcome eq Status.Failure shouldBe "steps.step-0.outcome == 'failure'"
1515
step0.outcome eq Status.Cancelled shouldBe "steps.step-0.outcome == 'cancelled'"
1616
step0.outcome eq Status.Skipped shouldBe "steps.step-0.outcome == 'skipped'"
1717
step0.outcome eq Status.Success shouldBe "steps.step-0.outcome == 'success'"
1818
}
1919
test("step.conclusion") {
20-
val someStep: Step =
20+
val someStep: Step<*> =
2121
ActionStep(
2222
id = "whatever",
2323
action = Checkout(),
@@ -29,4 +29,8 @@ class StepTest :
2929
someStep.conclusion eq Status.Skipped shouldBe "steps.whatever.conclusion == 'skipped'"
3030
someStep.conclusion eq Status.Success shouldBe "steps.whatever.conclusion == 'success'"
3131
}
32+
test("step.outputs") {
33+
val step0: Step<*> = CommandStep(id = "step-0", command = "ls")
34+
step0.outputs["foo"] shouldBe "steps.step-0.outputs.foo"
35+
}
3236
})

0 commit comments

Comments
 (0)