From 3572dc3f7dcfa8bf837ac9d4c9ef1f3370c2b351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Fri, 16 Aug 2024 12:06:04 +0200 Subject: [PATCH] fix(abg): do not use double slash for top-level action URL --- .../domain/ActionCoords.kt | 2 +- .../typing/TypesProviding.kt | 6 +- .../typing/TypesProvidingTest.kt | 141 +++++++++++++++++- 3 files changed, 137 insertions(+), 12 deletions(-) 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 85d6cc0c39..6650508de2 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 @@ -27,7 +27,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("/")}" internal fun String.toActionCoords(): ActionCoords { val (ownerAndName, version) = this.split('@') 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 cf780d44c1..56aeb5b3e2 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 @@ -29,18 +29,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/$repoName/$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/$repoName/$version$subName/action-types.yml" private fun ActionCoords.catalogMetadata() = "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + "main/typings/$owner/$repoName/metadata.yml" private fun ActionCoords.actionTypesYamlUrl(gitRef: String) = - "https://raw.githubusercontent.com/$owner/$repoName/$gitRef/$subName/action-types.yaml" + "https://raw.githubusercontent.com/$owner/$repoName/$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/typing/TypesProvidingTest.kt b/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt index dee642037b..ebb9a6f8b2 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 @@ -103,7 +103,7 @@ class TypesProvidingTest : // Given val fetchUri: (URI) -> String = { when (it) { - URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> hostedByActionYml else -> throw IOException() } } @@ -116,11 +116,28 @@ class TypesProvidingTest : types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION) } + test("only hosted by the subaction (.yml)") { + // Given + val fetchUri: (URI) -> String = { + when (it) { + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yml") -> hostedByActionYml + else -> throw IOException() + } + } + val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + + // When + val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) + + // Then + types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION) + } + test("only hosted by the action (.yaml)") { // Given val fetchUri: (URI) -> String = { when (it) { - URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yaml") -> hostedByActionYaml else -> throw IOException() } } @@ -133,12 +150,29 @@ class TypesProvidingTest : types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION) } + test("only hosted by the subaction (.yaml)") { + // Given + val fetchUri: (URI) -> String = { + when (it) { + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yaml") -> hostedByActionYaml + else -> throw IOException() + } + } + val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + + // When + val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) + + // Then + types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION) + } + test("only hosted by the action, both extensions") { // Given val fetchUri: (URI) -> String = { when (it) { - URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml - URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> hostedByActionYml + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yaml") -> hostedByActionYaml else -> throw IOException() } } @@ -151,13 +185,31 @@ class TypesProvidingTest : types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION) } + test("only hosted by the subaction, both extensions") { + // Given + val fetchUri: (URI) -> String = { + when (it) { + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yml") -> hostedByActionYml + URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yaml") -> hostedByActionYaml + else -> throw IOException() + } + } + val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + + // When + val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) + + // Then + types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION) + } + test("only stored in typing catalog") { // Given val fetchUri: (URI) -> String = { when (it) { URI( "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + - "main/typings/some-owner/some-name/v3//action-types.yml", + "main/typings/some-owner/some-name/v3/action-types.yml", ), -> storedInTypingCatalog else -> throw IOException() @@ -172,18 +224,39 @@ class TypesProvidingTest : types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG) } + test("only stored in typing catalog for subaction") { + // Given + val fetchUri: (URI) -> String = { + when (it) { + URI( + "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + + "main/typings/some-owner/some-name/v3/some-sub/action-types.yml", + ), + -> storedInTypingCatalog + else -> throw IOException() + } + } + val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + + // When + val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) + + // Then + types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG) + } + test("hosted by action and stored in typing catalog") { // Given val fetchUri: (URI) -> String = { when (it) { URI( "https://raw.githubusercontent.com/some-owner/some-name/" + - "some-hash//action-types.yml", + "some-hash/action-types.yml", ), -> hostedByActionYml URI( "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + - "main/typings/some-owner/some-name/v3//action-types.yml", + "main/typings/some-owner/some-name/v3/action-types.yml", ), -> storedInTypingCatalog else -> throw IOException() @@ -198,6 +271,32 @@ class TypesProvidingTest : types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION) } + test("hosted by subaction and stored in typing catalog") { + // Given + val fetchUri: (URI) -> String = { + when (it) { + URI( + "https://raw.githubusercontent.com/some-owner/some-name/" + + "some-hash/some-sub/action-types.yml", + ), + -> hostedByActionYml + URI( + "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + + "main/typings/some-owner/some-name/v3/some-sub/action-types.yml", + ), + -> storedInTypingCatalog + else -> throw IOException() + } + } + val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3") + + // When + val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) + + // Then + types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION) + } + test("only stored in typing catalog for older version") { // Given val fetchUri: (URI) -> String = { @@ -209,7 +308,7 @@ class TypesProvidingTest : -> metadata URI( "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + - "main/typings/some-owner/some-name/v4//action-types.yml", + "main/typings/some-owner/some-name/v4/action-types.yml", ), -> storedInTypingCatalogForOlderVersion else -> throw IOException() @@ -224,6 +323,32 @@ class TypesProvidingTest : types shouldBe Pair(mapOf("stored-in-typing-catalog-for-older-version" to StringTyping), TypingActualSource.TYPING_CATALOG) } + test("only stored in typing catalog for older version of subaction") { + // Given + val fetchUri: (URI) -> String = { + when (it) { + URI( + "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + + "main/typings/some-owner/some-name/metadata.yml", + ), + -> metadata + URI( + "https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" + + "main/typings/some-owner/some-name/v4/some-sub/action-types.yml", + ), + -> storedInTypingCatalogForOlderVersion + else -> throw IOException() + } + } + val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v6") + + // When + val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri) + + // Then + types shouldBe Pair(mapOf("stored-in-typing-catalog-for-older-version" to StringTyping), TypingActualSource.TYPING_CATALOG) + } + test("metadata available but no version available") { // Given val fetchUri: (URI) -> String = {