Skip to content

Commit bac52c9

Browse files
authored
feat(automation): print diffs in inputs/outputs when suggesting versions (#1256)
1 parent 85520ad commit bac52c9

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

action-binding-generator/api/action-binding-generator.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public final class io/github/typesafegithub/workflows/actionbindinggenerator/met
163163
public final fun serializer ()Lkotlinx/serialization/KSerializer;
164164
}
165165

166+
public final class io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReadingKt {
167+
public static final fun fetchMetadata (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/MetadataRevision;Lkotlin/jvm/functions/Function1;)Lio/github/typesafegithub/workflows/actionbindinggenerator/metadata/Metadata;
168+
public static synthetic fun fetchMetadata$default (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/MetadataRevision;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/github/typesafegithub/workflows/actionbindinggenerator/metadata/Metadata;
169+
}
170+
166171
public final class io/github/typesafegithub/workflows/actionbindinggenerator/metadata/Output {
167172
public static final field Companion Lio/github/typesafegithub/workflows/actionbindinggenerator/metadata/Output$Companion;
168173
public fun <init> ()V

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/metadata/MetadataReading.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal val ActionCoords.releasesUrl: String get() = "$gitHubUrl/releases"
5252

5353
internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name"
5454

55-
internal fun ActionCoords.fetchMetadata(
55+
public fun ActionCoords.fetchMetadata(
5656
metadataRevision: MetadataRevision,
5757
fetchUri: (URI) -> String = ::fetchUri,
5858
): Metadata {

automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package io.github.typesafegithub.workflows.codegenerator.versions
22

33
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
4+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.FromLockfile
5+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
6+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.NewestForVersion
47
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.isTopLevel
58
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPrint
9+
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Metadata
10+
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.fetchMetadata
611
import io.github.typesafegithub.workflows.codegenerator.bindingsToGenerate
712
import io.github.typesafegithub.workflows.codegenerator.model.Version
813
import java.io.File
@@ -63,6 +68,7 @@ fun List<GithubRef>.versions(): List<Version> =
6368
fun ActionCoords.suggestNewerVersion(
6469
existingVersions: List<Version>,
6570
availableVersions: List<Version>,
71+
fetchMeta: ActionCoords.(MetadataRevision) -> Metadata = { this.fetchMetadata(it) },
6672
): String? {
6773
if (availableVersions.isEmpty()) {
6874
return null
@@ -77,13 +83,18 @@ fun ActionCoords.suggestNewerVersion(
7783
.filter { it.isMajorVersion() }
7884
.sorted()
7985

86+
val metadata by lazy { this.copy(version = maxExisting.version).fetchMeta(FromLockfile) }
87+
8088
val newerMajorVersions =
8189
majorVersions.filter { it > maxExisting }.sorted()
82-
.map { "$it ([diff](${this.buildGitHubComparisonUrl(maxExisting, it)}))" }
90+
.map {
91+
val thisMetadata = this@suggestNewerVersion.copy(version = it.version).fetchMeta(NewestForVersion)
92+
val addedInputs = thisMetadata.inputs.keys - metadata.inputs.keys
93+
val removedInputs = metadata.inputs.keys - thisMetadata.inputs.keys
94+
val addedOutputs = thisMetadata.outputs.keys - metadata.outputs.keys
95+
val removedOutputs = metadata.outputs.keys - thisMetadata.outputs.keys
96+
"$it (added inputs: $addedInputs, removed inputs: $removedInputs, " +
97+
"added outputs: $addedOutputs, removed outputs: $removedOutputs)"
98+
}
8399
return "new version(s) available: $newerMajorVersions".takeIf { newerMajorVersions.isNotEmpty() }
84100
}
85-
86-
private fun ActionCoords.buildGitHubComparisonUrl(
87-
version1: Version,
88-
version2: Version,
89-
): String = "https://github.com/${this.owner}/${this.name}/compare/$version1...$version2#files_bucket"

automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersionsTest.kt

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package io.github.typesafegithub.workflows.codegenerator.versions
22

33
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
4+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
5+
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Input
6+
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Metadata
7+
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Output
48
import io.github.typesafegithub.workflows.codegenerator.model.Version
59
import io.kotest.assertions.assertSoftly
610
import io.kotest.core.spec.style.FunSpec
@@ -55,24 +59,67 @@ class SuggestVersionsTest : FunSpec({
5559
}
5660

5761
test("New major version") {
58-
assertSoftly {
62+
@Suppress("UNUSED_PARAMETER")
63+
fun ActionCoords.fetchMeta(metadataRevision: MetadataRevision): Metadata {
64+
assert(owner == "test-owner")
65+
assert(name == "test-name")
66+
return when (this.version) {
67+
"v1" ->
68+
Metadata(
69+
name = "Test",
70+
description = "Test",
71+
inputs =
72+
mapOf(
73+
"some-input" to Input(),
74+
"input-will-be-removed-in-v2" to Input(),
75+
),
76+
outputs =
77+
mapOf(
78+
"some-outputs" to Output(),
79+
"outputs-will-be-removed-in-v2" to Output(),
80+
),
81+
)
82+
"v2", "v3", "v9", "v12" ->
83+
Metadata(
84+
name = "Test",
85+
description = "Test",
86+
inputs =
87+
mapOf(
88+
"some-input" to Input(),
89+
"new-input-in-v2" to Input(),
90+
),
91+
outputs =
92+
mapOf(
93+
"some-outputs" to Output(),
94+
"new-input-in-v2" to Output(),
95+
),
96+
)
97+
else -> error("No mocked response for version ${this.version}")
98+
}
99+
}
59100

101+
assertSoftly {
60102
testCoords.suggestNewerVersion(
61103
"v1".versions(),
62104
"v1, v1.1.1, v2, v2.0.1, v3, v3.1.1".versions(),
105+
fetchMeta = ActionCoords::fetchMeta,
63106
) shouldBe "new version(s) available: [" +
64-
"v2 ([diff](https://github.com/test-owner/test-name/compare/v1...v2#files_bucket)), " +
65-
"v3 ([diff](https://github.com/test-owner/test-name/compare/v1...v3#files_bucket))]"
107+
"v2 (added inputs: [new-input-in-v2], removed inputs: [input-will-be-removed-in-v2], " +
108+
"added outputs: [new-input-in-v2], removed outputs: [outputs-will-be-removed-in-v2]), " +
109+
"v3 (added inputs: [new-input-in-v2], removed inputs: [input-will-be-removed-in-v2], " +
110+
"added outputs: [new-input-in-v2], removed outputs: [outputs-will-be-removed-in-v2])]"
66111

67112
testCoords.suggestNewerVersion(
68113
"v2".versions(),
69114
"v1.1.1, v2, v2.0.1, v3, v3.1.1".versions(),
70-
) shouldBe "new version(s) available: [v3 ([diff](https://github.com/test-owner/test-name/compare/v2...v3#files_bucket))]"
115+
fetchMeta = ActionCoords::fetchMeta,
116+
) shouldBe "new version(s) available: [v3 (added inputs: [], removed inputs: [], added outputs: [], removed outputs: [])]"
71117

72118
testCoords.suggestNewerVersion(
73119
"v9".versions(),
74120
"v12, v12.0.1".versions(),
75-
) shouldBe "new version(s) available: [v12 ([diff](https://github.com/test-owner/test-name/compare/v9...v12#files_bucket))]"
121+
fetchMeta = ActionCoords::fetchMeta,
122+
) shouldBe "new version(s) available: [v12 (added inputs: [], removed inputs: [], added outputs: [], removed outputs: [])]"
76123
}
77124
}
78125
}

0 commit comments

Comments
 (0)