From 1dc7506a862b02b884ff6a75e88e229b29007a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Sun, 8 Sep 2024 02:24:27 +0200 Subject: [PATCH] chore(abg): Unify content of ActionCoords name --- .../api/action-binding-generator.api | 11 ++-- .../domain/ActionCoords.kt | 26 ++++---- .../generation/ClassNaming.kt | 3 +- .../generation/Generation.kt | 9 +-- .../metadata/MetadataReading.kt | 11 +--- .../typing/TypesProviding.kt | 9 ++- .../ActionWithSubAction.kt | 54 ++++++++++++++++ .../generation/ClassNamingTest.kt | 4 +- .../generation/GenerationTest.kt | 24 +++++++ .../typing/TypesProvidingTest.kt | 12 ++-- .../workflows/jitbindingserver/Main.kt | 8 ++- .../mavenbinding/ActionCoordsUtils.kt | 6 ++ .../workflows/mavenbinding/JarBuilding.kt | 24 +------ .../mavenbinding/MavenMetadataBuilding.kt | 12 ++-- .../workflows/mavenbinding/ModuleBuilding.kt | 19 +++--- .../mavenbinding/PackageArtifactsBuilding.kt | 2 +- .../workflows/mavenbinding/PomBuilding.kt | 62 +++++++++---------- .../mavenbinding/VersionArtifactsBuilding.kt | 22 +++---- 18 files changed, 191 insertions(+), 127 deletions(-) create mode 100644 action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithSubAction.kt create mode 100644 maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ActionCoordsUtils.kt diff --git a/action-binding-generator/api/action-binding-generator.api b/action-binding-generator/api/action-binding-generator.api index ab354073ab..76660945c9 100644 --- a/action-binding-generator/api/action-binding-generator.api +++ b/action-binding-generator/api/action-binding-generator.api @@ -1,21 +1,24 @@ public final class io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords { - public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public synthetic fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/lang/String; public final fun component3 ()Ljava/lang/String; - public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords; - public static synthetic fun copy$default (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords; + public final fun component4 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords; + public static synthetic fun copy$default (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords; public fun equals (Ljava/lang/Object;)Z public final fun getName ()Ljava/lang/String; public final fun getOwner ()Ljava/lang/String; + public final fun getPath ()Ljava/lang/String; public final fun getVersion ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } public final class io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoordsKt { + public static final fun getFullName (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;)Ljava/lang/String; public static final fun getPrettyPrint (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;)Ljava/lang/String; - public static final fun getRepoName (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;)Ljava/lang/String; public static final fun getSubName (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;)Ljava/lang/String; public static final fun isTopLevel (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;)Z } 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 6650508de2..617d283cb0 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 @@ -4,37 +4,39 @@ public data class ActionCoords( val owner: String, val name: String, val version: String, + val path: String? = null, ) /** * 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() = path == null -public val ActionCoords.prettyPrint: String get() = "$owner/$name@$version" +public val ActionCoords.prettyPrint: String get() = "$owner/$fullName@$version" /** - * 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. + * 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, starting with a slash. */ -public val ActionCoords.repoName: String get() = - name.substringBefore("/") +public val ActionCoords.subName: String get() = path?.let { "/$path" } ?: "" /** - * 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 + * For most actions, it's equal to [ActionCoords.name]. + * For actions that aren't executed from the root of the repo, it returns the path starting with the repo root where the * action lives. */ -public val ActionCoords.subName: String get() = - if (isTopLevel) "" else "/${name.substringAfter("/")}" +public val ActionCoords.fullName: String get() = "$name$subName" internal fun String.toActionCoords(): ActionCoords { - val (ownerAndName, version) = this.split('@') - val (owner, name) = ownerAndName.split('/', limit = 2) + val (coordinates, version) = this.split('@') + val coordinateParts = coordinates.split('/') + val (owner, name) = coordinateParts return ActionCoords( owner = owner, name = name, version = version, + path = coordinateParts.drop(2).joinToString("/").takeUnless { it.isBlank() }, ) } 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..da955f4517 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 @@ -1,6 +1,7 @@ package io.github.typesafegithub.workflows.actionbindinggenerator.generation import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.fullName import io.github.typesafegithub.workflows.actionbindinggenerator.utils.toPascalCase -internal fun ActionCoords.buildActionClassName(): String = this.name.toPascalCase() +internal fun ActionCoords.buildActionClassName(): String = this.fullName.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 e5ccbb47cc..0591b1b3fd 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 @@ -18,6 +18,9 @@ import com.squareup.kotlinpoet.buildCodeBlock 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.fullName +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.isTopLevel +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 @@ -411,7 +414,7 @@ private fun TypeSpec.Builder.inheritsFromRegularAction( return this .superclass(superclass) .addSuperclassConstructorParameter("%S", coords.owner) - .addSuperclassConstructorParameter("%S", coords.name) + .addSuperclassConstructorParameter("%S", coords.fullName) .addSuperclassConstructorParameter("_customVersion ?: %S", coords.version) } @@ -614,9 +617,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.name}${if (coords.isTopLevel) "" else "/tree/${coords.version}${coords.subName}"}) """.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 c2fb7ece84..bacd9d3384 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 @@ -5,6 +5,7 @@ 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.subName import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import java.io.IOException @@ -35,15 +36,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/$name/$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" +private fun ActionCoords.actionYamlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$name/$gitRef$subName/action.yaml" internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name" diff --git a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt index 8cb029d86f..a36d409d4e 100644 --- a/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt +++ b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt @@ -8,7 +8,6 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.NewestFo import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource.ACTION import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource.TYPING_CATALOG -import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.fetchUri import io.github.typesafegithub.workflows.actionbindinggenerator.utils.toPascalCase @@ -29,18 +28,18 @@ internal fun ActionCoords.provideTypes( ?: Pair(emptyMap(), null) private fun ActionCoords.actionTypesYmlUrl(gitRef: String) = - "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action-types.yml" + "https://raw.githubusercontent.com/$owner/$name/$gitRef$subName/action-types.yml" private fun ActionCoords.actionTypesFromCatalog() = "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + - "main/typings/$owner/$repoName/$version$subName/action-types.yml" + "main/typings/$owner/$name/$version$subName/action-types.yml" private fun ActionCoords.catalogMetadata() = "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + - "main/typings/$owner/$repoName/metadata.yml" + "main/typings/$owner/$name/metadata.yml" private fun ActionCoords.actionTypesYamlUrl(gitRef: String) = - "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action-types.yaml" + "https://raw.githubusercontent.com/$owner/$name/$gitRef$subName/action-types.yaml" private fun ActionCoords.fetchTypingMetadata( metadataRevision: MetadataRevision, diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithSubAction.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithSubAction.kt new file mode 100644 index 0000000000..d057e43b92 --- /dev/null +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/ActionWithSubAction.kt @@ -0,0 +1,54 @@ +// 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-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( + /** + * 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/sub/action", _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/generation/ClassNamingTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt index f543792a31..f32beae252 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,8 @@ 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", "v2", "subaction") to "SomeActionNameSubaction", + ActionCoords("irrelevant", "some-action-name", "v2", "foo/bar/baz") 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 4e08800962..b0070d3b1f 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 @@ -287,6 +287,30 @@ class GenerationTest : binding.shouldContainAndMatchFile("ActionWithNoInputs.kt") } + test("subaction") { + // given + val actionManifestHasNoInputs = emptyMap() + val actionManifest = + Metadata( + inputs = actionManifestHasNoInputs, + name = "Action With No Inputs", + description = "Description", + ) + + val coords = ActionCoords("john-smith", "action-with", "v3", "sub/action") + + // when + val binding = + coords.generateBinding( + metadataRevision = NewestForVersion, + metadata = actionManifest, + inputTypings = Pair(emptyMap(), ACTION), + ) + + // then + binding.shouldContainAndMatchFile("ActionWithSubAction.kt") + } + test("action with deprecated input resolving to the same Kotlin field name") { // given val actionManifest = diff --git a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt index c0b352fbc4..4798402913 100644 --- a/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt +++ b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt @@ -129,7 +129,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name", "v3", "some-sub") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -166,7 +166,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name", "v3", "some-sub") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -208,7 +208,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name", "v3", "some-sub") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -250,7 +250,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name", "v3", "some-sub") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -302,7 +302,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name", "v3", "some-sub") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -354,7 +354,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v6") + val actionCoord = ActionCoords("some-owner", "some-name", "v6", "some-sub") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) diff --git a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt index 8c27e4a5e2..fb41166eba 100644 --- a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt +++ b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt @@ -72,13 +72,15 @@ private fun Route.metadata(refresh: Boolean = false) { } val owner = call.parameters["owner"]!! - val name = call.parameters["name"]!! + val nameAndPath = call.parameters["name"]!!.split("__") + val name = nameAndPath.first() val file = call.parameters["file"]!! val actionCoords = ActionCoords( owner = owner, name = name, version = "irrelevant", + path = nameAndPath.drop(1).joinToString("/").takeUnless { it.isBlank() }, ) val bindingArtifacts = actionCoords.buildPackageArtifacts(githubToken = getGithubToken()) if (file in bindingArtifacts) { @@ -143,13 +145,15 @@ private suspend fun ApplicationCall.toBindingArtifacts( refresh: Boolean, ): Map? { val owner = parameters["owner"]!! - val name = parameters["name"]!! + val nameAndPath = parameters["name"]!!.split("__") + val name = nameAndPath.first() val version = parameters["version"]!! val actionCoords = ActionCoords( owner = owner, name = name, version = version, + path = nameAndPath.drop(1).joinToString("/").takeUnless { it.isBlank() }, ) println("➡️ Requesting ${actionCoords.prettyPrint}") val bindingArtifacts = diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ActionCoordsUtils.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ActionCoordsUtils.kt new file mode 100644 index 0000000000..5739a0aa1a --- /dev/null +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ActionCoordsUtils.kt @@ -0,0 +1,6 @@ +package io.github.typesafegithub.workflows.mavenbinding + +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName + +internal val ActionCoords.mavenName: String get() = "$name${subName.replace("/", "__")}" 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 88eb0b43a0..5da351987d 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,13 +26,9 @@ internal data class Jars( val sourcesJar: () -> ByteArray, ) -internal fun buildJars( - owner: String, - name: String, - version: String, -): Jars? { +internal fun ActionCoords.buildJars(): Jars? { val binding = - generateBinding(owner = owner, name = name, version = version).also { + generateBinding(metadataRevision = NewestForVersion).also { if (it.isEmpty()) return null } @@ -60,22 +56,6 @@ internal fun buildJars( ) } -private fun generateBinding( - owner: String, - name: String, - version: String, -): List { - val actionCoords = - ActionCoords( - owner = owner, - name = name, - version = version, - ) - return actionCoords.generateBinding( - metadataRevision = NewestForVersion, - ) -} - private fun compileBinding(sourceFilePaths: List): Path { val compilationOutput = createTempDirectory(prefix = "gwkt-classes_") 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 2e0b9aee6a..8a8c854b6d 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 @@ -1,15 +1,13 @@ package io.github.typesafegithub.workflows.mavenbinding +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.fullName import io.github.typesafegithub.workflows.shared.internal.fetchAvailableVersions import java.time.format.DateTimeFormatter -internal suspend fun buildMavenMetadataFile( - owner: String, - name: String, - githubToken: String, -): String { +internal suspend fun ActionCoords.buildMavenMetadataFile(githubToken: String): String { val availableMajorVersions = - fetchAvailableVersions(owner = owner, name = name.substringBefore("__"), githubToken = githubToken) + fetchAvailableVersions(owner = owner, name = name, githubToken = githubToken) .filter { it.isMajorVersion() } val newest = availableMajorVersions.max() val lastUpdated = @@ -20,7 +18,7 @@ internal suspend fun buildMavenMetadataFile( $owner - ${name.replace("__", "/")} + $fullName $newest $newest diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ModuleBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ModuleBuilding.kt index a39c8a5b44..170729fc93 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ModuleBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ModuleBuilding.kt @@ -1,16 +1,15 @@ package io.github.typesafegithub.workflows.mavenbinding -internal fun buildModuleFile( - owner: String, - name: String, - version: String, -): String = +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.fullName + +internal fun ActionCoords.buildModuleFile() = """ { "formatVersion": "1.1", "component": { "group": "$owner", - "module": "$name", + "module": "$fullName", "version": "$version", "attributes": { "org.gradle.status": "release" @@ -36,8 +35,8 @@ internal fun buildModuleFile( "dependencies": [], "files": [ { - "name": "$name-$version.jar", - "url": "$name-$version.jar", + "name": "$fullName-$version.jar", + "url": "$fullName-$version.jar", "size": 1 } ] @@ -56,8 +55,8 @@ internal fun buildModuleFile( "dependencies": [], "files": [ { - "name": "$name-$version.jar", - "url": "$name-$version.jar", + "name": "$fullName-$version.jar", + "url": "$fullName-$version.jar", "size": 1 } ] diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PackageArtifactsBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PackageArtifactsBuilding.kt index 9f1bb4ed8c..686aff5e5d 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PackageArtifactsBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PackageArtifactsBuilding.kt @@ -3,7 +3,7 @@ package io.github.typesafegithub.workflows.mavenbinding import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords suspend fun ActionCoords.buildPackageArtifacts(githubToken: String): Map { - val mavenMetadata = buildMavenMetadataFile(owner = owner, name = name, githubToken = githubToken) + val mavenMetadata = buildMavenMetadataFile(githubToken = githubToken) return mapOf( "maven-metadata.xml" to mavenMetadata, "maven-metadata.xml.md5" to mavenMetadata.md5Checksum(), diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PomBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PomBuilding.kt index 2abf694830..2afb025bc0 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PomBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PomBuilding.kt @@ -1,36 +1,34 @@ package io.github.typesafegithub.workflows.mavenbinding +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.fullName +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPrint + internal const val LATEST_RELASED_LIBRARY_VERSION = "3.0.0" -internal fun buildPomFile( - owner: String, - name: String, - version: String, -): String { - val nameForRepo = name.substringBefore("/") - return """ - - - 4.0.0 - $owner - $name - $version - $name - Auto-generated binding for $owner/$name@$version. - https://github.com/$owner/$nameForRepo - - scm:git:git://github.com/$owner/$nameForRepo.git/ - scm:git:ssh://github.com:$owner/$nameForRepo.git - https://github.com/$owner/$nameForRepo.git - - - - io.github.typesafegithub - github-workflows-kt - $LATEST_RELASED_LIBRARY_VERSION - compile - - - - """.trimIndent() -} +internal fun ActionCoords.buildPomFile() = + """ + + + 4.0.0 + $owner + $fullName + $version + $fullName + Auto-generated binding for $prettyPrint. + https://github.com/$owner/$name + + scm:git:git://github.com/$owner/$name.git/ + scm:git:ssh://github.com:$owner/$name.git + https://github.com/$owner/$name.git + + + + io.github.typesafegithub + github-workflows-kt + $LATEST_RELASED_LIBRARY_VERSION + compile + + + + """.trimIndent() 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 195ff85b2d..aef17b35be 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 @@ -13,17 +13,17 @@ data class JarArtifact( ) : Artifact fun ActionCoords.buildVersionArtifacts(): Map? { - val jars = buildJars(owner = owner, name = name.replace("__", "/"), version = version) ?: return null - val pom = buildPomFile(owner = owner, name = name.replace("__", "/"), version = version) - val module = buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version) + val jars = buildJars() ?: return null + val pom = buildPomFile() + val module = buildModuleFile() return mapOf( - "$name-$version.jar" to JarArtifact(jars.mainJar), - "$name-$version.jar.md5" to TextArtifact { jars.mainJar().md5Checksum() }, - "$name-$version-sources.jar" to JarArtifact(jars.sourcesJar), - "$name-$version-sources.jar.md5" to TextArtifact { jars.sourcesJar().md5Checksum() }, - "$name-$version.pom" to TextArtifact { pom }, - "$name-$version.pom.md5" to TextArtifact { pom.md5Checksum() }, - "$name-$version.module" to TextArtifact { module }, - "$name-$version.module.md5" to TextArtifact { module.md5Checksum() }, + "$mavenName-$version.jar" to JarArtifact(jars.mainJar), + "$mavenName-$version.jar.md5" to TextArtifact { jars.mainJar().md5Checksum() }, + "$mavenName-$version-sources.jar" to JarArtifact(jars.sourcesJar), + "$mavenName-$version-sources.jar.md5" to TextArtifact { jars.sourcesJar().md5Checksum() }, + "$mavenName-$version.pom" to TextArtifact { pom }, + "$mavenName-$version.pom.md5" to TextArtifact { pom.md5Checksum() }, + "$mavenName-$version.module" to TextArtifact { module }, + "$mavenName-$version.module.md5" to TextArtifact { module.md5Checksum() }, ) }