Skip to content

Commit c2beee5

Browse files
committed
feat(abg): add binding version v2
1 parent 4d58607 commit c2beee5

61 files changed

Lines changed: 3646 additions & 1016 deletions

File tree

Some content is hidden

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

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,20 @@ workflow(
112112
cleanMavenLocal()
113113

114114
run(
115-
name = "Execute the script using the bindings from the server",
115+
name = "Execute the script using the bindings from the server with binding version v1",
116116
command = """
117-
mv .github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings.main.kts
118-
.github/workflows/test-script-consuming-jit-bindings.main.kts
117+
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
118+
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
119119
""".trimIndent(),
120120
)
121121

122122
cleanMavenLocal()
123123

124124
run(
125-
name = "Execute the script using the bindings from the server with v1 route",
125+
name = "Execute the script using the bindings from the server with binding version v2",
126126
command = """
127-
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
128-
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
127+
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
128+
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
129129
""".trimIndent(),
130130
)
131131

@@ -147,7 +147,7 @@ workflow(
147147
runWithSpecificKotlinVersion(
148148
kotlinVersion = newestNotCompatibleVersion,
149149
command = """
150-
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
150+
cp .github/workflows/test-script-consuming-jit-bindings-v1.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
151151
${failsWithPhraseInLogs(
152152
command = ".github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts",
153153
// This test depicts the current behavior that the served bindings aren't
@@ -160,7 +160,7 @@ workflow(
160160
runWithSpecificKotlinVersion(
161161
kotlinVersion = oldestCompatibleVersion,
162162
command = """
163-
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
163+
cp .github/workflows/test-script-consuming-jit-bindings-v1.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
164164
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
165165
""".trimIndent(),
166166
)
@@ -175,11 +175,11 @@ workflow(
175175

176176
run(
177177
name = "Fetch maven-metadata.xml for top-level action",
178-
command = "curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep '<version>v4</version>'",
178+
command = "curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep '<version>binding_version_v1___v4</version>'",
179179
)
180180
run(
181181
name = "Fetch maven-metadata.xml for nested action",
182-
command = "curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep '<version>v4</version>'",
182+
command = "curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep '<version>binding_version_v1___v4</version>'",
183183
)
184184

185185
run(

.github/workflows/bindings-server.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ jobs:
7474
name: 'Clean Maven Local to fetch required POMs again'
7575
run: 'rm -rf ~/.m2/repository/'
7676
- id: 'step-5'
77-
name: 'Execute the script using the bindings from the server'
77+
name: 'Execute the script using the bindings from the server with binding version v1'
7878
run: |-
79-
mv .github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings.main.kts
80-
.github/workflows/test-script-consuming-jit-bindings.main.kts
79+
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
80+
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
8181
- id: 'step-6'
8282
name: 'Clean Maven Local to fetch required POMs again'
8383
run: 'rm -rf ~/.m2/repository/'
8484
- id: 'step-7'
85-
name: 'Execute the script using the bindings from the server with v1 route'
85+
name: 'Execute the script using the bindings from the server with binding version v2'
8686
run: |-
87-
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
88-
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
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
8989
- id: 'step-8'
9090
name: 'Clean Maven Local to fetch required POMs again'
9191
run: 'rm -rf ~/.m2/repository/'
@@ -105,7 +105,7 @@ jobs:
105105
- id: 'step-12'
106106
name: 'Execute the script using the bindings from the server, using older Kotlin (1.9.0) as consumer'
107107
run: |2-
108-
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
108+
cp .github/workflows/test-script-consuming-jit-bindings-v1.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
109109
(.github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts || true) >> output.txt 2>&1
110110
grep "was compiled with an incompatible version of Kotlin" output.txt
111111
- id: 'step-13'
@@ -119,7 +119,7 @@ jobs:
119119
- id: 'step-15'
120120
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
121121
run: |-
122-
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
122+
cp .github/workflows/test-script-consuming-jit-bindings-v1.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
123123
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
124124
- id: 'step-16'
125125
name: 'Compile a Gradle project using the bindings from the server'
@@ -128,10 +128,10 @@ jobs:
128128
./gradlew build --refresh-dependencies
129129
- id: 'step-17'
130130
name: 'Fetch maven-metadata.xml for top-level action'
131-
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
131+
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>binding_version_v1___v4</version>'''
132132
- id: 'step-18'
133133
name: 'Fetch maven-metadata.xml for nested action'
134-
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
134+
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>binding_version_v1___v4</version>'''
135135
- id: 'step-19'
136136
name: 'Print server logs'
137137
run: 'cat jit-binding-server/logs/server.log'

.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")
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")
6+
7+
// Regular, top-level action.
8+
@file:DependsOn("actions:checkout:binding_version_v2___v4-beta")
9+
10+
// Nested action.
11+
@file:DependsOn("gradle:actions__setup-gradle:binding_version_v2___v3-beta")
12+
13+
// Using specific version.
14+
@file:DependsOn("actions:cache:binding_version_v2___v3.3.3-beta")
15+
16+
// Always untyped action.
17+
@file:DependsOn("typesafegithub:always-untyped-action-for-tests:binding_version_v2___v1-beta")
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: 0 additions & 55 deletions
This file was deleted.

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

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

219219
public final class io/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion : java/lang/Enum {
220220
public static final field V1 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
221+
public static final field V2 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
221222
public static fun getEntries ()Lkotlin/enums/EnumEntries;
222223
public final fun getLibraryVersion ()Ljava/lang/String;
223224
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
@@ -22,7 +22,9 @@ dependencies {
2222
implementation(projects.sharedInternal)
2323

2424
testImplementation("io.ktor:ktor-client-mock:3.5.0")
25+
testImplementation(kotlin("reflect"))
2526
testImplementation(projects.githubWorkflowsKt)
27+
testImplementation(projects.testUtils)
2628
}
2729

2830
kotlin {

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.7.0"),
9+
V2(libraryVersion = "3.7.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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
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.engine.mapError
47
import io.kotest.matchers.Matcher.Companion.failure
58
import io.kotest.matchers.shouldBe
9+
import java.lang.reflect.InvocationTargetException
610
import java.nio.file.Paths
11+
import kotlin.reflect.full.primaryConstructor
12+
import kotlin.reflect.jvm.isAccessible
713

814
fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
915
val binding =
@@ -37,3 +43,29 @@ fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
3743
}
3844

3945
private fun String.removeWindowsNewLines(): String = replace("\r\n", "\n")
46+
47+
fun constructAction(
48+
owner: String,
49+
classBaseName: String,
50+
bindingVersion: BindingVersion,
51+
arguments: Map<String, Any?> = emptyMap(),
52+
): Action<*> {
53+
val constructor =
54+
Class
55+
.forName("io.github.typesafegithub.workflows.actions.$owner.${classBaseName}Binding${bindingVersion.name}")
56+
.let {
57+
@Suppress("UNCHECKED_CAST")
58+
it as Class<Action<*>>
59+
}.kotlin
60+
.let { it.primaryConstructor ?: it.constructors.first() }
61+
.apply { isAccessible = true }
62+
return runCatching {
63+
constructor.callBy(
64+
arguments.mapKeys { (key, _) ->
65+
constructor.parameters.first { it.name == key }
66+
},
67+
)
68+
}.mapError {
69+
if (it is InvocationTargetException) it.targetException else it
70+
}.getOrThrow()
71+
}

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)