Skip to content

Commit 1023bcc

Browse files
committed
feat(abg): add binding version v2
1 parent f1e42c2 commit 1023bcc

File tree

42 files changed

+2716
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2716
-630
lines changed

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

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

108108
cleanMavenLocal()
109109

110+
run(
111+
name = "Execute the script using the bindings from the server with v2 route",
112+
command = """
113+
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
114+
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
115+
""".trimIndent(),
116+
)
117+
118+
cleanMavenLocal()
119+
110120
run(
111121
name = "Execute the script using bindings but without dependency on library",
112122
command = """

.github/workflows/bindings-server.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,54 @@ jobs:
8282
name: 'Clean Maven Local to fetch required POMs again'
8383
run: 'rm -rf ~/.m2/repository/'
8484
- id: 'step-9'
85+
name: 'Execute the script using the bindings from the server with v2 route'
86+
run: |-
87+
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
88+
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
89+
- id: 'step-10'
90+
name: 'Clean Maven Local to fetch required POMs again'
91+
run: 'rm -rf ~/.m2/repository/'
92+
- id: 'step-11'
8593
name: 'Execute the script using bindings but without dependency on library'
8694
run: |-
8795
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
8896
.github/workflows/test-served-bindings-depend-on-library.main.kts
89-
- id: 'step-10'
97+
- id: 'step-12'
9098
name: 'Install Kotlin 1.9.0'
9199
uses: 'fwilhe2/setup-kotlin@v1'
92100
with:
93101
version: '1.9.0'
94-
- id: 'step-11'
102+
- id: 'step-13'
95103
name: 'Clean Maven Local to fetch required POMs again'
96104
run: 'rm -rf ~/.m2/repository/'
97-
- id: 'step-12'
105+
- id: 'step-14'
98106
name: 'Execute the script using the bindings from the server, using older Kotlin (1.9.0) as consumer'
99107
run: |2-
100108
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
101109
(.github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts || true) >> output.txt 2>&1
102110
grep "was compiled with an incompatible version of Kotlin" output.txt
103-
- id: 'step-13'
111+
- id: 'step-15'
104112
name: 'Install Kotlin 2.0.0'
105113
uses: 'fwilhe2/setup-kotlin@v1'
106114
with:
107115
version: '2.0.0'
108-
- id: 'step-14'
116+
- id: 'step-16'
109117
name: 'Clean Maven Local to fetch required POMs again'
110118
run: 'rm -rf ~/.m2/repository/'
111-
- id: 'step-15'
119+
- id: 'step-17'
112120
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
113121
run: |-
114122
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
115123
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
116-
- id: 'step-16'
124+
- id: 'step-18'
117125
name: 'Compile a Gradle project using the bindings from the server'
118126
run: |-
119127
cd .github/workflows/test-gradle-project-using-bindings-server
120128
./gradlew build
121-
- id: 'step-17'
129+
- id: 'step-19'
122130
name: 'Fetch maven-metadata.xml for top-level action'
123131
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
124-
- id: 'step-18'
132+
- id: 'step-20'
125133
name: 'Fetch maven-metadata.xml for nested action'
126134
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
127135
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
@file:DependsOn("io.kotest:kotest-assertions-core:5.9.1")
55

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

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

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

194194
public final class io/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion : java/lang/Enum {
195195
public static final field V1 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
196+
public static final field V2 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
196197
public static fun getEntries ()Lkotlin/enums/EnumEntries;
197198
public final fun getLibraryVersion ()Ljava/lang/String;
198199
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("io.github.oshai:kotlin-logging:7.0.6")
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.3.0"),
9+
V2(libraryVersion = "3.3.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+
)

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithSubAction.kt renamed to action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionBindingV1WithSubAction.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import kotlin.collections.Map
2222
*
2323
* Description
2424
*
25-
* [Action on GitHub](https://github.com/john-smith/action-with/tree/v3/sub/action)
25+
* [Action on GitHub](https://github.com/john-smith/action-binding-v1-with/tree/v3/sub/action)
2626
*
2727
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
2828
* @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
2929
*/
3030
@ExposedCopyVisibility
31-
public data class ActionWithSubAction private constructor(
31+
public data class ActionBindingV1WithSubAction private constructor(
3232
/**
3333
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
3434
*/
@@ -37,7 +37,7 @@ public data class ActionWithSubAction private constructor(
3737
* 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
3838
*/
3939
public val _customVersion: String? = null,
40-
) : RegularAction<Action.Outputs>("john-smith", "action-with/sub/action", _customVersion ?: "v3") {
40+
) : RegularAction<Action.Outputs>("john-smith", "action-binding-v1-with/sub/action", _customVersion ?: "v3") {
4141
public constructor(
4242
vararg pleaseUseNamedArguments: Unit,
4343
_customInputs: Map<String, String> = mapOf(),

0 commit comments

Comments
 (0)