Skip to content

Commit 6fd7327

Browse files
committed
chore(abg): Unify content of ActionCoords name
1 parent 34e7d40 commit 6fd7327

File tree

10 files changed

+89
-111
lines changed

10 files changed

+89
-111
lines changed

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,26 @@ public data class ActionCoords(
1010
* A top-level action is an action with its `action.y(a)ml` file in the repository root, as opposed to actions stored
1111
* in subdirectories.
1212
*/
13-
public val ActionCoords.isTopLevel: Boolean get() = "/" !in name
13+
public val ActionCoords.isTopLevel: Boolean get() = "__" !in name
1414

15-
public val ActionCoords.prettyPrint: String get() = "$owner/$name@$version"
15+
public val ActionCoords.prettyPrint: String get() = "$owner/${
16+
name.replace("__", "/")
17+
}@$version"
1618

1719
/**
1820
* For most actions, it's the same as [ActionCoords.name].
1921
* For actions that aren't executed from the root of the repo, it returns the repo name.
2022
*/
2123
public val ActionCoords.repoName: String get() =
22-
name.substringBefore("/")
24+
name.substringBefore("__")
2325

2426
/**
2527
* For most actions, it's empty.
2628
* For actions that aren't executed from the root of the repo, it returns the path relative to the repo root where the
2729
* action lives.
2830
*/
2931
public val ActionCoords.subName: String get() =
30-
if (isTopLevel) "" else "/${name.substringAfter("/")}"
32+
if (isTopLevel) "" else "/${name.substringAfter("__").replace("__", "/")}"
3133

