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..07b6423d5a 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 @@ -10,16 +10,18 @@ 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 -public val ActionCoords.prettyPrint: String get() = "$owner/$name@$version" +public val ActionCoords.prettyPrint: String get() = "$owner/${ + name.replace("__", "/") +}@$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. */ public val ActionCoords.repoName: String get() = - name.substringBefore("/") + name.substringBefore("__") /** * For most actions, it's empty. @@ -27,7 +29,7 @@ public val ActionCoords.repoName: String get() = * action lives. */ public val ActionCoords.subName: String get() = - if (isTopLevel) "" else "/${name.substringAfter("/")}" + if (isTopLevel) "" else "/${name.substringAfter("__").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/Generation.kt b/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt index c7c452cf0d..294288101e 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 @@ -622,9 +625,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 c2fb7ece84..a3b8d6d93a 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,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 kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import java.io.IOException @@ -35,15 +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" +private fun ActionCoords.actionYamlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$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/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/generation/ClassNamingTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt index f543792a31..763bf2c151 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__subaction", "v2") to "SomeActionNameSubaction", + ActionCoords("irrelevant", "some-action-name__foo__bar__baz", "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/typing/TypesProvidingTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt index d60cc1a3d2..829459bb1b 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 @@ -127,7 +127,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -164,7 +164,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -206,7 +206,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -248,7 +248,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -300,7 +300,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) @@ -352,7 +352,7 @@ class TypesProvidingTest : else -> throw IOException() } } - val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v6") + val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v6") // When val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) 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 78c1619546..ef76d4a5f4 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 } val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources() @@ -50,22 +46,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() 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..be6d99f278 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,67 +1,68 @@ package io.github.typesafegithub.workflows.mavenbinding -internal fun buildModuleFile( - owner: String, - name: String, - version: String, -): String = - """ - { - "formatVersion": "1.1", - "component": { - "group": "$owner", - "module": "$name", - "version": "$version", - "attributes": { - "org.gradle.status": "release" - } - }, - "createdBy": { - "gradle": { - "version": "8.7" - } - }, - "variants": [ +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords + +internal fun ActionCoords.buildModuleFile() = + run { + val name = name.replace("__", "/") + """ { - "name": "apiElements", - "attributes": { - "org.gradle.category": "library", - "org.gradle.dependency.bundling": "external", - "org.gradle.jvm.environment": "standard-jvm", - "org.gradle.jvm.version": 11, - "org.gradle.libraryelements": "jar", - "org.gradle.usage": "java-api", - "org.jetbrains.kotlin.platform.type": "jvm" + "formatVersion": "1.1", + "component": { + "group": "$owner", + "module": "$name", + "version": "$version", + "attributes": { + "org.gradle.status": "release" + } }, - "dependencies": [], - "files": [ - { - "name": "$name-$version.jar", - "url": "$name-$version.jar", - "size": 1 + "createdBy": { + "gradle": { + "version": "8.7" } - ] - }, - { - "name": "runtimeElements", - "attributes": { - "org.gradle.category": "library", - "org.gradle.dependency.bundling": "external", - "org.gradle.jvm.environment": "standard-jvm", - "org.gradle.jvm.version": 11, - "org.gradle.libraryelements": "jar", - "org.gradle.usage": "java-runtime", - "org.jetbrains.kotlin.platform.type": "jvm" }, - "dependencies": [], - "files": [ + "variants": [ + { + "name": "apiElements", + "attributes": { + "org.gradle.category": "library", + "org.gradle.dependency.bundling": "external", + "org.gradle.jvm.environment": "standard-jvm", + "org.gradle.jvm.version": 11, + "org.gradle.libraryelements": "jar", + "org.gradle.usage": "java-api", + "org.jetbrains.kotlin.platform.type": "jvm" + }, + "dependencies": [], + "files": [ + { + "name": "$name-$version.jar", + "url": "$name-$version.jar", + "size": 1 + } + ] + }, { - "name": "$name-$version.jar", - "url": "$name-$version.jar", - "size": 1 + "name": "runtimeElements", + "attributes": { + "org.gradle.category": "library", + "org.gradle.dependency.bundling": "external", + "org.gradle.jvm.environment": "standard-jvm", + "org.gradle.jvm.version": 11, + "org.gradle.libraryelements": "jar", + "org.gradle.usage": "java-runtime", + "org.jetbrains.kotlin.platform.type": "jvm" + }, + "dependencies": [], + "files": [ + { + "name": "$name-$version.jar", + "url": "$name-$version.jar", + "size": 1 + } + ] } ] } - ] + """.trimIndent() } - """.trimIndent() 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..6ae4eaf82a 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,13 +1,11 @@ package io.github.typesafegithub.workflows.mavenbinding +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords + internal const val LATEST_RELASED_LIBRARY_VERSION = "3.0.0" -internal fun buildPomFile( - owner: String, - name: String, - version: String, -): String { - val nameForRepo = name.substringBefore("/") +internal fun ActionCoords.buildPomFile(): String { + val nameForRepo = name.substringBefore("__") return """ 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 eb9800c4a4..58d2379237 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,9 +14,9 @@ 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()),