Skip to content

Commit 49d5b76

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

File tree

16 files changed

+420
-27
lines changed

16 files changed

+420
-27
lines changed

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
@@ -43,8 +43,6 @@ private fun ActionCoords.actionYmlUrl(gitRef: String) = "https://raw.githubuserc
4343

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

46-
internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name"
47-
4846
public fun ActionCoords.fetchMetadata(
4947
metadataRevision: MetadataRevision,
5048
fetchUri: (URI) -> String = ::fetchUri,
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+
}
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-minor-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("ActionWithNoInputsWithMinorVersion"),
54+
)
55+
@ExposedCopyVisibility
56+
public data class ActionWithNoInputsWithMinorVersion_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-minor-version", _customVersion ?: "v3.1") {
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+
}

0 commit comments

Comments
 (0)