Skip to content

Commit c7e8e3a

Browse files
committed
refactor: move checking existence of manifests to manifestsToReport
1 parent 2838cd6 commit c7e8e3a

File tree

3 files changed

+93
-17
lines changed

3 files changed

+93
-17
lines changed

src/jvmMain/kotlin/it/krzeminski/githubactionstyping/Logic.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import kotlin.io.path.exists
1515
*/
1616
fun validateTypings(repoRoot: Path = Path.of(".")): Pair<Boolean, String> {
1717
require(repoRoot.exists()) { "The given repo root leads to non-existent dir: $repoRoot" }
18-
val (manifest, manifestPath) = repoRoot.readYamlFile("action") ?:
19-
return Pair(false, "No action manifest (action.yml or action.yaml) found!")
18+
val manifestAndPath: Pair<String, Path>? = repoRoot.readYamlFile("action")
19+
val typesManifestAndPath: Pair<String, Path>? = repoRoot.readYamlFile("action-types")
2020

21-
val (typesManifest, _) = repoRoot.readYamlFile("action-types") ?:
22-
return Pair(false, "No types manifest (action-types.yml or action-types.yaml) found!")
23-
24-
return manifestsToReport(repoRoot.relativize(manifestPath), manifest, typesManifest)
21+
return manifestsToReport(
22+
manifestAndPath = manifestAndPath?.let { Pair(it.first, repoRoot.relativize(it.second)) },
23+
typesManifest = typesManifestAndPath?.first,
24+
)
2525
}

src/jvmMain/kotlin/it/krzeminski/githubactionstyping/ManifestsToReport.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ import it.krzeminski.githubactionstyping.validation.buildInputOutputMismatchVali
99
import it.krzeminski.githubactionstyping.validation.validate
1010
import java.nio.file.Path
1111

