Skip to content

Commit a485fe4

Browse files
committed
feat(abg): add binding version v2
1 parent 280e1f1 commit a485fe4

File tree

40 files changed

+2711
-609
lines changed

40 files changed

+2711
-609
lines changed

.github/workflows/bindings-server.main.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ workflow(
101101

102102
cleanMavenLocal()
103103

104+
run(
105+
name = "Execute the script using the bindings from the server with v2 route",
106+
command = """
107+
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
108+
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
109+
""".trimIndent(),
110+
)
111+
112+
cleanMavenLocal()
113+
104114
run(
105115
name = "Execute the script using bindings but without dependency on library",
106116
command = """

.github/workflows/bindings-server.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,22 @@ jobs:
6565
name: 'Clean Maven Local to fetch required POMs again'
6666
run: 'rm -rf ~/.m2/repository/'
6767
- id: 'step-9'
68+
name: 'Execute the script using the bindings from the server with v2 route'
69+
run: |-
70+
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
71+
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
72+
- id: 'step-10'
73+
name: 'Clean Maven Local to fetch required POMs again'
74+
run: 'rm -rf ~/.m2/repository/'
75+
- id: 'step-11'
6876
name: 'Execute the script using bindings but without dependency on library'
6977
run: |-
7078
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
7179
.github/workflows/test-served-bindings-depend-on-library.main.kts
72-
- id: 'step-10'
80+
- id: 'step-12'
7381
name: 'Fetch maven-metadata.xml for top-level action'
7482
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
75-
- id: 'step-11'
83+
- id: 'step-13'
7684
name: 'Fetch maven-metadata.xml for nested action'
7785
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
7886
deploy:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env kotlin
22
@file:Repository("https://repo.maven.apache.org/maven2/")
3-
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
3+
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")
44

55
@file:Repository("http://localhost:8080/v1")
66

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env kotlin
2+
@file:Repository("https://repo.maven.apache.org/maven2/")
3+
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")
4+
5+
@file:Repository("http://localhost:8080/v2")
6+
7+
// Regular, top-level action.
8+
@file:DependsOn("actions:checkout:v4")
9+
10+
// Nested action.
11+
@file:DependsOn("gradle:actions__setup-gradle:v3")
12+
13+
// Using specific version.
14+
@file:DependsOn("actions:cache:v3.3.3")
15+
16+
// Always untyped action.
17+
@file:DependsOn("typesafegithub:always-untyped-action-for-tests:v1")
18+
19+
import io.github.typesafegithub.workflows.actions.actions.Cache
20+
import io.github.typesafegithub.workflows.actions.actions.Checkout
21+
import io.github.typesafegithub.workflows.actions.actions.Checkout_Untyped
22+
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
23+
import io.github.typesafegithub.workflows.actions.typesafegithub.AlwaysUntypedActionForTests_Untyped
24+
25+
println(Checkout_Untyped(fetchTags_Untyped = "false"))
26+
println(Checkout(fetchTags = false))
27+
println(Checkout(fetchTags_Untyped = "false"))
28+
println(AlwaysUntypedActionForTests_Untyped(foobar_Untyped = "baz"))
29+
println(ActionsSetupGradle())
30+
println(Cache(path = listOf("some-path"), key = "some-key"))
31+
32+
// Ensure that 'copy(...)' method is exposed.
33+
Checkout(fetchTags = false).copy(fetchTags = true)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env kotlin
22
@file:Repository("https://repo.maven.apache.org/maven2/")
3-
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
3+
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")
44

55
@file:Repository("http://localhost:8080")
66

action-binding-generator/api/action-binding-generator.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public abstract interface class io/github/typesafegithub/workflows/actionbinding
181181

182182
public final class io/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion : java/lang/Enum {
183183
public static final field V1 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
184+
public static final field V2 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
184185
public static fun getEntries ()Lkotlin/enums/EnumEntries;
185186
public final fun getLibraryVersion ()Ljava/lang/String;
186187
public final fun isDeprecated ()Z

action-binding-generator/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies {
1616
implementation("com.charleskorn.kaml:kaml:0.61.0")
1717
implementation(projects.sharedInternal)
1818

19+
testImplementation("io.kotest:kotest-framework-datatest")
20+
testImplementation(kotlin("reflect"))
1921
testImplementation(projects.githubWorkflowsKt)
2022
}
2123

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public enum class BindingVersion(
66
public val libraryVersion: String,
77
) {
88
V1(isExperimental = false, libraryVersion = "3.0.0"),
9+
V2(libraryVersion = "3.0.0"),
910
;
1011

1112
override fun toString(): String = super.toString().lowercase()

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package io.github.typesafegithub.workflows.actionbindinggenerator
22

33
import io.github.typesafegithub.workflows.actionbindinggenerator.generation.ActionBinding
4+
import io.github.typesafegithub.workflows.actionbindinggenerator.versioning.BindingVersion
5+
import io.github.typesafegithub.workflows.domain.actions.Action
6+
import io.kotest.common.mapError
7+
import io.kotest.core.spec.style.scopes.ContainerScope
8+
import io.kotest.datatest.withData
49
import io.kotest.matchers.Matcher.Companion.failure
510
import io.kotest.matchers.shouldBe
11+
import java.lang.reflect.InvocationTargetException
612
import java.nio.file.Paths
713

814
fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
@@ -36,3 +42,68 @@ fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
3642
}
3743

3844
private fun String.removeWindowsNewLines(): String = replace("\r\n", "\n")
45+
46+
fun constructAction(
47+
owner: String,
48+
classBaseName: String,
49+
bindingVersion: BindingVersion,
50+
arguments: Map<String, Any?> = emptyMap(),
51+
): Action<*> {
52+
val constructor =
53+
Class
54+
.forName("io.github.typesafegithub.workflows.actions.$owner.${classBaseName}Binding${bindingVersion.name}")
55+
.let {
56+
@Suppress("UNCHECKED_CAST")
57+
it as Class<Action<*>>
58+
}.kotlin
59+
.constructors
60+
.first()
61+
return runCatching {
62+
constructor.callBy(
63+
arguments.mapKeys { (key, _) ->
64+
constructor.parameters.first { it.name == key }
65+
},
66+
)
67+
}.mapError {
68+
if (it is InvocationTargetException) it.targetException else it
69+
}.getOrThrow()
70+
}
71+
72+
suspend fun ContainerScope.withBindingVersions(
73+
bindingVersions: Iterable<BindingVersion>,
74+
test: suspend ContainerScope.(BindingVersion) -> Unit,
75+
) = withData(
76+
nameFn = { "binding version $it" },
77+
ts = bindingVersions,
78+
test = test,
79+
)
80+
81+
suspend fun ContainerScope.withAllBindingVersions(test: suspend ContainerScope.(BindingVersion) -> Unit) =
82+
withBindingVersions(
83+
bindingVersions = BindingVersion.entries,
84+
test = test,
85+
)
86+
87+
suspend fun ContainerScope.withBindingVersions(
88+
bindingVersions: OpenEndRange<BindingVersion>,
89+
test: suspend ContainerScope.(BindingVersion) -> Unit,
90+
) = withBindingVersions(
91+
bindingVersions = BindingVersion.entries.filter { it in bindingVersions },
92+
test = test,
93+
)
94+
95+
suspend fun ContainerScope.withBindingVersions(
96+
bindingVersions: ClosedRange<BindingVersion>,
97+
test: suspend ContainerScope.(BindingVersion) -> Unit,
98+
) = withBindingVersions(
99+
bindingVersions = BindingVersion.entries.filter { it in bindingVersions },
100+
test = test,
101+
)
102+
103+
suspend fun ContainerScope.withBindingVersionsFrom(
104+
bindingVersion: BindingVersion,
105+
test: suspend ContainerScope.(BindingVersion) -> Unit,
106+
) = withBindingVersions(
107+
bindingVersions = bindingVersion..BindingVersion.entries.last(),
108+
test = test,
109+
)
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import kotlin.collections.toTypedArray
2828
*
2929
* This is a test description that should be put in the KDoc comment for a class
3030
*
31-
* [Action on GitHub](https://github.com/john-smith/action-with-all-types-of-inputs)
31+
* [Action on GitHub](https://github.com/john-smith/action-with-all-types-of-inputs-binding-v1)
3232
*
3333
* @param fooBar &lt;required&gt; Short description
3434
* @param fooBar_Untyped &lt;required&gt; Short description
@@ -60,7 +60,7 @@ import kotlin.collections.toTypedArray
6060
* version, or a newer version that the binding doesn't yet know about
6161
*/
6262
@ExposedCopyVisibility
63-
public data class ActionWithAllTypesOfInputs private constructor(
63+
public data class ActionWithAllTypesOfInputsBindingV1 private constructor(
6464
/**
6565
* &lt;required&gt; Short description
6666
*/
@@ -104,23 +104,23 @@ public data class ActionWithAllTypesOfInputs private constructor(
104104
/**
105105
* &lt;required&gt; Enumeration
106106
*/
107-
public val finBin: ActionWithAllTypesOfInputs.Bin? = null,
107+
public val finBin: ActionWithAllTypesOfInputsBindingV1.Bin? = null,
108108
/**
109109
* &lt;required&gt; Enumeration
110110
*/
111111
public val finBin_Untyped: String? = null,
112112
/**
113113
* &lt;required&gt; Integer with special value
114114
*/
115-
public val gooZen: ActionWithAllTypesOfInputs.Zen? = null,
115+
public val gooZen: ActionWithAllTypesOfInputsBindingV1.Zen? = null,
116116
/**
117117
* &lt;required&gt; Integer with special value
118118
*/
119119
public val gooZen_Untyped: String? = null,
120120
/**
121121
* &lt;required&gt; Enum with custom naming
122122
*/
123-
public val bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
123+
public val bahEnum: ActionWithAllTypesOfInputsBindingV1.BahEnum? = null,
124124
/**
125125
* &lt;required&gt; Enum with custom naming
126126
*/
@@ -144,15 +144,15 @@ public data class ActionWithAllTypesOfInputs private constructor(
144144
/**
145145
* List of enums
146146
*/
147-
public val listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
147+
public val listEnums: List<ActionWithAllTypesOfInputsBindingV1.MyEnum>? = null,
148148
/**
149149
* List of enums
150150
*/
151151
public val listEnums_Untyped: String? = null,
152152
/**
153153
* List of integer with special values
154154
*/
155-
public val listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
155+
public val listIntSpecial: List<ActionWithAllTypesOfInputsBindingV1.MyInt>? = null,
156156
/**
157157
* List of integer with special values
158158
*/
@@ -166,8 +166,8 @@ public data class ActionWithAllTypesOfInputs private constructor(
166166
* version that the binding doesn't yet know about
167167
*/
168168
public val _customVersion: String? = null,
169-
) : RegularAction<ActionWithAllTypesOfInputs.Outputs>("john-smith",
170-
"action-with-all-types-of-inputs", _customVersion ?: "v3") {
169+
) : RegularAction<ActionWithAllTypesOfInputsBindingV1.Outputs>("john-smith",
170+
"action-with-all-types-of-inputs-binding-v1", _customVersion ?: "v3") {
171171
init {
172172
require(!((fooBar != null) && (fooBar_Untyped != null))) {
173173
"Only fooBar or fooBar_Untyped must be set, but not both"
@@ -251,19 +251,19 @@ public data class ActionWithAllTypesOfInputs private constructor(
251251
intPint_Untyped: String? = null,
252252
floPint: Float? = null,
253253
floPint_Untyped: String? = null,
254-
finBin: ActionWithAllTypesOfInputs.Bin? = null,
254+
finBin: ActionWithAllTypesOfInputsBindingV1.Bin? = null,
255255
finBin_Untyped: String? = null,
256-
gooZen: ActionWithAllTypesOfInputs.Zen? = null,
256+
gooZen: ActionWithAllTypesOfInputsBindingV1.Zen? = null,
257257
gooZen_Untyped: String? = null,
258-
bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
258+
bahEnum: ActionWithAllTypesOfInputsBindingV1.BahEnum? = null,
259259
bahEnum_Untyped: String? = null,
260260
listStrings: List<String>? = null,
261261
listStrings_Untyped: String? = null,
262262
listInts: List<Int>? = null,
263263
listInts_Untyped: String? = null,
264-
listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
264+
listEnums: List<ActionWithAllTypesOfInputsBindingV1.MyEnum>? = null,
265265
listEnums_Untyped: String? = null,
266-
listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
266+
listIntSpecial: List<ActionWithAllTypesOfInputsBindingV1.MyInt>? = null,
267267
listIntSpecial_Untyped: String? = null,
268268
_customInputs: Map<String, String> = mapOf(),
269269
_customVersion: String? = null,
@@ -314,61 +314,61 @@ public data class ActionWithAllTypesOfInputs private constructor(
314314
public sealed class Bin(
315315
public val stringValue: String,
316316
) {
317-
public object Foo : ActionWithAllTypesOfInputs.Bin("foo")
317+
public object Foo : ActionWithAllTypesOfInputsBindingV1.Bin("foo")
318318

319-
public object BooBar : ActionWithAllTypesOfInputs.Bin("boo-bar")
319+
public object BooBar : ActionWithAllTypesOfInputsBindingV1.Bin("boo-bar")
320320

321-
public object Baz123 : ActionWithAllTypesOfInputs.Bin("baz123")
321+
public object Baz123 : ActionWithAllTypesOfInputsBindingV1.Bin("baz123")
322322

323323
public class Custom(
324324
customStringValue: String,
325-
) : ActionWithAllTypesOfInputs.Bin(customStringValue)
325+
) : ActionWithAllTypesOfInputsBindingV1.Bin(customStringValue)
326326
}
327327

328328
public sealed class Zen(
329329
public val integerValue: Int,
330330
) {
331331
public class Value(
332332
requestedValue: Int,
333-
) : ActionWithAllTypesOfInputs.Zen(requestedValue)
333+
) : ActionWithAllTypesOfInputsBindingV1.Zen(requestedValue)
334334

335-
public object Special1 : ActionWithAllTypesOfInputs.Zen(3)
335+
public object Special1 : ActionWithAllTypesOfInputsBindingV1.Zen(3)
336336

337-
public object Special2 : ActionWithAllTypesOfInputs.Zen(-1)
337+
public object Special2 : ActionWithAllTypesOfInputsBindingV1.Zen(-1)
338338
}
339339

340340
public sealed class BahEnum(
341341
public val stringValue: String,
342342
) {
343-
public object HelloWorld : ActionWithAllTypesOfInputs.BahEnum("helloworld")
343+
public object HelloWorld : ActionWithAllTypesOfInputsBindingV1.BahEnum("helloworld")
344344

345345
public class Custom(
346346
customStringValue: String,
347-
) : ActionWithAllTypesOfInputs.BahEnum(customStringValue)
347+
) : ActionWithAllTypesOfInputsBindingV1.BahEnum(customStringValue)
348348
}
349349

350350
public sealed class MyEnum(
351351
public val stringValue: String,
352352
) {
353-
public object One : ActionWithAllTypesOfInputs.MyEnum("one")
353+
public object One : ActionWithAllTypesOfInputsBindingV1.MyEnum("one")
354354

355-
public object Two : ActionWithAllTypesOfInputs.MyEnum("two")
355+
public object Two : ActionWithAllTypesOfInputsBindingV1.MyEnum("two")
356356

357-
public object Three : ActionWithAllTypesOfInputs.MyEnum("three")
357+
public object Three : ActionWithAllTypesOfInputsBindingV1.MyEnum("three")
358358

359359
public class Custom(
360360
customStringValue: String,
361-
) : ActionWithAllTypesOfInputs.MyEnum(customStringValue)
361+
) : ActionWithAllTypesOfInputsBindingV1.MyEnum(customStringValue)
362362
}
363363

364364
public sealed class MyInt(
365365
public val integerValue: Int,
366366
) {
367367
public class Value(
368368
requestedValue: Int,
369-
) : ActionWithAllTypesOfInputs.MyInt(requestedValue)
369+
) : ActionWithAllTypesOfInputsBindingV1.MyInt(requestedValue)
370370

371-
public object TheAnswer : ActionWithAllTypesOfInputs.MyInt(42)
371+
public object TheAnswer : ActionWithAllTypesOfInputsBindingV1.MyInt(42)
372372
}
373373

374374
public class Outputs(

0 commit comments

Comments
 (0)