3234
internal fun String.toActionCoords(): ActionCoords {
3335
val (ownerAndName, version) = this.split('@')

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import com.squareup.kotlinpoet.buildCodeBlock
1818
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
1919
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
2020
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
21+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.isTopLevel
22+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName
23+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName
2124
import io.github.typesafegithub.workflows.actionbindinggenerator.generation.Properties.CUSTOM_INPUTS
2225
import io.github.typesafegithub.workflows.actionbindinggenerator.generation.Properties.CUSTOM_VERSION
2326
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Input
@@ -614,9 +617,7 @@ private fun actionKdoc(
614617
|
615618
|${metadata.description.escapedForComments.removeTrailingWhitespacesForEachLine()}
616619
|
617-
|[Action on GitHub](https://github.com/${coords.owner}/${coords.name.substringBefore(
618-
'/',
619-
)}${if ("/" in coords.name) "/tree/${coords.version}/${coords.name.substringAfter('/')}" else ""})
620+
|[Action on GitHub](https://github.com/${coords.owner}/${coords.repoName}${if (!coords.isTopLevel) "/tree/${coords.version}${coords.subName}" else ""})
620621
""".trimMargin()
621622

622623
private fun Map<String, Typing>?.getInputTyping(key: String) = this?.get(key) ?: StringTyping

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReading.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCo
55
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.CommitHash
66
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
77
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.NewestForVersion
8+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName
9+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName
810
import kotlinx.serialization.Serializable
911
import kotlinx.serialization.decodeFromString
1012
import java.io.IOException
@@ -35,15 +37,9 @@ public data class Output(
3537
val description: String = "",
3638
)
3739

38-
private fun ActionCoords.actionYmlUrl(gitRef: String) =
39-
"https://raw.githubusercontent.com/$owner/${name.substringBefore(
40-
'/',
41-
)}/$gitRef/${if ("/" in name) "${name.substringAfter('/')}/" else ""}action.yml"
40+
private fun ActionCoords.actionYmlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action.yml"
4241

43-
private fun ActionCoords.actionYamlUrl(gitRef: String) =
44-
"https://raw.githubusercontent.com/$owner/${name.substringBefore(
45-
'/',
46-
)}/$gitRef/${if ("/" in name) "${name.substringAfter('/')}/" else ""}action.yaml"
42+
private fun ActionCoords.actionYamlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action.yaml"
4743

4844
internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name"
4945

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/utils/TextUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal fun String.toPascalCase(): String {
77
val normalizedString = if (hasOnlyUppercases) lowercase() else this
88
return normalizedString
99
.replace("+", "-plus-")
10-
.split("-", "_", " ", ".", "/")
10+
.split("-", "_", " ", ".", "/", "__")
1111
.joinToString("") {
1212
it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
1313
}

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClassNamingTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class ClassNamingTest :
99
context("buildActionClassName") {
1010
listOf(
1111
ActionCoords("irrelevant", "some-action-name", "v2") to "SomeActionName",
12-
ActionCoords("irrelevant", "some-action-name/subaction", "v2") to "SomeActionNameSubaction",
13-
ActionCoords("irrelevant", "some-action-name/foo/bar/baz", "v2") to "SomeActionNameFooBarBaz",
12+
ActionCoords("irrelevant", "some-action-name__subaction", "v2") to "SomeActionNameSubaction",
13+
ActionCoords("irrelevant", "some-action-name__foo__bar__baz", "v2") to "SomeActionNameFooBarBaz",
1414
).forEach { (input, output) ->
1515
test("should get '$input' and produce '$output'") {
1616
input.buildActionClassName() shouldBe output

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class TypesProvidingTest :
127127
else -> throw IOException()
128128
}
129129
}
130-
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
130+
val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3")
131131

132132
// When
133133
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
@@ -164,7 +164,7 @@ class TypesProvidingTest :
164164
else -> throw IOException()
165165
}
166166
}
167-
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
167+
val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3")
168168

169169
// When
170170
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
@@ -206,7 +206,7 @@ class TypesProvidingTest :
206206
else -> throw IOException()
207207
}
208208
}
209-
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
209+
val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3")
210210

211211
// When
212212
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
@@ -248,7 +248,7 @@ class TypesProvidingTest :
248248
else -> throw IOException()
249249
}
250250
}
251-
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
251+
val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3")
252252

253253
// When
254254
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
@@ -300,7 +300,7 @@ class TypesProvidingTest :
300300
else -> throw IOException()
301301
}
302302
}
303-
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
303+
val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v3")
304304

305305
// When
306306
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
@@ -352,7 +352,7 @@ class TypesProvidingTest :
352352
else -> throw IOException()
353353
}
354354
}
355-
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v6")
355+
val actionCoord = ActionCoords("some-owner", "some-name__some-sub", "v6")
356356

357357
// When
358358
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ internal data class Jars(
2626
val sourcesJar: ByteArray,
2727
)
2828

29-
internal fun buildJars(
30-
owner: String,
31-
name: String,
32-
version: String,
33-
): Jars? {
29+
internal fun ActionCoords.buildJars(): Jars? {
3430
val binding =
35-
generateBinding(owner = owner, name = name, version = version).also {
31+
generateBinding(metadataRevision = NewestForVersion).also {
3632
if (it.isEmpty()) return null
3733
}
3834
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()
@@ -52,22 +48,6 @@ internal fun buildJars(
5248
)
5349
}
5450

55-
private fun generateBinding(
56-
owner: String,
57-
name: String,
58-
version: String,
59-
): List<ActionBinding> {
60-
val actionCoords =
61-
ActionCoords(
62-
owner = owner,
63-
name = name,
64-
version = version,
65-
)
66-
return actionCoords.generateBinding(
67-
metadataRevision = NewestForVersion,
68-
)
69-
}
70-
7151
private fun compileBinding(sourceFilePaths: List<Path>): Path {
7252
val compilationOutput = createTempDirectory(prefix = "gwkt-classes_")
7353

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ModuleBuilding.kt

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
11
package io.github.typesafegithub.workflows.mavenbinding
22

3-
internal fun buildModuleFile(
4-
owner: String,
5-
name: String,
6-
version: String,
7-
): String =
8-
"""
9-
{
10-
"formatVersion": "1.1",
11-
"component": {
12-
"group": "$owner",
13-
"module": "$name",
14-
"version": "$version",
15-
"attributes": {
16-
"org.gradle.status": "release"
17-
}
18-
},
19-
"createdBy": {
20-
"gradle": {
21-
"version": "8.7"
22-
}
23-
},
24-
"variants": [
3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
4+
5+
internal fun ActionCoords.buildModuleFile() =
6+
run {
7+
val name = name.replace("__", "/")
8+
"""
259
{
26-
"name": "apiElements",
27-
"attributes": {
28-
"org.gradle.category": "library",
29-
"org.gradle.dependency.bundling": "external",
30-
"org.gradle.jvm.environment": "standard-jvm",
31-
"org.gradle.jvm.version": 11,
32-
"org.gradle.libraryelements": "jar",
33-
"org.gradle.usage": "java-api",
34-
"org.jetbrains.kotlin.platform.type": "jvm"
10+
"formatVersion": "1.1",
11+
"component": {
12+
"group": "$owner",
13+
"module": "$name",
14+
"version": "$version",
15+
"attributes": {
16+
"org.gradle.status": "release"
17+
}
3518
},
36-
"dependencies": [],
37-
"files": [
38-
{
39-
"name": "$name-$version.jar",
40-
"url": "$name-$version.jar",
41-
"size": 1
19+
"createdBy": {
20+
"gradle": {
21+
"version": "8.7"
4222
}
43-
]
44-
},
45-
{
46-
"name": "runtimeElements",
47-
"attributes": {
48-
"org.gradle.category": "library",
49-
"org.gradle.dependency.bundling": "external",
50-
"org.gradle.jvm.environment": "standard-jvm",
51-
"org.gradle.jvm.version": 11,
52-
"org.gradle.libraryelements": "jar",
53-
"org.gradle.usage": "java-runtime",
54-
"org.jetbrains.kotlin.platform.type": "jvm"
5523
},
56-
"dependencies": [],
57-
"files": [
24+
"variants": [
25+
{
26+
"name": "apiElements",
27+
"attributes": {
28+
"org.gradle.category": "library",
29+
"org.gradle.dependency.bundling": "external",
30+
"org.gradle.jvm.environment": "standard-jvm",
31+
"org.gradle.jvm.version": 11,
32+
"org.gradle.libraryelements": "jar",
33+
"org.gradle.usage": "java-api",
34+
"org.jetbrains.kotlin.platform.type": "jvm"
35+
},
36+
"dependencies": [],
37+
"files": [
38+
{
39+
"name": "$name-$version.jar",
40+
"url": "$name-$version.jar",
41+
"size": 1
42+
}
43+
]
44+
},
5845
{
59-
"name": "$name-$version.jar",
60-
"url": "$name-$version.jar",
61-
"size": 1
46+
"name": "runtimeElements",
47+
"attributes": {
48+
"org.gradle.category": "library",
49+
"org.gradle.dependency.bundling": "external",
50+
"org.gradle.jvm.environment": "standard-jvm",
51+
"org.gradle.jvm.version": 11,
52+
"org.gradle.libraryelements": "jar",
53+
"org.gradle.usage": "java-runtime",
54+
"org.jetbrains.kotlin.platform.type": "jvm"
55+
},
56+
"dependencies": [],
57+
"files": [
58+
{
59+
"name": "$name-$version.jar",
60+
"url": "$name-$version.jar",
61+
"size": 1
62+
}
63+
]
6264
}
6365
]
6466
}
65-
]
67+
""".trimIndent()
6668
}
67-
""".trimIndent()

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/PomBuilding.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package io.github.typesafegithub.workflows.mavenbinding
22

3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
4+
35
internal const val LATEST_RELASED_LIBRARY_VERSION = "3.0.0"
46

5-
internal fun buildPomFile(
6-
owner: String,
7-
name: String,
8-
version: String,
9-
): String {
10-
val nameForRepo = name.substringBefore("/")
7+
internal fun ActionCoords.buildPomFile(): String {
8+
val nameForRepo = name.substringBefore("__")
119
return """
1210
<?xml version="1.0" encoding="UTF-8"?>
1311
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ data class JarArtifact(
1414
) : Artifact
1515

1616
fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact>? {
17-
val jars = buildJars(owner = owner, name = name.replace("__", "/"), version = version) ?: return null
18-
val pom = buildPomFile(owner = owner, name = name.replace("__", "/"), version = version)
19-
val module = buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version)
17+
val jars = buildJars() ?: return null
18+
val pom = buildPomFile()
19+
val module = buildModuleFile()
2020
return mapOf(
2121
"$name-$version.jar" to JarArtifact(jars.mainJar),
2222
"$name-$version.jar.md5" to TextArtifact(jars.mainJar.md5Checksum()),

0 commit comments

Comments
 (0)