Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/bindings-server.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ workflow(
cleanMavenLocal()

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

cleanMavenLocal()

run(
name = "Execute the script using the bindings from the server with v1 route",
name = "Execute the script using the bindings from the server with binding version v2",
command = """
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
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(),
)

Expand All @@ -133,7 +133,7 @@ workflow(
runWithSpecificKotlinVersion(
kotlinVersion = newestNotCompatibleVersion,
command = """
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
cp .github/workflows/test-script-consuming-jit-bindings-v1.main.kts .github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts
${failsWithPhraseInLogs(
command = ".github/workflows/test-script-consuming-jit-bindings-too-old-kotlin.main.kts",
// This test depicts the current behavior that the served bindings aren't
Expand All @@ -146,7 +146,7 @@ workflow(
runWithSpecificKotlinVersion(
kotlinVersion = oldestCompatibleVersion,
command = """
cp .github/workflows/test-script-consuming-jit-bindings.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
cp .github/workflows/test-script-consuming-jit-bindings-v1.main.kts .github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
.github/workflows/test-script-consuming-jit-bindings-older-kotlin.main.kts
""".trimIndent(),
)
Expand All @@ -161,11 +161,11 @@ workflow(

run(
name = "Fetch maven-metadata.xml for top-level action",
command = "curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep '<version>v4</version>'",
command = "curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep '<version>binding_version_v1___v4</version>'",
)
run(
name = "Fetch maven-metadata.xml for nested action",
command = "curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep '<version>v4</version>'",
command = "curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep '<version>binding_version_v1___v4</version>'",
)

run(
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/bindings-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ jobs:
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-5'
name: 'Execute the script using the bindings from the server'
name: 'Execute the script using the bindings from the server with binding version v1'
run: |-
mv .github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings.main.kts
.github/workflows/test-script-consuming-jit-bindings.main.kts
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
- id: 'step-6'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
- id: 'step-7'
name: 'Execute the script using the bindings from the server with v1 route'
name: 'Execute the script using the bindings from the server with binding version v2'
run: |-
mv .github/workflows/test-script-consuming-jit-bindings-v1.main.do-not-compile.kts .github/workflows/test-script-consuming-jit-bindings-v1.main.kts
.github/workflows/test-script-consuming-jit-bindings-v1.main.kts
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-8'
name: 'Clean Maven Local to fetch required POMs again'
run: 'rm -rf ~/.m2/repository/'
Expand All @@ -100,7 +100,7 @@ jobs:
- id: 'step-12'
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
cp .github/workflows/test-script-consuming-jit-bindings-v1.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'
Expand All @@ -114,7 +114,7 @@ jobs:
- id: 'step-15'
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
cp .github/workflows/test-script-consuming-jit-bindings-v1.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'
name: 'Compile a Gradle project using the bindings from the server'
Expand All @@ -123,10 +123,10 @@ jobs:
./gradlew build --refresh-dependencies
- id: 'step-17'
name: 'Fetch maven-metadata.xml for top-level action'
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>v4</version>'''
run: 'curl --fail http://localhost:8080/actions/checkout/maven-metadata.xml | grep ''<version>binding_version_v1___v4</version>'''
- id: 'step-18'
name: 'Fetch maven-metadata.xml for nested action'
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>v4</version>'''
run: 'curl --fail http://localhost:8080/actions/cache__save/maven-metadata.xml | grep ''<version>binding_version_v1___v4</version>'''
- id: 'step-19'
name: 'Print server logs'
run: 'cat jit-binding-server/logs/server.log'
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")

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")

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

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

// Using specific version.
@file:DependsOn("actions:cache:binding_version_v2___v3.3.3-beta")

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

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)

This file was deleted.

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 @@ -218,6 +218,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 @@ -22,7 +22,9 @@ dependencies {
implementation(projects.sharedInternal)

testImplementation("io.ktor:ktor-client-mock:3.4.3")
testImplementation(kotlin("reflect"))
testImplementation(projects.githubWorkflowsKt)
testImplementation(projects.testUtils)
}

kotlin {
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.7.0"),
V2(libraryVersion = "3.7.0"),
;

override fun toString(): String = super.toString().lowercase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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.engine.mapError
import io.kotest.matchers.Matcher.Companion.failure
import io.kotest.matchers.shouldBe
import java.lang.reflect.InvocationTargetException
import java.nio.file.Paths
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.jvm.isAccessible

fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
val binding =
Expand Down Expand Up @@ -37,3 +43,29 @@ 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
.let { it.primaryConstructor ?: it.constructors.first() }
.apply { isAccessible = true }
return runCatching {
constructor.callBy(
arguments.mapKeys { (key, _) ->
constructor.parameters.first { it.name == key }
},
)
}.mapError {
if (it is InvocationTargetException) it.targetException else it
}.getOrThrow()
}
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
Loading