Skip to content

Commit c5fecae

Browse files
authored
feat: allow ignoring certain actions (#278)
The immediate motivation is being able to use this action within this very repo - there are some actions used in tests that don't have valid typings, so we need to ignore them.
1 parent 562787f commit c5fecae

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

action-types.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
inputs:
2+
ignored-action-files:
3+
type: list
4+
separator: "\n"
5+
list-item:
6+
type: string

action.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ branding:
77
runs:
88
using: 'docker'
99
image: 'Dockerfile'
10+
inputs:
11+
ignored-action-files:
12+
description: >
13+
Paths to 'action.y(a)ml' files that shouldn't be validated against their typings.
14+
The separator character is '/', regardless of the operating system.
15+
required: false

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ import it.krzeminski.githubactionstyping.reporting.appendStatus
55
import it.krzeminski.githubactionstyping.validation.ItemValidationResult
66
import java.nio.file.Path
77
import kotlin.io.path.exists
8+
import kotlin.io.path.invariantSeparatorsPathString
89
import kotlin.io.path.name
9-
import kotlin.io.path.nameWithoutExtension
10-
import kotlin.io.path.pathString
1110
import kotlin.io.path.walk
1211

1312
/**
1413
* Runs validation for a given action, with its manifest files present in the current directory.
1514
*
15+
* @param ignoredActionFiles: Paths to 'action.y(a)ml' files that shouldn't be validated against their typings.
16+
* The separator character is '/', regardless of the operating system.
1617
* @param repoRoot: Allows customizing which path should be taken as repo root for action(-types).y(a)ml file discovery.
1718
*
1819
* @return a pair where:
1920
* - the boolean means if the typings are valid
2021
* - the string is a printable report, with details about all inputs and outputs
2122
*/
22-
fun validateTypings(repoRoot: Path = Path.of(".")): Pair<Boolean, String> {
23+
fun validateTypings(
24+
ignoredActionFiles: List<String> = emptyList(),
25+
repoRoot: Path = Path.of("."),
26+
): Pair<Boolean, String> {
2327
require(repoRoot.exists()) { "The given repo root leads to non-existent dir: $repoRoot" }
2428

2529
val validationResultsForActions = repoRoot.walk()
2630
.sorted()
2731
.filter { it.name in setOf("action.yml", "action.yaml") }
32+
.filter { repoRoot.relativize(it).invariantSeparatorsPathString !in ignoredActionFiles }
2833
.map { manifestPath ->
2934
val manifest = repoRoot.readYamlFile(manifestPath.parent.resolve("action").toString())
3035
val typesManifest = repoRoot.readYamlFile(manifestPath.parent.resolve("action-types").toString())

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package it.krzeminski.githubactionstyping
33
import kotlin.system.exitProcess
44

55
fun main() {
6-
val (isValid, report) = validateTypings()
6+
val (isValid, report) = validateTypings(
7+
ignoredActionFiles = readIgnoredActionFiles(),
8+
)
79
println(report)
810

911
if (!isValid) {
1012
exitProcess(1)
1113
}
1214
}
15+
16+
private fun readIgnoredActionFiles(): List<String> =
17+
System.getenv("INPUT_IGNORED-ACTION-FILES")?.split("\n") ?: emptyList()

src/jvmTest/kotlin/it/krzeminski/githubactionstyping/LogicTest.kt

+32
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,38 @@ class LogicTest : FunSpec({
250250
}
251251
}
252252

253+
test("repo with top-level action with valid typings, and nested action with invalid typings that are ignored") {
254+
// When
255+
val (isValid, report) = validateTypings(
256+
repoRoot = testRepos.resolve("repo-with-top-level-and-nested-action-and-invalid-typings"),
257+
ignoredActionFiles = listOf("some/directory/action.yaml"),
258+
)
259+
260+
// Then
261+
assertSoftly {
262+
isValid shouldBe true
263+
report shouldBe """
264+
Overall result:
265+
✔ VALID
266+
267+
For action with manifest at 'action.yml':
268+
Result:
269+
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
270+
271+
Inputs:
272+
• verbose:
273+
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
274+
• someEnum:
275+
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
276+
277+
Outputs:
278+
None.
279+
280+
281+
""".trimIndent()
282+
}
283+
}
284+
253285
test("repo with only top-level action and no top-level manifest") {
254286
// When
255287
val (isValid, report) = validateTypings(

0 commit comments

Comments
 (0)