Skip to content

Commit c23c6a1

Browse files
authored
fix(library): do not emit WorkflowCall outputs and secrets if none set (#1791)
A follow-up after #1788.
1 parent 3e6fd5a commit c23c6a1

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import kotlinx.serialization.Serializable
1010
@Serializable
1111
public data class WorkflowCall(
1212
val inputs: Map<String, Input> = emptyMap(),
13-
val outputs: Map<String, Output> = emptyMap(),
14-
val secrets: Map<String, Secret> = emptyMap(),
13+
val outputs: Map<String, Output>? = null,
14+
val secrets: Map<String, Secret>? = null,
1515
override val _customArguments: Map<String, @Contextual Any> = mapOf(),
1616
) : Trigger() {
1717
@Serializable

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ private fun WorkflowCall.toAdditionalYaml(): Map<String, Any?> =
172172
when {
173173
inputs.isEmpty() -> emptyMap()
174174
else ->
175-
mapOf(
175+
mapOfNotNullValues(
176176
"inputs" to inputs.mapValues { (_, value) -> value.toYaml() },
177-
"outputs" to outputs.mapValues { (_, value) -> value.toYaml() },
178-
"secrets" to secrets.mapValues { (_, value) -> value.toYaml() },
177+
"outputs" to outputs?.mapValues { (_, value) -> value.toYaml() },
178+
"secrets" to secrets?.mapValues { (_, value) -> value.toYaml() },
179179
)
180180
}
181181

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/yaml/TriggersToYamlTest.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,44 @@ class TriggersToYamlTest :
153153
)
154154
}
155155

156+
it("renders with just inputs") {
157+
// given
158+
val triggers =
159+
listOf(
160+
WorkflowCall(
161+
inputs =
162+
mapOf(
163+
"tags" to
164+
WorkflowCall.Input(
165+
description = "Test scenario tags",
166+
type = WorkflowCall.Type.Boolean,
167+
required = false,
168+
),
169+
),
170+
),
171+
)
172+
173+
// when
174+
val yaml = triggers.triggersToYaml()
175+
176+
// then
177+
yaml shouldBe
178+
mapOf(
179+
"workflow_call" to
180+
mapOf(
181+
"inputs" to
182+
mapOf(
183+
"tags" to
184+
mapOf(
185+
"description" to "Test scenario tags",
186+
"type" to "boolean",
187+
"required" to false,
188+
),
189+
),
190+
),
191+
)
192+
}
193+
156194
it("renders with all parameters") {
157195
// given
158196
val triggers =

0 commit comments

Comments
 (0)