Skip to content

Commit daa99c0

Browse files
Vampirekrzema12
authored andcommitted
feat(abg)!: provide untyped fields always and typed ones if type available (#1585)
1 parent 42cd19f commit daa99c0

20 files changed

+1192
-174
lines changed

.github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import io.github.typesafegithub.workflows.actions.actions.Checkout_Untyped
2222
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
2323
import io.github.typesafegithub.workflows.actions.typesafegithub.AlwaysUntypedActionForTests_Untyped
2424

25-
println(Checkout_Untyped(fetchTags = "false"))
25+
println(Checkout_Untyped(fetchTags_Untyped = "false"))
2626
println(Checkout(fetchTags = false))
27-
println(AlwaysUntypedActionForTests_Untyped(foobar = "baz"))
27+
println(Checkout(fetchTags_Untyped = "false"))
28+
println(AlwaysUntypedActionForTests_Untyped(foobar_Untyped = "baz"))
2829
println(ActionsSetupGradle())
2930
println(Cache(path = listOf("some-path"), key = "some-key"))

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt

Lines changed: 245 additions & 74 deletions
Large diffs are not rendered by default.

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/InputNullability.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ package io.github.typesafegithub.workflows.actionbindinggenerator.metadata
44
* [Input.required] is in theory a required field in action's metadata, but in practice a lot of actions don't specify
55
* it. It's thus a challenge to infer nullability of inputs in the Kotlin bindings. This function tackles this task.
66
*/
7-
internal fun Input.shouldBeNonNullInBinding() = default == null && required == true
7+
internal fun Input.shouldBeRequiredInBinding() = default == null && required == true

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithAllTypesOfInputs.kt

Lines changed: 199 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,72 +29,132 @@ import kotlin.collections.toTypedArray
2929
*
3030
* [Action on GitHub](https://github.com/john-smith/action-with-all-types-of-inputs)
3131
*
32-
* @param fooBar Short description
33-
* @param bazGoo First boolean input!
32+
* @param fooBar <required> Short description
33+
* @param fooBar_Untyped <required> Short description
34+
* @param bazGoo <required> First boolean input!
35+
* @param bazGoo_Untyped <required> First boolean input!
3436
* @param binKin Boolean and nullable
35-
* @param intPint Integer
36-
* @param floPint Float
37-
* @param finBin Enumeration
38-
* @param gooZen Integer with special value
39-
* @param bahEnum Enum with custom naming
37+
* @param binKin_Untyped Boolean and nullable
38+
* @param intPint <required> Integer
39+
* @param intPint_Untyped <required> Integer
40+
* @param floPint <required> Float
41+
* @param floPint_Untyped <required> Float
42+
* @param finBin <required> Enumeration
43+
* @param finBin_Untyped <required> Enumeration
44+
* @param gooZen <required> Integer with special value
45+
* @param gooZen_Untyped <required> Integer with special value
46+
* @param bahEnum <required> Enum with custom naming
47+
* @param bahEnum_Untyped <required> Enum with custom naming
4048
* @param listStrings List of strings
49+
* @param listStrings_Untyped List of strings
4150
* @param listInts List of integers
51+
* @param listInts_Untyped List of integers
4252
* @param listEnums List of enums
53+
* @param listEnums_Untyped List of enums
4354
* @param listIntSpecial List of integer with special values
55+
* @param listIntSpecial_Untyped List of integer with special values
4456
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by
4557
* the binding
4658
* @param _customVersion Allows overriding action's version, for example to use a specific minor
4759
* version, or a newer version that the binding doesn't yet know about
4860
*/
4961
public data class ActionWithAllTypesOfInputs private constructor(
5062
/**
51-
* Short description
63+
* <required> Short description
5264
*/
53-
public val fooBar: String,
65+
public val fooBar: String? = null,
5466
/**
55-
* First boolean input!
67+
* <required> Short description
5668
*/
57-
public val bazGoo: Boolean,
69+
public val fooBar_Untyped: String? = null,
70+
/**
71+
* <required> First boolean input!
72+
*/
73+
public val bazGoo: Boolean? = null,
74+
/**
75+
* <required> First boolean input!
76+
*/
77+
public val bazGoo_Untyped: String? = null,
5878
/**
5979
* Boolean and nullable
6080
*/
6181
public val binKin: Boolean? = null,
6282
/**
63-
* Integer
83+
* Boolean and nullable
84+
*/
85+
public val binKin_Untyped: String? = null,
86+
/**
87+
* <required> Integer
88+
*/
89+
public val intPint: Int? = null,
90+
/**
91+
* <required> Integer
92+
*/
93+
public val intPint_Untyped: String? = null,
94+
/**
95+
* <required> Float
6496
*/
65-
public val intPint: Int,
97+
public val floPint: Float? = null,
6698
/**
67-
* Float
99+
* <required> Float
68100
*/
69-
public val floPint: Float,
101+
public val floPint_Untyped: String? = null,
70102
/**
71-
* Enumeration
103+
* <required> Enumeration
72104
*/
73-
public val finBin: ActionWithAllTypesOfInputs.Bin,
105+
public val finBin: ActionWithAllTypesOfInputs.Bin? = null,
74106
/**
75-
* Integer with special value
107+
* <required> Enumeration
76108
*/
77-
public val gooZen: ActionWithAllTypesOfInputs.Zen,
109+
public val finBin_Untyped: String? = null,
78110
/**
79-
* Enum with custom naming
111+
* <required> Integer with special value
80112
*/
81-
public val bahEnum: ActionWithAllTypesOfInputs.BahEnum,
113+
public val gooZen: ActionWithAllTypesOfInputs.Zen? = null,
114+
/**
115+
* <required> Integer with special value
116+
*/
117+
public val gooZen_Untyped: String? = null,
118+
/**
119+
* <required> Enum with custom naming
120+
*/
121+
public val bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
122+
/**
123+
* <required> Enum with custom naming
124+
*/
125+
public val bahEnum_Untyped: String? = null,
82126
/**
83127
* List of strings
84128
*/
85129
public val listStrings: List<String>? = null,
130+
/**
131+
* List of strings
132+
*/
133+
public val listStrings_Untyped: String? = null,
86134
/**
87135
* List of integers
88136
*/
89137
public val listInts: List<Int>? = null,
138+
/**
139+
* List of integers
140+
*/
141+
public val listInts_Untyped: String? = null,
90142
/**
91143
* List of enums
92144
*/
93145
public val listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
146+
/**
147+
* List of enums
148+
*/
149+
public val listEnums_Untyped: String? = null,
94150
/**
95151
* List of integer with special values
96152
*/
97153
public val listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
154+
/**
155+
* List of integer with special values
156+
*/
157+
public val listIntSpecial_Untyped: String? = null,
98158
/**
99159
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
100160
*/
@@ -106,43 +166,143 @@ public data class ActionWithAllTypesOfInputs private constructor(
106166
public val _customVersion: String? = null,
107167
) : RegularAction<ActionWithAllTypesOfInputs.Outputs>("john-smith",
108168
"action-with-all-types-of-inputs", _customVersion ?: "v3") {
169+
init {
170+
require(!((fooBar != null) && (fooBar_Untyped != null))) {
171+
"Only fooBar or fooBar_Untyped must be set, but not both"
172+
}
173+
require((fooBar != null) || (fooBar_Untyped != null)) {
174+
"Either fooBar or fooBar_Untyped must be set, one of them is required"
175+
}
176+
177+
require(!((bazGoo != null) && (bazGoo_Untyped != null))) {
178+
"Only bazGoo or bazGoo_Untyped must be set, but not both"
179+
}
180+
require((bazGoo != null) || (bazGoo_Untyped != null)) {
181+
"Either bazGoo or bazGoo_Untyped must be set, one of them is required"
182+
}
183+
184+
require(!((binKin != null) && (binKin_Untyped != null))) {
185+
"Only binKin or binKin_Untyped must be set, but not both"
186+
}
187+
188+
require(!((intPint != null) && (intPint_Untyped != null))) {
189+
"Only intPint or intPint_Untyped must be set, but not both"
190+
}
191+
require((intPint != null) || (intPint_Untyped != null)) {
192+
"Either intPint or intPint_Untyped must be set, one of them is required"
193+
}
194+
195+
require(!((floPint != null) && (floPint_Untyped != null))) {
196+
"Only floPint or floPint_Untyped must be set, but not both"
197+
}
198+
require((floPint != null) || (floPint_Untyped != null)) {
199+
"Either floPint or floPint_Untyped must be set, one of them is required"
200+
}
201+
202+
require(!((finBin != null) && (finBin_Untyped != null))) {
203+
"Only finBin or finBin_Untyped must be set, but not both"
204+
}
205+
require((finBin != null) || (finBin_Untyped != null)) {
206+
"Either finBin or finBin_Untyped must be set, one of them is required"
207+
}
208+
209+
require(!((gooZen != null) && (gooZen_Untyped != null))) {
210+
"Only gooZen or gooZen_Untyped must be set, but not both"
211+
}
212+
require((gooZen != null) || (gooZen_Untyped != null)) {
213+
"Either gooZen or gooZen_Untyped must be set, one of them is required"
214+
}
215+
216+
require(!((bahEnum != null) && (bahEnum_Untyped != null))) {
217+
"Only bahEnum or bahEnum_Untyped must be set, but not both"
218+
}
219+
require((bahEnum != null) || (bahEnum_Untyped != null)) {
220+
"Either bahEnum or bahEnum_Untyped must be set, one of them is required"
221+
}
222+
223+
require(!((listStrings != null) && (listStrings_Untyped != null))) {
224+
"Only listStrings or listStrings_Untyped must be set, but not both"
225+
}
226+
227+
require(!((listInts != null) && (listInts_Untyped != null))) {
228+
"Only listInts or listInts_Untyped must be set, but not both"
229+
}
230+
231+
require(!((listEnums != null) && (listEnums_Untyped != null))) {
232+
"Only listEnums or listEnums_Untyped must be set, but not both"
233+
}
234+
235+
require(!((listIntSpecial != null) && (listIntSpecial_Untyped != null))) {
236+
"Only listIntSpecial or listIntSpecial_Untyped must be set, but not both"
237+
}
238+
}
239+
109240
public constructor(
110241
vararg pleaseUseNamedArguments: Unit,
111-
fooBar: String,
112-
bazGoo: Boolean,
242+
fooBar: String? = null,
243+
fooBar_Untyped: String? = null,
244+
bazGoo: Boolean? = null,
245+
bazGoo_Untyped: String? = null,
113246
binKin: Boolean? = null,
114-
intPint: Int,
115-
floPint: Float,
116-
finBin: ActionWithAllTypesOfInputs.Bin,
117-
gooZen: ActionWithAllTypesOfInputs.Zen,
118-
bahEnum: ActionWithAllTypesOfInputs.BahEnum,
247+
binKin_Untyped: String? = null,
248+
intPint: Int? = null,
249+
intPint_Untyped: String? = null,
250+
floPint: Float? = null,
251+
floPint_Untyped: String? = null,
252+
finBin: ActionWithAllTypesOfInputs.Bin? = null,
253+
finBin_Untyped: String? = null,
254+
gooZen: ActionWithAllTypesOfInputs.Zen? = null,
255+
gooZen_Untyped: String? = null,
256+
bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
257+
bahEnum_Untyped: String? = null,
119258
listStrings: List<String>? = null,
259+
listStrings_Untyped: String? = null,
120260
listInts: List<Int>? = null,
261+
listInts_Untyped: String? = null,
121262
listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
263+
listEnums_Untyped: String? = null,
122264
listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
265+
listIntSpecial_Untyped: String? = null,
123266
_customInputs: Map<String, String> = mapOf(),
124267
_customVersion: String? = null,
125-
) : this(fooBar=fooBar, bazGoo=bazGoo, binKin=binKin, intPint=intPint, floPint=floPint,
126-
finBin=finBin, gooZen=gooZen, bahEnum=bahEnum, listStrings=listStrings,
127-
listInts=listInts, listEnums=listEnums, listIntSpecial=listIntSpecial,
128-
_customInputs=_customInputs, _customVersion=_customVersion)
268+
) : this(fooBar = fooBar, fooBar_Untyped = fooBar_Untyped, bazGoo = bazGoo, bazGoo_Untyped =
269+
bazGoo_Untyped, binKin = binKin, binKin_Untyped = binKin_Untyped, intPint = intPint,
270+
intPint_Untyped = intPint_Untyped, floPint = floPint, floPint_Untyped = floPint_Untyped,
271+
finBin = finBin, finBin_Untyped = finBin_Untyped, gooZen = gooZen, gooZen_Untyped =
272+
gooZen_Untyped, bahEnum = bahEnum, bahEnum_Untyped = bahEnum_Untyped, listStrings =
273+
listStrings, listStrings_Untyped = listStrings_Untyped, listInts = listInts,
274+
listInts_Untyped = listInts_Untyped, listEnums = listEnums, listEnums_Untyped =
275+
listEnums_Untyped, listIntSpecial = listIntSpecial, listIntSpecial_Untyped =
276+
listIntSpecial_Untyped, _customInputs = _customInputs, _customVersion = _customVersion)
129277

130278
@Suppress("SpreadOperator")
131279
override fun toYamlArguments(): LinkedHashMap<String, String> = linkedMapOf(
132280
*listOfNotNull(
133-
"foo-bar" to fooBar,
134-
"baz-goo" to bazGoo.toString(),
281+
fooBar?.let { "foo-bar" to it },
282+
fooBar_Untyped?.let { "foo-bar" to it },
283+
bazGoo?.let { "baz-goo" to it.toString() },
284+
bazGoo_Untyped?.let { "baz-goo" to it },
135285
binKin?.let { "bin-kin" to it.toString() },
136-
"int-pint" to intPint.toString(),
137-
"flo-pint" to floPint.toString(),
138-
"fin-bin" to finBin.stringValue,
139-
"goo-zen" to gooZen.integerValue.toString(),
140-
"bah-enum" to bahEnum.stringValue,
286+
binKin_Untyped?.let { "bin-kin" to it },
287+
intPint?.let { "int-pint" to it.toString() },
288+
intPint_Untyped?.let { "int-pint" to it },
289+
floPint?.let { "flo-pint" to it.toString() },
290+
floPint_Untyped?.let { "flo-pint" to it },
291+
finBin?.let { "fin-bin" to it.stringValue },
292+
finBin_Untyped?.let { "fin-bin" to it },
293+
gooZen?.let { "goo-zen" to it.integerValue.toString() },
294+
gooZen_Untyped?.let { "goo-zen" to it },
295+
bahEnum?.let { "bah-enum" to it.stringValue },
296+
bahEnum_Untyped?.let { "bah-enum" to it },
141297
listStrings?.let { "list-strings" to it.joinToString(",") },
298+
listStrings_Untyped?.let { "list-strings" to it },
142299
listInts?.let { "list-ints" to it.joinToString(",") { it.toString() } },
300+
listInts_Untyped?.let { "list-ints" to it },
143301
listEnums?.let { "list-enums" to it.joinToString(",") { it.stringValue } },
302+
listEnums_Untyped?.let { "list-enums" to it },
144303
listIntSpecial?.let { "list-int-special" to it.joinToString(",") {
145304
it.integerValue.toString() } },
305+
listIntSpecial_Untyped?.let { "list-int-special" to it },
146306
*_customInputs.toList().toTypedArray(),
147307
).toTypedArray()
148308
)

0 commit comments

Comments
 (0)