Skip to content

Commit 10649a1

Browse files
authored
fix: properly handle types manifest with only comments (#241)
1 parent 3e8ef3e commit 10649a1

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main/kotlin/it/krzeminski/githubactionstyping/parsing/TypesManifestParsing.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package it.krzeminski.githubactionstyping.parsing
22

3+
import com.charleskorn.kaml.EmptyYamlDocumentException
34
import com.charleskorn.kaml.Yaml
45
import kotlinx.serialization.SerialName
56
import kotlinx.serialization.Serializable
@@ -32,4 +33,11 @@ private val myYaml = Yaml(
3233
)
3334

3435
fun parseTypesManifest(manifestString: String): TypesManifest =
35-
myYaml.decodeFromString(manifestString)
36+
runCatching {
37+
myYaml.decodeFromString<TypesManifest>(manifestString)
38+
}.getOrElse {
39+
if (it is EmptyYamlDocumentException) {
40+
return TypesManifest()
41+
}
42+
throw it
43+
}

src/test/kotlin/it/krzeminski/githubactionstyping/validation/ManifestsToReportTest.kt

+34
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,40 @@ class ManifestsToReportTest : FunSpec({
157157
}
158158
}
159159

160+
test("comment-only types YAML") {
161+
// when
162+
val manifest = """
163+
name: GitHub Actions Typing
164+
description: Bring type-safety to your GitHub actions' API!
165+
author: Piotr Krzemiński
166+
runs:
167+
using: 'docker'
168+
image: 'Dockerfile'
169+
""".trimIndent()
170+
val typesManifest = "#"
171+
172+
// when
173+
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
174+
175+
// then
176+
assertSoftly {
177+
isValid shouldBe true
178+
report shouldBe """
179+
For action with manifest at 'action.yml':
180+
Result:
181+
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
182+
183+
Inputs:
184+
None.
185+
186+
Outputs:
187+
None.
188+
189+
190+
""".trimIndent()
191+
}
192+
}
193+
160194
test("enum: missing allowed values") {
161195
// when
162196
val manifest = """

0 commit comments

Comments
 (0)