Skip to content

Commit 6f967d4

Browse files
committed
chore(abg): Unify content of ActionCoords name
1 parent 2118339 commit 6f967d4

File tree

8 files changed

+30
-50
lines changed

8 files changed

+30
-50
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/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()
@@ -50,22 +46,6 @@ internal fun buildJars(
5046
)
5147
}
5248

53-
private fun generateBinding(
54-
owner: String,
55-
name: String,
56-
version: String,
57-
): List<ActionBinding> {
58-
val actionCoords =
59-
ActionCoords(
60-
owner = owner,
61-
name = name,
62-
version = version,
63-
)
64-
return actionCoords.generateBinding(
65-
metadataRevision = NewestForVersion,
66-
)
67-
}
68-
6949
private fun compileBinding(sourceFilePaths: List<Path>): Path {
7050
val compilationOutput = createTempDirectory()
7151

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

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

3-
internal fun buildModuleFile(
4-
owner: String,
5-
name: String,
6-
version: String,
7-
): String =
8-
"""
3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
4+
5+
internal fun ActionCoords.buildModuleFile(): String {
6+
val name = name.replace("__", "/")
7+
return """
98
{
109
"formatVersion": "1.1",
1110
"component": {
@@ -65,3 +64,4 @@ internal fun buildModuleFile(
6564
]
6665
}
6766
""".trimIndent()
67+
}

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)