Repository: typesafegithub/github-workflows-kt
Pull request #1085 (2023-11-09 09:14:44)

[#1071] ci: use generateActionBindings helper
The library now provides a helper function for implementing the logic required for bindings generation.


Patch:
diff --git a/.github/workflows/generate-action-bindings.main.kts b/.github/workflows/generate-action-bindings.main.kts
index 2601ee845..b19ed3d41 100755
--- a/.github/workflows/generate-action-bindings.main.kts
+++ b/.github/workflows/generate-action-bindings.main.kts
@@ -1,37 +1,7 @@
 #!/usr/bin/env kotlin
 @file:Repository("https://s01.oss.sonatype.org/content/repositories/snapshots/")
-@file:DependsOn("io.github.typesafegithub:action-binding-generator:1.4.1-20231029.205542-12")
+@file:DependsOn("io.github.typesafegithub:action-binding-generator:1.4.1-20231109.093107-24")
 
-import io.github.typesafegithub.workflows.actionbindinggenerator.NewestForVersion
-import io.github.typesafegithub.workflows.actionbindinggenerator.extractUsedActionsFromWorkflow
-import io.github.typesafegithub.workflows.actionbindinggenerator.generateBinding
-import java.io.File
-import kotlin.io.path.Path
+import io.github.typesafegithub.workflows.actionbindinggenerator.generateActionBindings
 
-val workflowYamlFileName: String? = when {
-    args.isEmpty() -> null
-    args.size == 1 -> args[0]
-    else -> error("At most one argument is supported!")
-}
-
-val allUsedActions = extractUsedActionsFromWorkflow(
-    manifest = File(".github/workflows/_used-actions.yaml").readText(),
-)
-
-val actionsToGenerateBindingsFor = workflowYamlFileName?.let {
-    val actionsUsedInRequestedWorkflow = extractUsedActionsFromWorkflow(
-        manifest = File(".github/workflows/$workflowYamlFileName").readText(),
-    )
-    allUsedActions.intersect(actionsUsedInRequestedWorkflow.toSet())
-} ?: allUsedActions
-
-actionsToGenerateBindingsFor.forEach { action ->
-    Path(".github").resolve("workflows").resolve("generated").resolve(action.owner).resolve("${action.name}.kt").let {
-        it.parent.toFile().mkdirs()
-        val binding = action.generateBinding(
-            metadataRevision = NewestForVersion,
-            generateForScript = true,
-        )
-        it.toFile().writeText(binding.kotlinCode)
-    }
-}
+generateActionBindings(args)
diff --git a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflow.kt b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflow.kt
index 88e4acdcf..3522ef759 100644
--- a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflow.kt
+++ b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflow.kt
@@ -27,8 +27,8 @@ private fun parseWorkflow(manifest: String) =
 private fun assertSingleVersionForEachAction(actionCoords: List<ActionCoords>) {
     val actionsWithMultipleVersions =
         actionCoords
-            .groupingBy { "${it.owner}/${it.name}" }
-            .eachCount()
+            .groupBy { "${it.owner}/${it.name}" }
+            .mapValues { it.value.toSet().size }
             .filterValues { it > 1 }
             .keys
     if (actionsWithMultipleVersions.isNotEmpty()) {


Test patch:
diff --git a/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflowTest.kt b/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflowTest.kt
index afb2de37f..7421d0870 100644
--- a/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflowTest.kt
+++ b/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ExtractUsedActionsFromWorkflowTest.kt
@@ -104,6 +104,10 @@ class ExtractUsedActionsFromWorkflowTest : FunSpec({
                   - uses: actions/checkout@v3
                   - uses: actions/setup-java@v4
                   - uses: actions/checkout@v5
+              another-job:
+                runs-on: ubuntu-latest
+                steps:
+                  - uses: actions/setup-java@v4
             """.trimIndent()
 
         // Then