Skip to content

Commit c9e8a2f

Browse files
committed
feat(abg): add binding version v2
1 parent ab9e729 commit c9e8a2f

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
@@ -108,6 +108,16 @@ workflow(
108108

109109
cleanMavenLocal()
110110

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

.github/workflows/bindings-server.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,46 +84,54 @@ jobs:
8484
name: 'Clean Maven Local to fetch required POMs again'
8585
run: 'rm -rf ~/.m2/repository/'
8686
- id: 'step-9'
87+
name: 'Execute the script using the bindings from the server with v2 route'
88+
run: |-
89+
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
90+
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
91+
- id: 'step-10'
92+
name: 'Clean Maven Local to fetch required POMs again'
93+
run: 'rm -rf ~/.m2/repository/'
94+
- id: 'step-11'
8795
name: 'Execute the script using bindings but without dependency on library'
8896
run: |-
8997
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
9098
.github/workflows/test-served-bindings-depend-on-library.main.kts
91-
- id: 'step-10'
99+
- id: 'step-12'
92100
name: 'Install Kotlin 1.9.0'
93101
uses: 'fwilhe2/setup-kotlin@v1'
94102
with:
95103
version: '1.9.0'
96-
- id: 'step-11'
104+
- id: 'step-13'
97105
name: 'Clean Maven Local to fetch required POMs again'
98106
run: 'rm -rf ~/.m2/repository/'
99-
- id: 'step-12'
107+
- id: 'step-14'
100108
name: 'Execute the script using the bindings from the server, using older Kotlin (1.9.0) as consumer'
101109
run: |2-
102110
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
103111
(.github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts || true) >> output.txt 2>&1
104112
grep "was compiled with an incompatible version of Kotlin" output.txt
105-
- id: 'step-13'
113+
- id: 'step-15'
106114
name: 'Install Kotlin 2.0.0'
107115
uses: 'fwilhe2/setup-kotlin@v1'
108116
with:
109117
version: '2.0.0'
110-
- id: 'step-14'
118+
- id: 'step-16'
111119
name: 'Clean Maven Local to fetch required POMs again'
112120
run: 'rm -rf ~/.m2/repository/'
113-
- id: 'step-15'
121+
- id: 'step-17'
114122
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
115123
run: |-
116124
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
117125
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
118-
- id: 'step-16'
126+
- id: 'step-18'
119127
name: 'Compile a Gradle project using the bindings from the server'
120128
run: |-
121129
cd .github/workflows/test-gradle-project-using-bindings-server
122130
./gradlew build
123-
- id: 'step-17'
131+
- id: 'step-19'
124132
name: 'Fetch maven-metadata.xml for top-level action'
125133
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
126-
- id: 'step-18'
134+
- id: 'step-20'
127135
name: 'Fetch maven-metadata.xml for nested action'
128136
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
129137
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
@@ -194,6 +194,7 @@ public abstract interface class io/github/typesafegithub/workflows/actionbinding
194194

195195
public final class io/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion : java/lang/Enum {
196196
public static final field V1 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
197+
public static final field V2 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
197198
public static fun getEntries ()Lkotlin/enums/EnumEntries;
198199
public final fun getLibraryVersion ()Ljava/lang/String;
199200
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.7")
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+
)
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(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This file was generated using action-binding-generator. Don't change it by hand, otherwise your
2+
// changes will be overwritten with the next binding code regeneration.
3+
// See https://github.com/typesafegithub/github-workflows-kt for more info.
4+
@file:Suppress(
5+
"DataClassPrivateConstructor",
6+
"UNUSED_PARAMETER",
7+
)
8+
9+
package io.github.typesafegithub.workflows.actions.johnsmith
10+
11+
import io.github.typesafegithub.workflows.domain.actions.Action
12+
import io.github.typesafegithub.workflows.domain.actions.RegularAction
13+
import java.util.LinkedHashMap
14+
import kotlin.ExposedCopyVisibility
15+
import kotlin.String
16+
import kotlin.Suppress
17+
import kotlin.Unit
18+
import kotlin.collections.Map
19+
20+
/**
21+
* Action: Action With No Inputs
22+
*
23+
* Description
24+
*
25+
* [Action on GitHub](https://github.com/john-smith/action-binding-v2-with/tree/v3/sub/action)
26+
*
27+
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
28+
* @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
29+
*/
30+
@ExposedCopyVisibility
31+
public data class ActionBindingV2WithSubAction private constructor(
32+
/**
33+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
34+
*/
35+
public val _customInputs: Map<String, String> = mapOf(),
36+
/**
37+
* 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
38+
*/
39+
public val _customVersion: String? = null,
40+
) : RegularAction<Action.Outputs>("john-smith", "action-binding-v2-with/sub/action", _customVersion ?: "v3") {
41+
init {
42+
println("WARNING: The used binding version v2 for john-smith/action-binding-v2-with/sub/action@v3 is experimental! Last stable version is v1.")
43+
if (System.getenv("GITHUB_ACTIONS").toBoolean()) {
44+
println("""
45+
|
46+
|::warning title=Experimental Binding Version Used::The used binding version v2 for john-smith/action-binding-v2-with/sub/action@v3 is experimental! Last stable version is v1.
47+
""".trimMargin())
48+
}
49+
50+
}
51+
52+
public constructor(
53+
vararg pleaseUseNamedArguments: Unit,
54+
_customInputs: Map<String, String> = mapOf(),
55+
_customVersion: String? = null,
56+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
57+
58+
@Suppress("SpreadOperator")
59+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
60+
61+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
62+
}

0 commit comments

Comments
 (0)