Skip to content

Commit 3572dc3

Browse files
committed
fix(abg): do not use double slash for top-level action URL
1 parent 0f0812e commit 3572dc3

File tree

3 files changed

+137
-12
lines changed

3 files changed

+137
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public val ActionCoords.repoName: String get() =
2727
* action lives.
2828
*/
2929
public val ActionCoords.subName: String get() =
30-
if (isTopLevel) "" else name.substringAfter("/")
30+
if (isTopLevel) "" else "/${name.substringAfter("/")}"
3131

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

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ internal fun ActionCoords.provideTypes(
2929
?: Pair(emptyMap(), null)
3030

3131
private fun ActionCoords.actionTypesYmlUrl(gitRef: String) =
32-
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef/$subName/action-types.yml"
32+
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action-types.yml"
3333

3434
private fun ActionCoords.actionTypesFromCatalog() =
3535
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
36-
"main/typings/$owner/$repoName/$version/$subName/action-types.yml"
36+
"main/typings/$owner/$repoName/$version$subName/action-types.yml"
3737

3838
private fun ActionCoords.catalogMetadata() =
3939
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
4040
"main/typings/$owner/$repoName/metadata.yml"
4141

4242
private fun ActionCoords.actionTypesYamlUrl(gitRef: String) =
43-
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef/$subName/action-types.yaml"
43+
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action-types.yaml"
4444

4545
private fun ActionCoords.fetchTypingMetadata(
4646
metadataRevision: MetadataRevision,

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

Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class TypesProvidingTest :
103103
// Given
104104
val fetchUri: (URI) -> String = {
105105
when (it) {
106-
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml
106+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> hostedByActionYml
107107
else -> throw IOException()
108108
}
109109
}
@@ -116,11 +116,28 @@ class TypesProvidingTest :
116116
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
117117
}
118118

119+
test("only hosted by the subaction (.yml)") {
120+
// Given
121+
val fetchUri: (URI) -> String = {
122+
when (it) {
123+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yml") -> hostedByActionYml
124+
else -> throw IOException()
125+
}
126+
}
127+
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
128+
129+
// When
130+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
131+
132+
// Then
133+
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
134+
}
135+
119136
test("only hosted by the action (.yaml)") {
120137
// Given
121138
val fetchUri: (URI) -> String = {
122139
when (it) {
123-
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml
140+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yaml") -> hostedByActionYaml
124141
else -> throw IOException()
125142
}
126143
}
@@ -133,12 +150,29 @@ class TypesProvidingTest :
133150
types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION)
134151
}
135152

153+
test("only hosted by the subaction (.yaml)") {
154+
// Given
155+
val fetchUri: (URI) -> String = {
156+
when (it) {
157+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yaml") -> hostedByActionYaml
158+
else -> throw IOException()
159+
}
160+
}
161+
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
162+
163+
// When
164+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
165+
166+
// Then
167+
types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION)
168+
}
169+
136170
test("only hosted by the action, both extensions") {
137171
// Given
138172
val fetchUri: (URI) -> String = {
139173
when (it) {
140-
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml
141-
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml
174+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> hostedByActionYml
175+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yaml") -> hostedByActionYaml
142176
else -> throw IOException()
143177
}
144178
}
@@ -151,13 +185,31 @@ class TypesProvidingTest :
151185
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
152186
}
153187

