Skip to content

Commit

Permalink
feat(abg): add binding version v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Sep 24, 2024
1 parent b1616bd commit 36a0a91
Show file tree
Hide file tree
Showing 40 changed files with 2,711 additions and 609 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/bindings-server.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ workflow(

cleanMavenLocal()

run(
name = "Execute the script using the bindings from the server with v2 route",
command = """
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
""".trimIndent(),
)

cleanMavenLocal()

run(
name = "Execute the script using bindings but without dependency on library",
command = """
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/bindings-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,22 @@ jobs:
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-9'
name: 'Execute the script using the bindings from the server with v2 route'
run: |-
mv .github/workflows/test-script-consuming-jit-bindings-v2.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v2.main.kts
.github/workflows/test-script-consuming-jit-bindings-v2.main.kts
- id: 'step-10'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-11'
name: 'Execute the script using bindings but without dependency on library'
run: |-
mv .github/workflows/test-served-bindings-depend-on-library.main.do-not-compile.kts .github/workflows/test-served-bindings-depend-on-library.main.kts
.github/workflows/test-served-bindings-depend-on-library.main.kts
- id: 'step-10'
- id: 'step-12'
name: 'Fetch maven-metadata.xml for top-level action'
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
- id: 'step-11'
- id: 'step-13'
name: 'Fetch maven-metadata.xml for nested action'
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
deploy:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env kotlin
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env kotlin
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")

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

// Regular, top-level action.
@file:DependsOn("actions:checkout:v4")

// Nested action.
@file:DependsOn("gradle:actions__setup-gradle:v3")

// Using specific version.
@file:DependsOn("actions:cache:v3.3.3")

// Always untyped action.
@file:DependsOn("typesafegithub:always-untyped-action-for-tests:v1")

import io.github.typesafegithub.workflows.actions.actions.Cache
import io.github.typesafegithub.workflows.actions.actions.Checkout
import io.github.typesafegithub.workflows.actions.actions.Checkout_Untyped
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
import io.github.typesafegithub.workflows.actions.typesafegithub.AlwaysUntypedActionForTests_Untyped

println(Checkout_Untyped(fetchTags_Untyped = "false"))
println(Checkout(fetchTags = false))
println(Checkout(fetchTags_Untyped = "false"))
println(AlwaysUntypedActionForTests_Untyped(foobar_Untyped = "baz"))
println(ActionsSetupGradle())
println(Cache(path = listOf("some-path"), key = "some-key"))

// Ensure that 'copy(...)' method is exposed.
Checkout(fetchTags = false).copy(fetchTags = true)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env kotlin
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")

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

Expand Down
1 change: 1 addition & 0 deletions action-binding-generator/api/action-binding-generator.api
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public abstract interface class io/github/typesafegithub/workflows/actionbinding

public final class io/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion : java/lang/Enum {
public static final field V1 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
public static final field V2 Lio/github/typesafegithub/workflows/actionbindinggenerator/versioning/BindingVersion;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public final fun getLibraryVersion ()Ljava/lang/String;
public final fun isDeprecated ()Z
Expand Down
2 changes: 2 additions & 0 deletions action-binding-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
implementation("com.charleskorn.kaml:kaml:0.61.0")
implementation(projects.sharedInternal)

testImplementation("io.kotest:kotest-framework-datatest")
testImplementation(kotlin("reflect"))
testImplementation(projects.githubWorkflowsKt)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum class BindingVersion(
public val libraryVersion: String,
) {
V1(isExperimental = false, libraryVersion = "3.0.0"),
V2(libraryVersion = "3.0.0"),
;

override fun toString(): String = super.toString().lowercase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package io.github.typesafegithub.workflows.actionbindinggenerator

import io.github.typesafegithub.workflows.actionbindinggenerator.generation.ActionBinding
import io.github.typesafegithub.workflows.actionbindinggenerator.versioning.BindingVersion
import io.github.typesafegithub.workflows.domain.actions.Action
import io.kotest.common.mapError
import io.kotest.core.spec.style.scopes.ContainerScope
import io.kotest.datatest.withData
import io.kotest.matchers.Matcher.Companion.failure
import io.kotest.matchers.shouldBe
import java.lang.reflect.InvocationTargetException
import java.nio.file.Paths

fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
Expand Down Expand Up @@ -36,3 +42,68 @@ fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
}

private fun String.removeWindowsNewLines(): String = replace("\r\n", "\n")

fun constructAction(
owner: String,
classBaseName: String,
bindingVersion: BindingVersion,
arguments: Map<String, Any?> = emptyMap(),
): Action<*> {
val constructor =
Class
.forName("io.github.typesafegithub.workflows.actions.$owner.${classBaseName}Binding${bindingVersion.name}")
.let {
@Suppress("UNCHECKED_CAST")
it as Class<Action<*>>
}.kotlin
.constructors
.first()
return runCatching {
constructor.callBy(
arguments.mapKeys { (key, _) ->
constructor.parameters.first { it.name == key }
},
)
}.mapError {
if (it is InvocationTargetException) it.targetException else it
}.getOrThrow()
}

suspend fun ContainerScope.withBindingVersions(
bindingVersions: Iterable<BindingVersion>,
test: suspend ContainerScope.(BindingVersion) -> Unit,
) = withData(
nameFn = { "binding version $it" },
ts = bindingVersions,
test = test,
)

suspend fun ContainerScope.withAllBindingVersions(test: suspend ContainerScope.(BindingVersion) -> Unit) =
withBindingVersions(
bindingVersions = BindingVersion.entries,
test = test,
)

suspend fun ContainerScope.withBindingVersions(
bindingVersions: OpenEndRange<BindingVersion>,
test: suspend ContainerScope.(BindingVersion) -> Unit,
) = withBindingVersions(
bindingVersions = BindingVersion.entries.filter { it in bindingVersions },
test = test,
)

suspend fun ContainerScope.withBindingVersions(
bindingVersions: ClosedRange<BindingVersion>,
test: suspend ContainerScope.(BindingVersion) -> Unit,
) = withBindingVersions(
bindingVersions = BindingVersion.entries.filter { it in bindingVersions },
test = test,
)

suspend fun ContainerScope.withBindingVersionsFrom(
bindingVersion: BindingVersion,
test: suspend ContainerScope.(BindingVersion) -> Unit,
) = withBindingVersions(
bindingVersions = bindingVersion..BindingVersion.entries.last(),
test = test,
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlin.collections.toTypedArray
*
* This is a test description that should be put in the KDoc comment for a class
*
* [Action on GitHub](https://github.com/john-smith/action-with-all-types-of-inputs)
* [Action on GitHub](https://github.com/john-smith/action-with-all-types-of-inputs-binding-v1)
*
* @param fooBar &lt;required&gt; Short description
* @param fooBar_Untyped &lt;required&gt; Short description
Expand Down Expand Up @@ -60,7 +60,7 @@ import kotlin.collections.toTypedArray
* version, or a newer version that the binding doesn't yet know about
*/
@ExposedCopyVisibility
public data class ActionWithAllTypesOfInputs private constructor(
public data class ActionWithAllTypesOfInputsBindingV1 private constructor(
/**
* &lt;required&gt; Short description
*/
Expand Down Expand Up @@ -104,23 +104,23 @@ public data class ActionWithAllTypesOfInputs private constructor(
/**
* &lt;required&gt; Enumeration
*/
public val finBin: ActionWithAllTypesOfInputs.Bin? = null,
public val finBin: ActionWithAllTypesOfInputsBindingV1.Bin? = null,
/**
* &lt;required&gt; Enumeration
*/
public val finBin_Untyped: String? = null,
/**
* &lt;required&gt; Integer with special value
*/
public val gooZen: ActionWithAllTypesOfInputs.Zen? = null,
public val gooZen: ActionWithAllTypesOfInputsBindingV1.Zen? = null,
/**
* &lt;required&gt; Integer with special value
*/
public val gooZen_Untyped: String? = null,
/**
* &lt;required&gt; Enum with custom naming
*/
public val bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
public val bahEnum: ActionWithAllTypesOfInputsBindingV1.BahEnum? = null,
/**
* &lt;required&gt; Enum with custom naming
*/
Expand All @@ -144,15 +144,15 @@ public data class ActionWithAllTypesOfInputs private constructor(
/**
* List of enums
*/
public val listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
public val listEnums: List<ActionWithAllTypesOfInputsBindingV1.MyEnum>? = null,
/**
* List of enums
*/
public val listEnums_Untyped: String? = null,
/**
* List of integer with special values
*/
public val listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
public val listIntSpecial: List<ActionWithAllTypesOfInputsBindingV1.MyInt>? = null,
/**
* List of integer with special values
*/
Expand All @@ -166,8 +166,8 @@ public data class ActionWithAllTypesOfInputs private constructor(
* version that the binding doesn't yet know about
*/
public val _customVersion: String? = null,
) : RegularAction<ActionWithAllTypesOfInputs.Outputs>("john-smith",
"action-with-all-types-of-inputs", _customVersion ?: "v3") {
) : RegularAction<ActionWithAllTypesOfInputsBindingV1.Outputs>("john-smith",
"action-with-all-types-of-inputs-binding-v1", _customVersion ?: "v3") {
init {
require(!((fooBar != null) && (fooBar_Untyped != null))) {
"Only fooBar or fooBar_Untyped must be set, but not both"
Expand Down Expand Up @@ -251,19 +251,19 @@ public data class ActionWithAllTypesOfInputs private constructor(
intPint_Untyped: String? = null,
floPint: Float? = null,
floPint_Untyped: String? = null,
finBin: ActionWithAllTypesOfInputs.Bin? = null,
finBin: ActionWithAllTypesOfInputsBindingV1.Bin? = null,
finBin_Untyped: String? = null,
gooZen: ActionWithAllTypesOfInputs.Zen? = null,
gooZen: ActionWithAllTypesOfInputsBindingV1.Zen? = null,
gooZen_Untyped: String? = null,
bahEnum: ActionWithAllTypesOfInputs.BahEnum? = null,
bahEnum: ActionWithAllTypesOfInputsBindingV1.BahEnum? = null,
bahEnum_Untyped: String? = null,
listStrings: List<String>? = null,
listStrings_Untyped: String? = null,
listInts: List<Int>? = null,
listInts_Untyped: String? = null,
listEnums: List<ActionWithAllTypesOfInputs.MyEnum>? = null,
listEnums: List<ActionWithAllTypesOfInputsBindingV1.MyEnum>? = null,
listEnums_Untyped: String? = null,
listIntSpecial: List<ActionWithAllTypesOfInputs.MyInt>? = null,
listIntSpecial: List<ActionWithAllTypesOfInputsBindingV1.MyInt>? = null,
listIntSpecial_Untyped: String? = null,
_customInputs: Map<String, String> = mapOf(),
_customVersion: String? = null,
Expand Down Expand Up @@ -314,61 +314,61 @@ public data class ActionWithAllTypesOfInputs private constructor(
public sealed class Bin(
public val stringValue: String,
) {
public object Foo : ActionWithAllTypesOfInputs.Bin("foo")
public object Foo : ActionWithAllTypesOfInputsBindingV1.Bin("foo")

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

public object Baz123 : ActionWithAllTypesOfInputs.Bin("baz123")
public object Baz123 : ActionWithAllTypesOfInputsBindingV1.Bin("baz123")

public class Custom(
customStringValue: String,
) : ActionWithAllTypesOfInputs.Bin(customStringValue)
) : ActionWithAllTypesOfInputsBindingV1.Bin(customStringValue)
}

public sealed class Zen(
public val integerValue: Int,
) {
public class Value(
requestedValue: Int,
) : ActionWithAllTypesOfInputs.Zen(requestedValue)
) : ActionWithAllTypesOfInputsBindingV1.Zen(requestedValue)

public object Special1 : ActionWithAllTypesOfInputs.Zen(3)
public object Special1 : ActionWithAllTypesOfInputsBindingV1.Zen(3)

public object Special2 : ActionWithAllTypesOfInputs.Zen(-1)
public object Special2 : ActionWithAllTypesOfInputsBindingV1.Zen(-1)
}

public sealed class BahEnum(
public val stringValue: String,
) {
public object HelloWorld : ActionWithAllTypesOfInputs.BahEnum("helloworld")
public object HelloWorld : ActionWithAllTypesOfInputsBindingV1.BahEnum("helloworld")

public class Custom(
customStringValue: String,
) : ActionWithAllTypesOfInputs.BahEnum(customStringValue)
) : ActionWithAllTypesOfInputsBindingV1.BahEnum(customStringValue)
}

public sealed class MyEnum(
public val stringValue: String,
) {
public object One : ActionWithAllTypesOfInputs.MyEnum("one")
public object One : ActionWithAllTypesOfInputsBindingV1.MyEnum("one")

public object Two : ActionWithAllTypesOfInputs.MyEnum("two")
public object Two : ActionWithAllTypesOfInputsBindingV1.MyEnum("two")

public object Three : ActionWithAllTypesOfInputs.MyEnum("three")
public object Three : ActionWithAllTypesOfInputsBindingV1.MyEnum("three")

public class Custom(
customStringValue: String,
) : ActionWithAllTypesOfInputs.MyEnum(customStringValue)
) : ActionWithAllTypesOfInputsBindingV1.MyEnum(customStringValue)
}

public sealed class MyInt(
public val integerValue: Int,
) {
public class Value(
requestedValue: Int,
) : ActionWithAllTypesOfInputs.MyInt(requestedValue)
) : ActionWithAllTypesOfInputsBindingV1.MyInt(requestedValue)

public object TheAnswer : ActionWithAllTypesOfInputs.MyInt(42)
public object TheAnswer : ActionWithAllTypesOfInputsBindingV1.MyInt(42)
}

public class Outputs(
Expand Down
Loading

0 comments on commit 36a0a91

Please sign in to comment.