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 Oct 28, 2024
1 parent 3421bcb commit d2f3975
Show file tree
Hide file tree
Showing 42 changed files with 2,712 additions and 626 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
16 changes: 12 additions & 4 deletions .github/workflows/bindings-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,30 @@ 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: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-11'
- id: 'step-13'
name: 'Compile a Gradle project using the bindings from the server'
run: |-
cd .github/workflows/test-gradle-project-using-bindings-server
./gradlew build
- id: 'step-12'
- id: 'step-14'
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-13'
- id: 'step-15'
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 @@ -184,6 +184,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 @@ -17,6 +17,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.1"),
V2(libraryVersion = "3.0.1"),
;

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 @@ -22,13 +22,13 @@ import kotlin.collections.Map
*
* Description
*
* [Action on GitHub](https://github.com/john-smith/action-with/tree/v3/sub/action)
* [Action on GitHub](https://github.com/john-smith/action-binding-v1-with/tree/v3/sub/action)
*
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
* @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
*/
@ExposedCopyVisibility
public data class ActionWithSubAction private constructor(
public data class ActionBindingV1WithSubAction private constructor(
/**
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
*/
Expand All @@ -37,7 +37,7 @@ public data class ActionWithSubAction private constructor(
* 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
*/
public val _customVersion: String? = null,
) : RegularAction<Action.Outputs>("john-smith", "action-with/sub/action", _customVersion ?: "v3") {
) : RegularAction<Action.Outputs>("john-smith", "action-binding-v1-with/sub/action", _customVersion ?: "v3") {
public constructor(
vararg pleaseUseNamedArguments: Unit,
_customInputs: Map<String, String> = mapOf(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file was generated using action-binding-generator. Don't change it by hand, otherwise your
// changes will be overwritten with the next binding code regeneration.
// See https://github.com/typesafegithub/github-workflows-kt for more info.
@file:Suppress(
"DataClassPrivateConstructor",
"UNUSED_PARAMETER",
)

package io.github.typesafegithub.workflows.actions.johnsmith

import io.github.typesafegithub.workflows.domain.actions.Action
import io.github.typesafegithub.workflows.domain.actions.RegularAction
import java.util.LinkedHashMap
import kotlin.ExposedCopyVisibility
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.Map

/**
* Action: Action With No Inputs
*
* Description
*
* [Action on GitHub](https://github.com/john-smith/action-binding-v2-with/tree/v3/sub/action)
*
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
* @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
*/
@ExposedCopyVisibility
public data class ActionBindingV2WithSubAction private constructor(
/**
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
*/
public val _customInputs: Map<String, String> = mapOf(),
/**
* 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
*/
public val _customVersion: String? = null,
) : RegularAction<Action.Outputs>("john-smith", "action-binding-v2-with/sub/action", _customVersion ?: "v3") {
init {
println("WARNING: The used binding version v2 for john-smith/action-binding-v2-with/sub/action@v3 is experimental! Last stable version is v1.")
if (System.getenv("GITHUB_ACTIONS").toBoolean()) {
println("""
|
|::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.
""".trimMargin())
}

}

public constructor(
vararg pleaseUseNamedArguments: Unit,
_customInputs: Map<String, String> = mapOf(),
_customVersion: String? = null,
) : this(_customInputs = _customInputs, _customVersion = _customVersion)

@Suppress("SpreadOperator")
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)

override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
}
Loading

0 comments on commit d2f3975

Please sign in to comment.