188+
test("only hosted by the subaction, both extensions") {
189+
// Given
190+
val fetchUri: (URI) -> String = {
191+
when (it) {
192+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yml") -> hostedByActionYml
193+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yaml") -> hostedByActionYaml
194+
else -> throw IOException()
195+
}
196+
}
197+
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
198+
199+
// When
200+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
201+
202+
// Then
203+
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
204+
}
205+
154206
test("only stored in typing catalog") {
155207
// Given
156208
val fetchUri: (URI) -> String = {
157209
when (it) {
158210
URI(
159211
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
160-
"main/typings/some-owner/some-name/v3//action-types.yml",
212+
"main/typings/some-owner/some-name/v3/action-types.yml",
161213
),
162214
-> storedInTypingCatalog
163215
else -> throw IOException()
@@ -172,18 +224,39 @@ class TypesProvidingTest :
172224
types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG)
173225
}
174226

227+
test("only stored in typing catalog for subaction") {
228+
// Given
229+
val fetchUri: (URI) -> String = {
230+
when (it) {
231+
URI(
232+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
233+
"main/typings/some-owner/some-name/v3/some-sub/action-types.yml",
234+
),
235+
-> storedInTypingCatalog
236+
else -> throw IOException()
237+
}
238+
}
239+
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
240+
241+
// When
242+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
243+
244+
// Then
245+
types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG)
246+
}
247+
175248
test("hosted by action and stored in typing catalog") {
176249
// Given
177250
val fetchUri: (URI) -> String = {
178251
when (it) {
179252
URI(
180253
"https://raw.githubusercontent.com/some-owner/some-name/" +
181-
"some-hash//action-types.yml",
254+
"some-hash/action-types.yml",
182255
),
183256
-> hostedByActionYml
184257
URI(
185258
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
186-
"main/typings/some-owner/some-name/v3//action-types.yml",
259+
"main/typings/some-owner/some-name/v3/action-types.yml",
187260
),
188261
-> storedInTypingCatalog
189262
else -> throw IOException()
@@ -198,6 +271,32 @@ class TypesProvidingTest :
198271
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
199272
}
200273

274+
test("hosted by subaction and stored in typing catalog") {
275+
// Given
276+
val fetchUri: (URI) -> String = {
277+
when (it) {
278+
URI(
279+
"https://raw.githubusercontent.com/some-owner/some-name/" +
280+
"some-hash/some-sub/action-types.yml",
281+
),
282+
-> hostedByActionYml
283+
URI(
284+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
285+
"main/typings/some-owner/some-name/v3/some-sub/action-types.yml",
286+
),
287+
-> storedInTypingCatalog
288+
else -> throw IOException()
289+
}
290+
}
291+
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")
292+
293+
// When
294+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
295+
296+
// Then
297+
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
298+
}
299+
201300
test("only stored in typing catalog for older version") {
202301
// Given
203302
val fetchUri: (URI) -> String = {
@@ -209,7 +308,7 @@ class TypesProvidingTest :
209308
-> metadata
210309
URI(
211310
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
212-
"main/typings/some-owner/some-name/v4//action-types.yml",
311+
"main/typings/some-owner/some-name/v4/action-types.yml",
213312
),
214313
-> storedInTypingCatalogForOlderVersion
215314
else -> throw IOException()
@@ -224,6 +323,32 @@ class TypesProvidingTest :
224323
types shouldBe Pair(mapOf("stored-in-typing-catalog-for-older-version" to StringTyping), TypingActualSource.TYPING_CATALOG)
225324
}
226325

326+
test("only stored in typing catalog for older version of subaction") {
327+
// Given
328+
val fetchUri: (URI) -> String = {
329+
when (it) {
330+
URI(
331+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
332+
"main/typings/some-owner/some-name/metadata.yml",
333+
),
334+
-> metadata
335+
URI(
336+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
337+
"main/typings/some-owner/some-name/v4/some-sub/action-types.yml",
338+
),
339+
-> storedInTypingCatalogForOlderVersion
340+
else -> throw IOException()
341+
}
342+
}
343+
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v6")
344+
345+
// When
346+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
347+
348+
// Then
349+
types shouldBe Pair(mapOf("stored-in-typing-catalog-for-older-version" to StringTyping), TypingActualSource.TYPING_CATALOG)
350+
}
351+
227352
test("metadata available but no version available") {
228353
// Given
229354
val fetchUri: (URI) -> String = {

0 commit comments

Comments
 (0)