8000 feat(abg): add binding version v2 by Vampire · Pull Request #1647 · typesafegithub/github-workflows-kt · GitHub
[go: up one dir, main page]

Skip to content

feat(abg): add binding version v2 #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: vampire/versioned-routes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension 8000


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/bindings-server.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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
28 changes: 18 additions & 10 deletions .github/workflows/bindings-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,49 +84,57 @@ 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: 'Install Kotlin 1.9.0'
uses: 'fwilhe2/setup-kotlin@v1'
with:
version: '1.9.0'
- id: 'step-11'
- id: 'step-13'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-12'
- id: 'step-14'
name: 'Execute the script using the bindings from the server, using older Kotlin (1.9.0) as consumer'
run: |2-
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
(.github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts || true) >> output.txt 2>&1
grep "was compiled with an incompatible version of Kotlin" output.txt
- id: 'step-13'
- id: 'step-15'
name: 'Install Kotlin 2.0.0'
uses: 'fwilhe2/setup-kotlin@v1'
with:
version: '2.0.0'
- id: 'step-14'
- id: 'step-16'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-15'
- id: 'step-17'
name: 'Execute the script using the bindings from the server, using older Kotlin (2.0.0) as consumer'
run: |-
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
- id: 'step-16'
- id: 'step-18'
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-17'
- id: 'step-19'
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-18'
- id: 'step-20'
name: 'Fetch maven-metadata.xml for nested action'
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
- id: 'step-19'
- id: 'step-21'
name: 'Print server logs'
run: 'cat jit-binding-server/logs/server.log'
if: '${{ always() }}'
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)
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 @@ -194,6 +194,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("io.github.oshai:kotlin-logging:7.0.7")
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.4.0"),
V2(libraryVersion = "3.4.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 @@ -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
1241
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
Loading
0