From d4948617c27ee2e6d633bdfd1fd20e6d4831b7c2 Mon Sep 17 00:00:00 2001 From: Piotr Krzeminski Date: Sat, 21 Nov 2026 14:35:04 +0100 Subject: [PATCH 1/3] Extract action coordinate parsing into a helper --- .github/workflows/test.main.kts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.main.kts b/.github/workflows/test.main.kts index 14461d7..cbe65e1 100755 --- a/.github/workflows/test.main.kts +++ b/.github/workflows/test.main.kts @@ -323,19 +323,21 @@ private fun listActionVersionsToValidate(sha: String, baseRef: String?): Stream< } else { println("Only validating changed typings") listAffectedActionManifestFiles(sha = sha, baseRef = baseRef) - }.map { - val (_, owner, name, version, pathAndYaml) = it.invariantSeparatorsPathString.split("/", limit = 5) - val path = if ("/" in pathAndYaml) pathAndYaml.substringBeforeLast("/") else null - ActionCoords( - owner = owner, - name = name, - version = version, - path = path, - pathToTypings = it.invariantSeparatorsPathString, - ) - } + }.map { it.toActionCoords() } } +private fun Path.toActionCoords(): ActionCoords { + val (_, owner, name, version, pathAndYaml) = invariantSeparatorsPathString.split("/", limit = 5) + val path = if ("/" in pathAndYaml) pathAndYaml.substringBeforeLast("/") else null + return ActionCoords( + owner = owner, + name = name, + version = version, + path = path, + pathToTypings = invariantSeparatorsPathString, + ) +} + private fun listAllActionManifestFilesInRepo(): Stream { val actionsWithYamlExtension = Files.walk(Path("typings")) .filter { it.name == "action-types.yaml" } From fe59790a6f3167842a689f59e8a6dd347334d11d Mon Sep 17 00:00:00 2001 From: Piotr Krzeminski Date: Sat, 21 Nov 2026 14:35:32 +0100 Subject: [PATCH 2/3] Add a helper for reading input/output names --- .github/workflows/test.main.kts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.main.kts b/.github/workflows/test.main.kts index cbe65e1..8a28641 100755 --- a/.github/workflows/test.main.kts +++ b/.github/workflows/test.main.kts @@ -203,8 +203,8 @@ private fun validateTypings(sha: String, baseRef: String?) { continue } - val typingsInputs = if ("inputs" in typings) (typings["inputs"] as Map).keys else emptySet() - val typingsOutputs = if ("outputs" in typings) (typings["outputs"] as Map).keys else emptySet() + val typingsInputs = typings.names("inputs") + val typingsOutputs = typings.names("outputs") val manifest = fetchManifest(action) if (manifest == null) { @@ -213,8 +213,8 @@ private fun validateTypings(sha: String, baseRef: String?) { continue } - val manifestInputs = if ("inputs" in manifest) (manifest["inputs"] as Map).keys else emptySet() - val manifestOutputs = if ("outputs" in manifest) (manifest["outputs"] as Map).keys else emptySet() + val manifestInputs = manifest.names("inputs") + val manifestOutputs = manifest.names("outputs") fun logTypeInferences(section: String, names: Set, includeInputName: Boolean) { names.forEach { name -> @@ -418,6 +418,9 @@ private fun formatTypingValue(value: Any?): String = when (value) { else -> value?.toString()?.replace("\n", "\\n") ?: "n/a" } +private fun Map<*, *>.names(section: String): Set = + (this[section] as? Map<*, *>)?.keys?.map { it.toString() }?.toSet() ?: emptySet() + private fun fetchManifest(action: ActionCoords): Map? { val list = listOf(action.actionYmlUrl, action.actionYamlUrl) From ff81ba50c00d0f5acccbb26f590386410318b7d3 Mon Sep 17 00:00:00 2001 From: Piotr Krzeminski Date: Sat, 21 Nov 2026 14:36:07 +0100 Subject: [PATCH 3/3] Return structured typing inferences from comparison --- .github/workflows/test.main.kts | 71 ++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test.main.kts b/.github/workflows/test.main.kts index 8a28641..66bedba 100755 --- a/.github/workflows/test.main.kts +++ b/.github/workflows/test.main.kts @@ -159,6 +159,16 @@ private data class TypingDifference( val extraOutputsInTypings: Set, ) +private data class TypingInference( + val section: String, + val name: String, + val actual: Map, + val inferred: Map, + val reason: String?, +) { + val isMismatch: Boolean get() = actual != inferred +} + private fun validateTypings(sha: String, baseRef: String?) { val typingsSchema = JsonSchema.fromDefinition( URI.create("https://raw.githubusercontent.com/typesafegithub/github-actions-typing/" + @@ -216,31 +226,17 @@ private fun validateTypings(sha: String, baseRef: String?) { val manifestInputs = manifest.names("inputs") val manifestOutputs = manifest.names("outputs") - fun logTypeInferences(section: String, names: Set, includeInputName: Boolean) { - names.forEach { name -> - val inference = TypingHeuristics.inferType( - manifest.definition(section, name), - if (includeInputName) name else null, - ) - val actualTyping: Map<*, *> = - (typings.definition(section, name) as? Map<*, *>) ?: emptyMap() - val inferredTyping: Map<*, *> = inference.toTypingMap() - val warning = if (actualTyping == inferredTyping) "" else "\u26A0\uFE0F " - val reason = inference.reason?.let { " ($it)" } ?: "" - val label = if (section == "inputs") "Input" else "Output" - println( - " ${warning}$label `$name`: actual `${formatTyping(actualTyping)}`, " + - "inferred `${formatTyping(inferredTyping)}`$reason" - ) - } + val inferences = compareTypings(typings, manifest) + inferences.forEach { inference -> + val warning = if (inference.isMismatch) "\u26A0\uFE0F " else "" + val reason = inference.reason?.let { " ($it)" } ?: "" + val label = if (inference.section == "inputs") "Input" else "Output" + println( + " ${warning}$label `${inference.name}`: actual `${formatTyping(inference.actual)}`, " + + "inferred `${formatTyping(inference.inferred)}`$reason" + ) } - // Input names feed boolean heuristics (e.g. `skip-cache`). Outputs have names too, but - // update-typings.main.kts currently omits passing them - that's a bug there. Mirror it for now - // so validation agrees with what the update workflow would actually generate. - logTypeInferences("inputs", manifestInputs, includeInputName = true) - logTypeInferences("outputs", manifestOutputs, includeInputName = false) - if (typingsInputs != manifestInputs || typingsOutputs != manifestOutputs) { println("\uD83D\uDD34 Something is wrong with the typings!") @@ -421,6 +417,35 @@ private fun formatTypingValue(value: Any?): String = when (value) { private fun Map<*, *>.names(section: String): Set = (this[section] as? Map<*, *>)?.keys?.map { it.toString() }?.toSet() ?: emptySet() +private fun compareTypings(typings: Map<*, *>, manifest: Map<*, *>): List = + // Input names feed boolean heuristics (e.g. `skip-cache`). Outputs have names too, but + // update-typings.main.kts currently omits passing them - that's a bug there. Mirror it for now + // so validation agrees with what the update workflow would actually generate. + listOf("inputs" to true, "outputs" to false).flatMap { (section, includeName) -> + manifest.names(section).map { name -> + val inference = TypingHeuristics.inferType( + manifest.definition(section, name), + if (includeName) name else null, + ) + TypingInference( + section = section, + name = name, + actual = (typings.definition(section, name) as? Map<*, *>)?.asTypingMap() ?: emptyMap(), + inferred = inference.toTypingMap().asTypingMap(), + reason = inference.reason, + ) + } + } + +private fun Map<*, *>.asTypingMap(): Map = + normalizeTyping(this) as Map + +private fun normalizeTyping(value: Any?): Any? = when (value) { + is Map<*, *> -> value.entries.associate { (key, entryValue) -> key.toString() to normalizeTyping(entryValue) } + is List<*> -> value.map { normalizeTyping(it) } + else -> value +} + private fun fetchManifest(action: ActionCoords): Map? { val list = listOf(action.actionYmlUrl, action.actionYamlUrl)