12-
fun manifestsToReport(manifestPath: Path, manifest: String, typesManifest: String): Pair<Boolean, String> {
12+
fun manifestsToReport(manifestAndPath: Pair<String, Path>?, typesManifest: String?): Pair<Boolean, String> {
13+
if (manifestAndPath == null) {
14+
return Pair(false, "No action manifest (action.yml or action.yaml) found!")
15+
}
16+
17+
if (typesManifest == null) {
18+
return Pair(false, "No types manifest (action-types.yml or action-types.yaml) found!")
19+
}
20+
1321
val parsedTypesManifest = if (typesManifest.isNotBlank()) {
1422
parseTypesManifest(typesManifest)
1523
} else {
1624
TypesManifest()
1725
}
18-
val parsedManifest = parseManifest(manifest)
26+
val parsedManifest = parseManifest(manifestAndPath.first)
1927

2028
val inputsInTypesManifest = parsedTypesManifest.inputs.keys
2129
val inputsInManifest = parsedManifest.inputs.keys
@@ -25,7 +33,7 @@ fun manifestsToReport(manifestPath: Path, manifest: String, typesManifest: Strin
2533

2634
if (inputsInManifest != inputsInTypesManifest || outputsInManifest != outputsInTypesManifest) {
2735
val inputOutputMismatchValidationResult = buildInputOutputMismatchValidationResult(
28-
manifestPath = manifestPath,
36+
manifestPath = manifestAndPath.second,
2937
inputsInManifest = inputsInManifest,
3038
inputsInTypesManifest = inputsInTypesManifest,
3139
outputsInManifest = outputsInManifest,
@@ -35,7 +43,7 @@ fun manifestsToReport(manifestPath: Path, manifest: String, typesManifest: Strin
3543
}
3644

3745
printlnDebug("Action's manifest:")
38-
printlnDebug(manifest)
46+
printlnDebug(manifestAndPath.first)
3947

4048
printlnDebug("Parsed manifest:")
4149
printlnDebug(parsedManifest)
@@ -50,7 +58,7 @@ fun manifestsToReport(manifestPath: Path, manifest: String, typesManifest: Strin
5058
printlnDebug("==============================================")
5159
printlnDebug()
5260

53-
val validationResult = parsedTypesManifest.validate(manifestPath)
61+
val validationResult = parsedTypesManifest.validate(manifestAndPath.second)
5462
val isValid = validationResult.overallResult is ItemValidationResult.Valid
5563
val report = validationResult.toPlaintextReport()
5664

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

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ManifestsToReportTest : FunSpec({
3737
""".trimIndent()
3838

3939
// when
40-
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
40+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), typesManifest)
4141

4242
// then
4343
assertSoftly {
@@ -97,7 +97,7 @@ class ManifestsToReportTest : FunSpec({
9797
""".trimIndent()
9898

9999
// when
100-
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
100+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), typesManifest)
101101

102102
// then
103103
assertSoftly {
@@ -136,7 +136,7 @@ class ManifestsToReportTest : FunSpec({
136136
val typesManifest = " "
137137

138138
// when
139-
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
139+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), typesManifest)
140140

141141
// then
142142
assertSoftly {
@@ -170,7 +170,7 @@ class ManifestsToReportTest : FunSpec({
170170
val typesManifest = "#"
171171

172172
// when
173-
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
173+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), typesManifest)
174174

175175
// then
176176
assertSoftly {
@@ -218,7 +218,7 @@ class ManifestsToReportTest : FunSpec({
218218
""".trimIndent()
219219

220220
// when
221-
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
221+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), typesManifest)
222222

223223
// then
224224
assertSoftly {
@@ -278,7 +278,7 @@ class ManifestsToReportTest : FunSpec({
278278
""".trimIndent()
279279

280280
// when
281-
val (isValid, report) = manifestsToReport(Path("action.yml"), manifest, typesManifest)
281+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), typesManifest)
282282

283283
// then
284284
assertSoftly {
@@ -308,4 +308,72 @@ class ManifestsToReportTest : FunSpec({
308308
""".trimIndent()
309309
}
310310
}
311+
312+
test("no action manifest") {
313+
// when
314+
val typesManifest = """
315+
inputs:
316+
foo:
317+
type: boolean
318+
baz:
319+
type: enum
320+
allowed-values:
321+
- foo
322+
- bar
323+
outputs:
324+
goo:
325+
type: boolean
326+
boo:
327+
type: enum
328+
""".trimIndent()
329+
330+
// when
331+
val (isValid, report) = manifestsToReport(null, typesManifest)
332+
333+
// then
334+
assertSoftly {
335+
isValid shouldBe false
336+
report shouldBe "No action manifest (action.yml or action.yaml) found!"
337+
}
338+
}
339+
340+
test("no types manifest") {
341+
// when
342+
val manifest = """
343+
name: GitHub Actions Typing
344+
description: Bring type-safety to your GitHub actions' API!
345+
author: Piotr Krzemiński
346+
inputs:
347+
verbose:
348+
description: 'Set to true to display debug information helpful when troubleshooting issues with this action.'
349+
required: false
350+
default: 'false'
351+
someEnum:
352+
description: 'Testing enum'
353+
required: false
354+
runs:
355+
using: 'docker'
356+
image: 'Dockerfile'
357+
""".trimIndent()
358+
359+
// when
360+
val (isValid, report) = manifestsToReport(Pair(manifest, Path("action.yml")), null)
361+
362+
// then
363+
assertSoftly {
364+
isValid shouldBe false
365+
report shouldBe "No types manifest (action-types.yml or action-types.yaml) found!"
366+
}
367+
}
368+
369+
test("no action manifest and types manifest") {
370+
// when
371+
val (isValid, report) = manifestsToReport(null, null)
372+
373+
// then
374+
assertSoftly {
375+
isValid shouldBe false
376+
report shouldBe "No action manifest (action.yml or action.yaml) found!"
377+
}
378+
}
311379
})

0 commit comments

Comments
 (0)