Skip to content

Commit c384f47

Browse files
authored
feat: allow using version ranges to cope with stale Maven Local cache (#1611)
With these changes you can for example depend on `actions:cache__save___major:[v4,v5)"` and get the latest v4 action with latest v4 typing by resolving to a concrete v4.x.y version but the output still contains just `v4`. The same for `actions:cache__save___minor:[v4.0,v4.1)`, to get the latest v4.0 but in the output just have `v4.0`.
1 parent 4e7ced7 commit c384f47

File tree

18 files changed

+521
-25
lines changed

18 files changed

+521
-25
lines changed

.github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env kotlin
22
@file:Repository("https://repo.maven.apache.org/maven2/")
33
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
4+
@file:DependsOn("io.kotest:kotest-assertions-core:5.9.1")
45

56
@file:Repository("http://localhost:8080")
67

@@ -13,14 +14,21 @@
1314
// Using specific version.
1415
@file:DependsOn("actions:cache:v3.3.3")
1516

17+
// Using version ranges.
18+
@file:DependsOn("gradle:actions__dependency-submission___major:[v3.3.1,v4-alpha)")
19+
@file:DependsOn("gradle:actions__wrapper-validation___minor:[v4.2.1,v4.3-alpha)")
20+
1621
// Always untyped action.
1722
@file:DependsOn("typesafegithub:always-untyped-action-for-tests:v1")
1823

1924
import io.github.typesafegithub.workflows.actions.actions.Cache
2025
import io.github.typesafegithub.workflows.actions.actions.Checkout
2126
import io.github.typesafegithub.workflows.actions.actions.Checkout_Untyped
2227
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
28+
import io.github.typesafegithub.workflows.actions.gradle.ActionsDependencySubmission_Untyped
29+
import io.github.typesafegithub.workflows.actions.gradle.ActionsWrapperValidation
2330
import io.github.typesafegithub.workflows.actions.typesafegithub.AlwaysUntypedActionForTests_Untyped
31+
import io.kotest.matchers.shouldBe
2432

2533
println(Checkout_Untyped(fetchTags_Untyped = "false"))
2634
println(Checkout(fetchTags = false))
@@ -29,5 +37,8 @@ println(AlwaysUntypedActionForTests_Untyped(foobar_Untyped = "baz"))
2937
println(ActionsSetupGradle())
3038
println(Cache(path = listOf("some-path"), key = "some-key"))
3139

40+
ActionsDependencySubmission_Untyped().actionVersion shouldBe "v3"
41+
ActionsWrapperValidation().actionVersion shouldBe "v4.2"
42+
3243
// Ensure that 'copy(...)' method is exposed.
3344
Checkout(fetchTags = false).copy(fetchTags = true)

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
public final class io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords {
2-
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
3-
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2+
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;Ljava/lang/String;)V
3+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
44
public final fun component1 ()Ljava/lang/String;
55
public final fun component2 ()Ljava/lang/String;
66
public final fun component3 ()Ljava/lang/String;
7-
public final fun component4 ()Ljava/lang/String;
8-
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;
9-
public static synthetic fun copy$default (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;
7+
public final fun component4 ()Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
8+
public final fun component5 ()Ljava/lang/String;
9+
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;Ljava/lang/String;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;
10+
public static synthetic fun copy$default (Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;Ljava/lang/String;ILjava/lang/Object;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords;
1011
public fun equals (Ljava/lang/Object;)Z
1112
public final fun getName ()Ljava/lang/String;
1213
public final fun getOwner ()Ljava/lang/String;
1314
public final fun getPath ()Ljava/lang/String;
15+
public final fun getSignificantVersion ()Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
1416
public final fun getVersion ()Ljava/lang/String;
1517
public fun hashCode ()I
1618
public fun toString ()Ljava/lang/String;
@@ -44,6 +46,16 @@ public final class io/github/typesafegithub/workflows/actionbindinggenerator/dom
4446
public fun toString ()Ljava/lang/String;
4547
}
4648

49+
public final class io/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion : java/lang/Enum {
50+
public static final field FULL Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
51+
public static final field MAJOR Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
52+
public static final field MINOR Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
53+
public static fun getEntries ()Lkotlin/enums/EnumEntries;
54+
public fun toString ()Ljava/lang/String;
55+
public static fun valueOf (Ljava/lang/String;)Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
56+
public static fun values ()[Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
57+
}
58+
4759
public final class io/github/typesafegithub/workflows/actionbindinggenerator/domain/TypingActualSource : java/lang/Enum {
4860
public static final field ACTION Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/TypingActualSource;
4961
public static final field TYPING_CATALOG Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/TypingActualSource;

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package io.github.typesafegithub.workflows.actionbindinggenerator.domain
22

3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
4+
35
public data class ActionCoords(
46
val owner: String,
57
val name: String,
68
val version: String,
9+
/**
10+
* The version part that is significant when generating the YAML output,
11+
* i.e. whether to write the full version, only the major version or major and minor version.
12+
* This is used to enable usage of Maven ranges without needing to specify a custom version
13+
* each time instantiating an action.
14+
* The value of this property is part of the Maven coordinates as a suffix for the [name] property.
15+
*/
16+
val significantVersion: SignificantVersion = FULL,
717
val path: String? = null,
818
)
919

@@ -13,7 +23,9 @@ public data class ActionCoords(
1323
*/
1424
public val ActionCoords.isTopLevel: Boolean get() = path == null
1525

16-
public val ActionCoords.prettyPrint: String get() = "$owner/$fullName@$version"
26+
public val ActionCoords.prettyPrint: String get() = "$owner/$fullName${
27+
significantVersion.takeUnless { it == FULL }?.let { " with $it version" } ?: ""
28+
}@$version"
1729

1830
/**
1931
* For most actions, it's empty.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.github.typesafegithub.workflows.actionbindinggenerator.domain
2+
3+
/**
4+
* The version part that is significant when generating the YAML output.
5+
* This is used to enable usage of Maven ranges without needing to specify a custom version
6+
* each time instantiating an action.
7+
*/
8+
public enum class SignificantVersion {
9+
/**
10+
* Only write the major version to the generated YAML.
11+
*/
12+
MAJOR,
13+
14+
/**
15+
* Only write the major and minor version to the generated YAML.
16+
*/
17+
MINOR,
18+
19+
/**
20+
* Write the full version to the generated YAML.
21+
*/
22+
FULL,
23+
;
24+
25+
override fun toString(): String = super.toString().lowercase()
26+
}

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/Generation.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import com.squareup.kotlinpoet.asTypeName
1717
import com.squareup.kotlinpoet.buildCodeBlock
1818
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
1919
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
20+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
21+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MAJOR
22+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MINOR
2023
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
2124
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.fullName
2225
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.isTopLevel
@@ -415,9 +418,19 @@ private fun TypeSpec.Builder.inheritsFromRegularAction(
415418
.superclass(superclass)
416419
.addSuperclassConstructorParameter("%S", coords.owner)
417420
.addSuperclassConstructorParameter("%S", coords.fullName)
418-
.addSuperclassConstructorParameter("_customVersion ?: %S", coords.version)
421+
.addSuperclassConstructorParameter(
422+
"_customVersion ?: %S",
423+
when (coords.significantVersion) {
424+
MAJOR -> coords.version.majorVersion
425+
MINOR -> coords.version.minorVersion
426+
FULL -> coords.version
427+
},
428+
)
419429
}
420430

431+
private val String.majorVersion get() = substringBefore('.')
432+
private val String.minorVersion get() = split('.', limit = 3).take(2).joinToString(".")
433+
421434
private fun Metadata.primaryConstructor(
422435
inputTypings: Map<String, Typing>,
423436
coords: ActionCoords,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This file was generated using action-binding-generator. Don't change it by hand, otherwise your
2+
// changes will be overwritten with the next binding code regeneration.
3+
// See https://github.com/typesafegithub/github-workflows-kt for more info.
4+
@file:Suppress(
5+
"DataClassPrivateConstructor",
6+
"UNUSED_PARAMETER",
7+
)
8+
9+
package io.github.typesafegithub.workflows.actions.johnsmith
10+
11+
import io.github.typesafegithub.workflows.domain.actions.Action
12+
import io.github.typesafegithub.workflows.domain.actions.RegularAction
13+
import java.util.LinkedHashMap
14+
import kotlin.ExposedCopyVisibility
15+
import kotlin.String
16+
import kotlin.Suppress
17+
import kotlin.Unit
18+
import kotlin.collections.Map
19+
20+
/**
21+
* Action: Action With No Inputs
22+
*
23+
* Description
24+
*
25+
* [Action on GitHub](https://github.com/john-smith/action-with-no-inputs-with-major-version)
26+
*
27+
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
28+
* @param _customVersion Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
29+
*/
30+
@ExposedCopyVisibility
31+
public data class ActionWithNoInputsWithMajorVersion private constructor(
32+
/**
33+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
34+
*/
35+
public val _customInputs: Map<String, String> = mapOf(),
36+
/**
37+
* Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
38+
*/
39+
public val _customVersion: String? = null,
40+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-major-version", _customVersion ?: "v3") {
41+
public constructor(
42+
vararg pleaseUseNamedArguments: Unit,
43+
_customInputs: Map<String, String> = mapOf(),
44+
_customVersion: String? = null,
45+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
46+
47+
@Suppress("SpreadOperator")
48+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
49+
50+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// This file was generated using action-binding-generator. Don't change it by hand, otherwise your
2+
// changes will be overwritten with the next binding code regeneration.
3+
// See https://github.com/typesafegithub/github-workflows-kt for more info.
4+
@file:Suppress(
5+
"DataClassPrivateConstructor",
6+
"UNUSED_PARAMETER",
7+
)
8+
9+
package io.github.typesafegithub.workflows.actions.johnsmith
10+
11+
import io.github.typesafegithub.workflows.domain.actions.Action
12+
import io.github.typesafegithub.workflows.domain.actions.RegularAction
13+
import java.util.LinkedHashMap
14+
import kotlin.Deprecated
15+
import kotlin.ExposedCopyVisibility
16+
import kotlin.String
17+
import kotlin.Suppress
18+
import kotlin.Unit
19+
import kotlin.collections.Map
20+
21+
/**
22+
* ```text
23+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24+
* !!! WARNING !!!
25+
* !!! !!!
26+
* !!! This action binding has no typings provided. All inputs will !!!
27+
* !!! have a default type of String. !!!
28+
* !!! To be able to use this action in a type-safe way, ask the !!!
29+
* !!! action's owner to provide the typings using !!!
30+
* !!! !!!
31+
* !!! https://github.com/typesafegithub/github-actions-typing !!!
32+
* !!! !!!
33+
* !!! or if it's impossible, contribute typings to a community-driven !!!
34+
* !!! !!!
35+
* !!! https://github.com/typesafegithub/github-actions-typing-catalog !!!
36+
* !!! !!!
37+
* !!! This '_Untyped' binding will be available even once the typings !!!
38+
* !!! are added. !!!
39+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40+
* ```
41+
*
42+
* Action: Action With No Inputs
43+
*
44+
* Description
45+
*
46+
* [Action on GitHub](https://github.com/john-smith/action-with-no-inputs-with-major-version)
47+
*
48+
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
49+
* @param _customVersion Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
50+
*/
51+
@Deprecated(
52+
"Use the typed class instead",
53+
ReplaceWith("ActionWithNoInputsWithMajorVersion"),
54+
)
55+
@ExposedCopyVisibility
56+
public data class ActionWithNoInputsWithMajorVersion_Untyped private constructor(
57+
/**
58+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
59+
*/
60+
public val _customInputs: Map<String, String> = mapOf(),
61+
/**
62+
* Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
63+
*/
64+
public val _customVersion: String? = null,
65+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-major-version", _customVersion ?: "v3") {
66+
public constructor(
67+
vararg pleaseUseNamedArguments: Unit,
68+
_customInputs: Map<String, String> = mapOf(),
69+
_customVersion: String? = null,
70+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
71+
72+
@Suppress("SpreadOperator")
73+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
74+
75+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This file was generated using action-binding-generator. Don't change it by hand, otherwise your
2+
// changes will be overwritten with the next binding code regeneration.
3+
// See https://github.com/typesafegithub/github-workflows-kt for more info.
4+
@file:Suppress(
5+
"DataClassPrivateConstructor",
6+
"UNUSED_PARAMETER",
7+
)
8+
9+
package io.github.typesafegithub.workflows.actions.johnsmith
10+
11+
import io.github.typesafegithub.workflows.domain.actions.Action
12+
import io.github.typesafegithub.workflows.domain.actions.RegularAction
13+
import java.util.LinkedHashMap
14+
import kotlin.ExposedCopyVisibility
15+
import kotlin.String
16+
import kotlin.Suppress
17+
import kotlin.Unit
18+
import kotlin.collections.Map
19+
20+
/**
21+
* Action: Action With No Inputs
22+
*
23+
* Description
24+
*
25+
* [Action on GitHub](https://github.com/john-smith/action-with-no-inputs-with-minor-version)
26+
*
27+
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by the binding
28+
* @param _customVersion Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
29+
*/
30+
@ExposedCopyVisibility
31+
public data class ActionWithNoInputsWithMinorVersion private constructor(
32+
/**
33+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
34+
*/
35+
public val _customInputs: Map<String, String> = mapOf(),
36+
/**
37+
* Allows overriding action's version, for example to use a specific minor version, or a newer version that the binding doesn't yet know about
38+
*/
39+
public val _customVersion: String? = null,
40+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-minor-version", _customVersion ?: "v3.1") {
41+
public constructor(
42+
vararg pleaseUseNamedArguments: Unit,
43+
_customInputs: Map<String, String> = mapOf(),
44+
_customVersion: String? = null,
45+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
46+
47+
@Suppress("SpreadOperator")
48+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
49+
50+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
51+
}

0 commit comments

Comments
 (0)