Skip to content

Commit acfbd14

Browse files
committed
feat(abg): allow usage of version ranges by generating only major or minor version even with more detailed version
1 parent 1dc7506 commit acfbd14

15 files changed

Lines changed: 440 additions & 43 deletions

File tree

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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+
val significantVersion: SignificantVersion = FULL,
710
val path: String? = null,
811
)
912

@@ -13,7 +16,9 @@ public data class ActionCoords(
1316
*/
1417
public val ActionCoords.isTopLevel: Boolean get() = path == null
1518

16-
public val ActionCoords.prettyPrint: String get() = "$owner/$fullName@$version"
19+
public val ActionCoords.prettyPrint: String get() = "$owner/$fullName${
20+
significantVersion.takeUnless { it == FULL }?.let { " with $it version" } ?: ""
21+
}@$version"
1722

1823
/**
1924
* For most actions, it's empty.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.github.typesafegithub.workflows.actionbindinggenerator.domain
2+
3+
public enum class SignificantVersion {
4+
MAJOR,
5+
MINOR,
6+
FULL,
7+
;
8+
9+
override fun toString(): String = super.toString().lowercase()
10+
}

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,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ private fun ActionCoords.actionYmlUrl(gitRef: String) = "https://raw.githubuserc
4040

4141
private fun ActionCoords.actionYamlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$name/$gitRef$subName/action.yaml"
4242

43-
internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name"
44-
4543
public fun ActionCoords.fetchMetadata(
4644
metadataRevision: MetadataRevision,
4745
fetchUri: (URI) -> String = ::fetchUri,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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
28+
* the binding
29+
* @param _customVersion Allows overriding action's version, for example to use a specific minor
30+
* version, or a newer version that the binding doesn't yet know about
31+
*/
32+
@ExposedCopyVisibility
33+
public data class ActionWithNoInputsWithMajorVersion private constructor(
34+
/**
35+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
36+
*/
37+
public val _customInputs: Map<String, String> = mapOf(),
38+
/**
39+
* Allows overriding action's version, for example to use a specific minor version, or a newer
40+
* version that the binding doesn't yet know about
41+
*/
42+
public val _customVersion: String? = null,
43+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-major-version",
44+
_customVersion ?: "v3") {
45+
public constructor(
46+
vararg pleaseUseNamedArguments: Unit,
47+
_customInputs: Map<String, String> = mapOf(),
48+
_customVersion: String? = null,
49+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
50+
51+
@Suppress("SpreadOperator")
52+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
53+
54+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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
49+
* the binding
50+
* @param _customVersion Allows overriding action's version, for example to use a specific minor
51+
* version, or a newer version that the binding doesn't yet know about
52+
*/
53+
@Deprecated(
54+
"Use the typed class instead",
55+
ReplaceWith("ActionWithNoInputsWithMajorVersion"),
56+
)
57+
@ExposedCopyVisibility
58+
public data class ActionWithNoInputsWithMajorVersion_Untyped private constructor(
59+
/**
60+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
61+
*/
62+
public val _customInputs: Map<String, String> = mapOf(),
63+
/**
64+
* Allows overriding action's version, for example to use a specific minor version, or a newer
65+
* version that the binding doesn't yet know about
66+
*/
67+
public val _customVersion: String? = null,
68+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-major-version",
69+
_customVersion ?: "v3") {
70+
public constructor(
71+
vararg pleaseUseNamedArguments: Unit,
72+
_customInputs: Map<String, String> = mapOf(),
73+
_customVersion: String? = null,
74+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
75+
76+
@Suppress("SpreadOperator")
77+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
78+
79+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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
28+
* the binding
29+
* @param _customVersion Allows overriding action's version, for example to use a specific minor
30+
* version, or a newer version that the binding doesn't yet know about
31+
*/
32+
@ExposedCopyVisibility
33+
public data class ActionWithNoInputsWithMinorVersion private constructor(
34+
/**
35+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
36+
*/
37+
public val _customInputs: Map<String, String> = mapOf(),
38+
/**
39+
* Allows overriding action's version, for example to use a specific minor version, or a newer
40+
* version that the binding doesn't yet know about
41+
*/
42+
public val _customVersion: String? = null,
43+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-minor-version",
44+
_customVersion ?: "v3.1") {
45+
public constructor(
46+
vararg pleaseUseNamedArguments: Unit,
47+
_customInputs: Map<String, String> = mapOf(),
48+
_customVersion: String? = null,
49+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
50+
51+
@Suppress("SpreadOperator")
52+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
53+
54+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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-minor-version)
47+
*
48+
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by
49+
* the binding
50+
* @param _customVersion Allows overriding action's version, for example to use a specific minor
51+
* version, or a newer version that the binding doesn't yet know about
52+
*/
53+
@Deprecated(
54+
"Use the typed class instead",
55+
ReplaceWith("ActionWithNoInputsWithMinorVersion"),
56+
)
57+
@ExposedCopyVisibility
58+
public data class ActionWithNoInputsWithMinorVersion_Untyped private constructor(
59+
/**
60+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
61+
*/
62+
public val _customInputs: Map<String, String> = mapOf(),
63+
/**
64+
* Allows overriding action's version, for example to use a specific minor version, or a newer
65+
* version that the binding doesn't yet know about
66+
*/
67+
public val _customVersion: String? = null,
68+
) : RegularAction<Action.Outputs>("john-smith", "action-with-no-inputs-with-minor-version",
69+
_customVersion ?: "v3.1") {
70+
public constructor(
71+
vararg pleaseUseNamedArguments: Unit,
72+
_customInputs: Map<String, String> = mapOf(),
73+
_customVersion: String? = null,
74+
) : this(_customInputs = _customInputs, _customVersion = _customVersion)
75+
76+
@Suppress("SpreadOperator")
77+
override fun toYamlArguments(): LinkedHashMap<String, String> = LinkedHashMap(_customInputs)
78+
79+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
80+
}

0 commit comments

Comments
 (0)