Skip to content

Commit 779b608

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

File tree

17 files changed

+393
-64
lines changed

17 files changed

+393
-64
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,28 @@ public data class ActionCoords(
1111
* A top-level action is an action with its `action.y(a)ml` file in the repository root, as opposed to actions stored
1212
* in subdirectories.
1313
*/
14-
public val ActionCoords.isTopLevel: Boolean get() = "/" !in name
14+
public val ActionCoords.isTopLevel: Boolean get() = "__" !in name.substringBefore("___")
1515

16-
public val ActionCoords.prettyPrint: String get() = "$owner/$name@$version${typesUuid?.let { " (types: $it)" } ?: ""}"
16+
public val ActionCoords.prettyPrint: String
17+
get() = "$owner/${
18+
name.replace("___", " with ").replace("__", "/")
19+
}@$version${typesUuid?.let { " (types: $it)" } ?: ""}"
1720

1821
/**
1922
* For most actions, it's the same as [ActionCoords.name].
2023
* For actions that aren't executed from the root of the repo, it returns the repo name.
2124
*/
2225
public val ActionCoords.repoName: String get() =
23-
name.substringBefore("/")
26+
name.substringBefore("__")
2427

2528
/**
2629
* For most actions, it's empty.
2730
* For actions that aren't executed from the root of the repo, it returns the path relative to the repo root where the
2831
* action lives.
2932
*/
30-
public val ActionCoords.subName: String get() =
31-
if (isTopLevel) "" else "/${name.substringAfter("/")}"
33+
public val ActionCoords.subName: String
34+
get() =
35+
if (isTopLevel) "" else "/${name.substringAfter("__").substringBefore("___").replace("__", "/")}"
3236

3337
internal fun String.toActionCoords(): ActionCoords {
3438
val (ownerAndName, version) = this.split('@')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package io.github.typesafegithub.workflows.actionbindinggenerator.generation
33
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
44
import io.github.typesafegithub.workflows.actionbindinggenerator.utils.toPascalCase
55

6-
internal fun ActionCoords.buildActionClassName(): String = this.name.toPascalCase()
6+
internal fun ActionCoords.buildActionClassName(): String = this.name.substringBefore("___").toPascalCase()

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import com.squareup.kotlinpoet.asTypeName
1717
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
1818
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
1919
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
20+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.isTopLevel
21+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName
22+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName
2023
import io.github.typesafegithub.workflows.actionbindinggenerator.generation.Properties.CUSTOM_INPUTS
2124
import io.github.typesafegithub.workflows.actionbindinggenerator.generation.Properties.CUSTOM_VERSION
2225
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Input
@@ -419,10 +422,20 @@ private fun TypeSpec.Builder.inheritsFromRegularAction(
419422
return this
420423
.superclass(superclass)
421424
.addSuperclassConstructorParameter("%S", coords.owner)
422-
.addSuperclassConstructorParameter("%S", coords.name)
423-
.addSuperclassConstructorParameter("_customVersion ?: %S", coords.version)
425+
.addSuperclassConstructorParameter("%S", coords.name.substringBefore("___").replace("__", "/"))
426+
.addSuperclassConstructorParameter(
427+
"_customVersion ?: %S",
428+
when {
429+
coords.name.endsWith("___major") -> coords.version.majorVersion
430+
coords.name.endsWith("___minor") -> coords.version.minorVersion
431+
else -> coords.version
432+
},
433+
)
424434
}
425435

436+
private val String.majorVersion get() = substringBefore('.')
437+
private val String.minorVersion get() = split('.', limit = 3).take(2).joinToString(".")
438+
426439
private fun Metadata.primaryConstructor(
427440
inputTypings: Map<String, Typing>,
428441
coords: ActionCoords,
@@ -624,9 +637,7 @@ private fun actionKdoc(
624637
|
625638
|${metadata.description.escapedForComments.removeTrailingWhitespacesForEachLine()}
626639
|
627-
|[Action on GitHub](https://github.com/${coords.owner}/${coords.name.substringBefore(
628-
'/',
629-
)}${if ("/" in coords.name) "/tree/${coords.version}/${coords.name.substringAfter('/')}" else ""})
640+
|[Action on GitHub](https://github.com/${coords.owner}/${coords.repoName}${if (!coords.isTopLevel) "/tree/${coords.version}${coords.subName}" else ""})
630641
""".trimMargin()
631642

632643
private fun Map<String, Typing>?.getInputTyping(key: String) = this?.get(key) ?: StringTyping

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCo
55
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.CommitHash
66
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
77
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.NewestForVersion
8+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.repoName
9+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName
810
import kotlinx.serialization.Serializable
911
import kotlinx.serialization.decodeFromString
1012
import java.io.IOException
@@ -35,17 +37,9 @@ public data class Output(
3537
val description: String = "",
3638
)
3739

38-
private fun ActionCoords.actionYmlUrl(gitRef: String) =
39-
"https://raw.githubusercontent.com/$owner/${name.substringBefore(
40-
'/',
41-
)}/$gitRef/${if ("/" in name) "${name.substringAfter('/')}/" else ""}action.yml"
40+
private fun ActionCoords.actionYmlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action.yml"
4241

43-
private fun ActionCoords.actionYamlUrl(gitRef: String) =
44-
"https://raw.githubusercontent.com/$owner/${name.substringBefore(
45-
'/',
46-
)}/$gitRef/${if ("/" in name) "${name.substringAfter('/')}/" else ""}action.yaml"
47-
48-
internal val ActionCoords.gitHubUrl: String get() = "https://github.com/$owner/$name"
42+
private fun ActionCoords.actionYamlUrl(gitRef: String) = "https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action.yaml"
4943

5044
public fun ActionCoords.fetchMetadata(
5145
metadataRevision: MetadataRevision,

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/utils/TextUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal fun String.toPascalCase(): String {
77
val normalizedString = if (hasOnlyUppercases) lowercase() else this
88
return normalizedString
99
.replace("+", "-plus-")
10-
.split("-", "_", " ", ".", "/")
10+
.split("-", "_", " ", ".", "/", "__")
1111
.joinToString("") {
1212
it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
1313
}
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)