Skip to content

Commit 1f9acc7

Browse files
committed
feat(abg): add binding version v2
1 parent 51faec4 commit 1f9acc7

File tree

40 files changed

+2620
-599
lines changed

40 files changed

+2620
-599
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
@@ -17,6 +17,8 @@ dependencies {
1717
implementation("com.charleskorn.kaml:kaml:0.61.0")
1818
implementation(projects.sharedInternal)
1919

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

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.1"),
9+
V2(libraryVersion = "3.0.1"),
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: 28 additions & 28 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
@@ -58,7 +58,7 @@ import kotlin.collections.toTypedArray
5858
* @param _customVersion Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
5959
*/
6060
@ExposedCopyVisibility
61-
public data class ActionWithAllTypesOfInputs private constructor(
61+
public data class ActionWithAllTypesOfInputsBindingV1 private constructor(
6262
/**
6363
* &lt;required&gt; Short description
6464
*/
@@ -102,23 +102,23 @@ public data class ActionWithAllTypesOfInputs private constructor(
102102
/**
103103
* &lt;required&gt; Enumeration
104104
*/
105-
public val finBin: ActionWithAllTypesOfInputs.Bin? = null,
105+
public val finBin: ActionWithAllTypesOfInputsBindingV1.Bin? = null,
106106
/**
107107
* &lt;required&gt; Enumeration
108108
*/
109109
public val finBin_Untyped: String? = null,
110110
/**
111111
* &lt;required&gt; Integer with special value
112112
*/
113-
public val gooZen: ActionWithAllTypesOfInputs.Zen? = null,
113+
public val gooZen: ActionWithAllTypesOfInputsBindingV1.Zen? = null,
114114
/**
115115
* &lt;required&gt; Integer with special value
116116
*/
117117
public val gooZen_Untyped: String? = null,
118118
/**
119119
* &lt;required&gt; Enum with custom naming
120120
*/
121-
public val bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
121+
public val bahEnum: ActionWithAllTypesOfInputsBindingV1.BahEnum? = null,
122122
/**
123123
* &lt;required&gt; Enum with custom naming
124124
*/
@@ -142,15 +142,15 @@ public data class ActionWithAllTypesOfInputs private constructor(
142142
/**
143143
* List of enums
144144
*/
145-
public val listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
145+
public val listEnums: List<ActionWithAllTypesOfInputsBindingV1.MyEnum>? = null,
146146
/**
147147
* List of enums
148148
*/
149149
public val listEnums_Untyped: String? = null,
150150
/**
151151
* List of integer with special values
152152
*/
153-
public val listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
153+
public val listIntSpecial: List<ActionWithAllTypesOfInputsBindingV1.MyInt>? = null,
154154
/**
155155
* List of integer with special values
156156
*/
@@ -163,7 +163,7 @@ public data class ActionWithAllTypesOfInputs private constructor(
163163
* Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
164164
*/
165165
public val _customVersion: String? = null,
166-
) : RegularAction<ActionWithAllTypesOfInputs.Outputs>("john-smith", "action-with-all-types-of-inputs", _customVersion ?: "v3") {
166+
) : RegularAction<ActionWithAllTypesOfInputsBindingV1.Outputs>("john-smith", "action-with-all-types-of-inputs-binding-v1", _customVersion ?: "v3") {
167167
init {
168168
require(!((fooBar != null) && (fooBar_Untyped != null))) {
169169
"Only fooBar or fooBar_Untyped must be set, but not both"
@@ -247,19 +247,19 @@ public data class ActionWithAllTypesOfInputs private constructor(
247247
intPint_Untyped: String? = null,
248248
floPint: Float? = null,
249249
floPint_Untyped: String? = null,
250-
finBin: ActionWithAllTypesOfInputs.Bin? = null,
250+
finBin: ActionWithAllTypesOfInputsBindingV1.Bin? = null,
251251
finBin_Untyped: String? = null,
252-
gooZen: ActionWithAllTypesOfInputs.Zen? = null,
252+
gooZen: ActionWithAllTypesOfInputsBindingV1.Zen? = null,
253253
gooZen_Untyped: String? = null,
254-
bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
254+
bahEnum: ActionWithAllTypesOfInputsBindingV1.BahEnum? = null,
255255
bahEnum_Untyped: String? = null,
256256
listStrings: List<String>? = null,
257257
listStrings_Untyped: String? = null,
258258
listInts: List<Int>? = null,
259259
listInts_Untyped: String? = null,
260-
listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
260+
listEnums: List<ActionWithAllTypesOfInputsBindingV1.MyEnum>? = null,
261261
listEnums_Untyped: String? = null,
262-
listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
262+
listIntSpecial: List<ActionWithAllTypesOfInputsBindingV1.MyInt>? = null,
263263
listIntSpecial_Untyped: String? = null,
264264
_customInputs: Map<String, String> = mapOf(),
265265
_customVersion: String? = null,
@@ -301,61 +301,61 @@ public data class ActionWithAllTypesOfInputs private constructor(
301301
public sealed class Bin(
302302
public val stringValue: String,
303303
) {
304-
public object Foo : ActionWithAllTypesOfInputs.Bin("foo")
304+
public object Foo : ActionWithAllTypesOfInputsBindingV1.Bin("foo")
305305

306-
public object BooBar : ActionWithAllTypesOfInputs.Bin("boo-bar")
306+
public object BooBar : ActionWithAllTypesOfInputsBindingV1.Bin("boo-bar")
307307

308-
public object Baz123 : ActionWithAllTypesOfInputs.Bin("baz123")
308+
public object Baz123 : ActionWithAllTypesOfInputsBindingV1.Bin("baz123")
309309

310310
public class Custom(
311311
customStringValue: String,
312-
) : ActionWithAllTypesOfInputs.Bin(customStringValue)
312+
) : ActionWithAllTypesOfInputsBindingV1.Bin(customStringValue)
313313
}
314314

315315
public sealed class Zen(
316316
public val integerValue: Int,
317317
) {
318318
public class Value(
319319
requestedValue: Int,
320-
) : ActionWithAllTypesOfInputs.Zen(requestedValue)
320+
) : ActionWithAllTypesOfInputsBindingV1.Zen(requestedValue)
321321

322-
public object Special1 : ActionWithAllTypesOfInputs.Zen(3)
322+
public object Special1 : ActionWithAllTypesOfInputsBindingV1.Zen(3)
323323

324-
public object Special2 : ActionWithAllTypesOfInputs.Zen(-1)
324+
public object Special2 : ActionWithAllTypesOfInputsBindingV1.Zen(-1)
325325
}
326326

327327
public sealed class BahEnum(
328328
public val stringValue: String,
329329
) {
330-
public object HelloWorld : ActionWithAllTypesOfInputs.BahEnum("helloworld")
330+
public object HelloWorld : ActionWithAllTypesOfInputsBindingV1.BahEnum("helloworld")
331331

332332
public class Custom(
333333
customStringValue: String,
334-
) : ActionWithAllTypesOfInputs.BahEnum(customStringValue)
334+
) : ActionWithAllTypesOfInputsBindingV1.BahEnum(customStringValue)
335335
}
336336

337337
public sealed class MyEnum(
338338
public val stringValue: String,
339339
) {
340-
public object One : ActionWithAllTypesOfInputs.MyEnum("one")
340+
public object One : ActionWithAllTypesOfInputsBindingV1.MyEnum("one")
341341

342-
public object Two : ActionWithAllTypesOfInputs.MyEnum("two")
342+
public object Two : ActionWithAllTypesOfInputsBindingV1.MyEnum("two")
343343

344-
public object Three : ActionWithAllTypesOfInputs.MyEnum("three")
344+
public object Three : ActionWithAllTypesOfInputsBindingV1.MyEnum("three")
345345

346346
public class Custom(
347347
customStringValue: String,
348-
) : ActionWithAllTypesOfInputs.MyEnum(customStringValue)
348+
) : ActionWithAllTypesOfInputsBindingV1.MyEnum(customStringValue)
349349
}
350350

351351
public sealed class MyInt(
352352
public val integerValue: Int,
353353
) {
354354
public class Value(
355355
requestedValue: Int,
356-
) : ActionWithAllTypesOfInputs.MyInt(requestedValue)
356+
) : ActionWithAllTypesOfInputsBindingV1.MyInt(requestedValue)
357357

358-
public object TheAnswer : ActionWithAllTypesOfInputs.MyInt(42)
358+
public object TheAnswer : ActionWithAllTypesOfInputsBindingV1.MyInt(42)
359359
}
360360

361361
public class Outputs(

0 commit comments

Comments
 (0)