diff --git a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt index 30f4ad88c6..8392c8fff5 100644 --- a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt +++ b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt @@ -11,24 +11,28 @@ public data class ActionCoords( * A top-level action is an action with its `action.y(a)ml` file in the repository root, as opposed to actions stored * in subdirectories. */ -public val ActionCoords.isTopLevel: Boolean get() = "/" !in name +public val ActionCoords.isTopLevel: Boolean get() = "__" !in name.substringBefore("___") -public val ActionCoords.prettyPrint: String get() = "$owner/$name@$version${typesUuid?.let { " (types: $it)" } ?: ""}" +public val ActionCoords.prettyPrint: String + get() = "$owner/${ + name.replace("___", " with ").replace("__", "/") + }@$version${typesUuid?.let { " (types: $it)" } ?: ""}" /** * For most actions, it's the same as [ActionCoords.name]. * For actions that aren't executed from the root of the repo, it returns the repo name. */ public val ActionCoords.repoName: String get() = - name.substringBefore("/") + name.substringBefore("__") /** * For most actions, it's empty. * For actions that aren't executed from the root of the repo, it returns the path relative to the repo root where the * action lives. */ -public val ActionCoords.subName: String get() = - if (isTopLevel) "" else "/${name.substringAfter("/")}" +public val ActionCoords.subName: String + get() = + if (isTopLevel) "" else "/${name.substringAfter("__").substringBefore("___").replace("__", "/")}" internal fun String.toActionCoords(): ActionCoords { val (ownerAndName, version) = this.split('@') diff --git a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNaming.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNaming.kt index 2d988e4fc6..ba68c602ea 100644 --- a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNaming.kt +++ b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNaming.kt @@ -3,4 +3,4 @@ package io.github.typesafegithub.workflows.actionbindinggenerator.generation import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords import io.github.typesafegithub.workflows.actionbindinggenerator.utils.toPascalCase -internal fun ActionCoords.buildActionClassName(): String = this.name.toPascalCase() +internal fun ActionCoords.buildActionClassName(): String = this.name.substringBefore("___").toPascalCase() diff --git a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt index c99211329e..67e996a05b 100644 --- a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt +++ b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt @@ -17,6 +17,9 @@ import com.squareup.kotlinpoet.asTypeName import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.isTopLevel +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName import io.github.typesafegithub.workflows.actionbindinggenerator.generation.Properties.CUSTOM_INPUTS import io.github.typesafegithub.workflows.actionbindinggenerator.generation.Properties.CUSTOM_VERSION import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Input @@ -396,10 +399,20 @@ private fun TypeSpec.Builder.inheritsFromRegularAction( return this .superclass(superclass) .addSuperclassConstructorParameter("%S", coords.owner) - .addSuperclassConstructorParameter("%S", coords.name) - .addSuperclassConstructorParameter("_customVersion ?: %S", coords.version) + .addSuperclassConstructorParameter("%S", coords.name.substringBefore("___").replace("__", "/")) + .addSuperclassConstructorParameter( + "_customVersion ?: %S", + when { + coords.name.endsWith("___major") -> coords.version.majorVersion + coords.name.endsWith("___minor") -> coords.version.minorVersion + else -> coords.version + }, + ) } +private val String.majorVersion get() = substringBefore('.') +private val String.minorVersion get() = split('.', limit = 3).take(2).joinToString(".") + private fun Metadata.primaryConstructor( inputTypings: Map, coords: ActionCoords, @@ -590,9 +603,7 @@ private fun actionKdoc( | |${metadata.description.escapedForComments.removeTrailingWhitespacesForEachLine()} | - |[Action on GitHub](https://github.com/${coords.owner}/${coords.name.substringBefore( - '/', - )}${if ("/" in coords.name) "/tree/${coords.version}/${coords.name.substringAfter('/')}" else ""}) + |[Action on GitHub](https://github.com/${coords.owner}/${coords.repoName}${if (!coords.isTopLevel) "/tree/${coords.version}${coords.subName}" else ""}) """.trimMargin() private fun Map?.getInputTyping(key: String) = this?.get(key) ?: StringTyping diff --git a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReading.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReading.kt index 4eb3fe197f..c1893c4f52 100644 --- a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReading.kt +++ b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReading.kt @@ -4,6 +4,8 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCo import io.github.typesafegithub.workflows.actionbindinggenerator.domain.CommitHash import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision import io.github.typesafegithub.workflows.actionbindinggenerator.domain.NewestForVersion +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName import io.github.typesafegithub.workflows.actionbindinggenerator.utils.myYaml import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString @@ -35,17 +37,9 @@ public data class Output( val description: String = "", ) -private fun ActionCoords.actionYmlUrl(gitRef: String) = - "https://raw.githubusercontent.com/$owner/${name.substringBefore( - '/', - )}/$gitRef/${if ("/" in name) "${name.substringAfter('/')}/" else ""}action.yml" +private fun ActionCoords.actionYmlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action.yml" -private fun ActionCoords.actionYamlUrl(gitRef: String) = - "https://raw.githubusercontent.com/$owner/${name.substringBefore( - '/', - )}/$gitRef/${if ("/" in name) "${name.substringAfter('/')}/" else ""}action.yaml" - -internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name" +private fun ActionCoords.actionYamlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action.yaml" public fun ActionCoords.fetchMetadata( metadataRevision: MetadataRevision, diff --git a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/utils/TextUtils.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/utils/TextUtils.kt index 0afd594faf..c3e5b86154 100644 --- a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/utils/TextUtils.kt +++ b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/utils/TextUtils.kt @@ -7,7 +7,7 @@ internal fun String.toPascalCase(): String { val normalizedString = if (hasOnlyUppercases) lowercase() else this return normalizedString .replace("+", "-plus-") - .split("-", "_", " ", ".", "/") + .split("-", "_", " ", ".", "/", "__") .joinToString("") { it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } } diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMajorVersion.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMajorVersion.kt new file mode 100644 index 0000000000..cbdda62627 --- /dev/null +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMajorVersion.kt @@ -0,0 +1,53 @@ +// 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.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-with-no-inputs-with-major-version) + * + * @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 + */ +public data class ActionWithNoInputsWithMajorVersion private constructor( + /** + * Type-unsafe map where you can put any inputs that are not yet supported by the binding + */ + public val _customInputs: Map = 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("john-smith", "action-with-no-inputs-with-major-version", + _customVersion ?: "v3") { + public constructor( + vararg pleaseUseNamedArguments: Unit, + _customInputs: Map = mapOf(), + _customVersion: String? = null, + ) : this(_customInputs = _customInputs, _customVersion = _customVersion) + + @Suppress("SpreadOperator") + override fun toYamlArguments(): LinkedHashMap = LinkedHashMap(_customInputs) + + override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId) +} diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMajorVersion_Untyped.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMajorVersion_Untyped.kt new file mode 100644 index 0000000000..ade239f3a7 --- /dev/null +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMajorVersion_Untyped.kt @@ -0,0 +1,78 @@ +// 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.Deprecated +import kotlin.String +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.Map + +/** + * ```text + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!! WARNING !!! + * !!! !!! + * !!! This action binding has no typings provided. All inputs will !!! + * !!! have a default type of String. !!! + * !!! To be able to use this action in a type-safe way, ask the !!! + * !!! action's owner to provide the typings using !!! + * !!! !!! + * !!! https://github.com/typesafegithub/github-actions-typing !!! + * !!! !!! + * !!! or if it's impossible, contribute typings to a community-driven !!! + * !!! !!! + * !!! https://github.com/typesafegithub/github-actions-typing-catalog !!! + * !!! !!! + * !!! This '_Untyped' binding will be available even once the typings !!! + * !!! are added. !!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ``` + * + * Action: Action With No Inputs + * + * Description + * + * [Action on GitHub](https://github.com/john-smith/action-with-no-inputs-with-major-version) + * + * @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 + */ +@Deprecated( + "Use the typed class instead", + ReplaceWith("ActionWithNoInputsWithMajorVersion"), +) +public data class ActionWithNoInputsWithMajorVersion_Untyped private constructor( + /** + * Type-unsafe map where you can put any inputs that are not yet supported by the binding + */ + public val _customInputs: Map = 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("john-smith", "action-with-no-inputs-with-major-version", + _customVersion ?: "v3") { + public constructor( + vararg pleaseUseNamedArguments: Unit, + _customInputs: Map = mapOf(), + _customVersion: String? = null, + ) : this(_customInputs = _customInputs, _customVersion = _customVersion) + + @Suppress("SpreadOperator") + override fun toYamlArguments(): LinkedHashMap = LinkedHashMap(_customInputs) + + override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId) +} diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMinorVersion.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMinorVersion.kt new file mode 100644 index 0000000000..b63510e779 --- /dev/null +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMinorVersion.kt @@ -0,0 +1,53 @@ +// 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.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-with-no-inputs-with-minor-version) + * + * @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 + */ +public data class ActionWithNoInputsWithMinorVersion private constructor( + /** + * Type-unsafe map where you can put any inputs that are not yet supported by the binding + */ + public val _customInputs: Map = 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("john-smith", "action-with-no-inputs-with-minor-version", + _customVersion ?: "v3.1") { + public constructor( + vararg pleaseUseNamedArguments: Unit, + _customInputs: Map = mapOf(), + _customVersion: String? = null, + ) : this(_customInputs = _customInputs, _customVersion = _customVersion) + + @Suppress("SpreadOperator") + override fun toYamlArguments(): LinkedHashMap = LinkedHashMap(_customInputs) + + override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId) +} diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMinorVersion_Untyped.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMinorVersion_Untyped.kt new file mode 100644 index 0000000000..7ee341fd5f --- /dev/null +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithNoInputsWithMinorVersion_Untyped.kt @@ -0,0 +1,78 @@ +// 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.Deprecated +import kotlin.String +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.Map + +/** + * ```text + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!! WARNING !!! + * !!! !!! + * !!! This action binding has no typings provided. All inputs will !!! + * !!! have a default type of String. !!! + * !!! To be able to use this action in a type-safe way, ask the !!! + * !!! action's owner to provide the typings using !!! + * !!! !!! + * !!! https://github.com/typesafegithub/github-actions-typing !!! + * !!! !!! + * !!! or if it's impossible, contribute typings to a community-driven !!! + * !!! !!! + * !!! https://github.com/typesafegithub/github-actions-typing-catalog !!! + * !!! !!! + * !!! This '_Untyped' binding will be available even once the typings !!! + * !!! are added. !!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ``` + * + * Action: Action With No Inputs + * + * Description + * + * [Action on GitHub](https://github.com/john-smith/action-with-no-inputs-with-minor-version) + * + * @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 + */ +@Deprecated( + "Use the typed class instead", + ReplaceWith("ActionWithNoInputsWithMinorVersion"), +) +public data class ActionWithNoInputsWithMinorVersion_Untyped private constructor( + /** + * Type-unsafe map where you can put any inputs that are not yet supported by the binding + */ + public val _customInputs: Map = 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("john-smith", "action-with-no-inputs-with-minor-version", + _customVersion ?: "v3.1") { + public constructor( + vararg pleaseUseNamedArguments: Unit, + _customInputs: Map = mapOf(), + _customVersion: String? = null, + ) : this(_customInputs = _customInputs, _customVersion = _customVersion) + + @Suppress("SpreadOperator") + override fun toYamlArguments(): LinkedHashMap = LinkedHashMap(_customInputs) + + override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId) +} diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt index f543792a31..2738f6bd4f 100644 --- a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt @@ -9,8 +9,9 @@ class ClassNamingTest : context("buildActionClassName") { listOf( ActionCoords("irrelevant", "some-action-name", "v2") to "SomeActionName", - ActionCoords("irrelevant", "some-action-name/subaction", "v2") to "SomeActionNameSubaction", - ActionCoords("irrelevant", "some-action-name/foo/bar/baz", "v2") to "SomeActionNameFooBarBaz", + ActionCoords("irrelevant", "some-action-name__subaction", "v2") to "SomeActionNameSubaction", + ActionCoords("irrelevant", "some-action-name__foo__bar__baz", "v2") to "SomeActionNameFooBarBaz", + ActionCoords("irrelevant", "some-action-name__foo__bar__baz___major", "v2") to "SomeActionNameFooBarBaz", ).forEach { (input, output) -> test("should get '$input' and produce '$output'") { input.buildActionClassName() shouldBe output diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/GenerationTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/GenerationTest.kt index f7769c10d0..04af2f6baf 100644 --- a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/GenerationTest.kt +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/GenerationTest.kt @@ -474,6 +474,56 @@ class GenerationTest : binding.shouldContainAndMatchFile("ActionWithPartlyTypings.kt") binding.shouldContainAndMatchFile("ActionWithPartlyTypings_Untyped.kt") } + + test("action with no inputs with major version") { + // given + val actionManifestHasNoInputs = emptyMap() + val actionManifest = + Metadata( + inputs = actionManifestHasNoInputs, + name = "Action With No Inputs", + description = "Description", + ) + + val coords = ActionCoords("john-smith", "action-with-no-inputs-with-major-version___major", "v3.1.3") + + // when + val binding = + coords.generateBinding( + metadataRevision = NewestForVersion, + metadata = actionManifest, + inputTypings = Pair(emptyMap(), ACTION), + ) + + // then + binding.shouldContainAndMatchFile("ActionWithNoInputsWithMajorVersion.kt") + binding.shouldContainAndMatchFile("ActionWithNoInputsWithMajorVersion_Untyped.kt") + } + + test("action with no inputs with minor version") { + // given + val actionManifestHasNoInputs = emptyMap() + val actionManifest = + Metadata( + inputs = actionManifestHasNoInputs, + name = "Action With No Inputs", + description = "Description", + ) + + val coords = ActionCoords("john-smith", "action-with-no-inputs-with-minor-version___minor", "v3.1.3") + + // when + val binding = + coords.generateBinding( + metadataRevision = NewestForVersion, + metadata = actionManifest, + inputTypings = Pair(emptyMap(), ACTION), + ) + + // then + binding.shouldContainAndMatchFile("ActionWithNoInputsWithMinorVersion.kt") + binding.shouldContainAndMatchFile("ActionWithNoInputsWithMinorVersion_Untyped.kt") + } }) private fun Metadata.allInputsAsStrings(): Map = this.inputs.mapValues { StringTyping } diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt index 5ad7082666..56613a9e36 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt @@ -26,14 +26,9 @@ internal data class Jars( val sourcesJar: ByteArray, ) -internal fun buildJars( - owner: String, - name: String, - version: String, - types: String?, -): Jars? { +internal fun ActionCoords.buildJars(types: String?): Jars? { val binding = - generateBinding(owner = owner, name = name, version = version, types = types).also { + generateBinding(metadataRevision = NewestForVersion, types = types).also { if (it.isEmpty()) return null } val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources() @@ -51,24 +46,6 @@ internal fun buildJars( ) } -private fun generateBinding( - owner: String, - name: String, - version: String, - types: String?, -): List { - val actionCoords = - ActionCoords( - owner = owner, - name = name, - version = version, - ) - return actionCoords.generateBinding( - metadataRevision = NewestForVersion, - types = types, - ) -} - private fun compileBinding(sourceFilePaths: List): Path { val compilationOutput = createTempDirectory() diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/MavenMetadataBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/MavenMetadataBuilding.kt index d7473eea77..46c4eeffb1 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/MavenMetadataBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/MavenMetadataBuilding.kt @@ -12,10 +12,10 @@ internal suspend fun ActionCoords.buildMavenMetadataFile(githubToken: String): S .ofPattern("yyyyMMddHHmmss") .withZone(ZoneId.systemDefault()) .format(Instant.now()) - val availableMajorVersions = + val availableVersions = fetchAvailableVersions(owner = owner, name = name.substringBefore("__"), githubToken = githubToken) - .filter { it.isMajorVersion() } - val newest = availableMajorVersions.max() + .filter { it.isMajorVersion() || name.endsWith("___major") || name.endsWith("___minor") } + val newest = availableVersions.max() return """ @@ -25,7 +25,7 @@ internal suspend fun ActionCoords.buildMavenMetadataFile(githubToken: String): S $newest $newest -${availableMajorVersions.joinToString(separator = "\n") { +${availableVersions.joinToString(separator = "\n") { " $it" }} diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt index ded2045d3c..1ca3f4e422 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt @@ -14,7 +14,7 @@ data class JarArtifact( ) : Artifact fun ActionCoords.buildVersionArtifacts(types: String? = null): Map? { - val jars = buildJars(owner = owner, name = name.replace("__", "/"), version = version, types = types) ?: return null + val jars = buildJars(types = types) ?: return null val pom = buildPomFile() val module = buildModuleFile() return mapOf(