Skip to content

Commit e6acd43

Browse files
authored
feat(abg): add versioned JAR mode (#1326)
Part of #1318.
1 parent 01594ce commit e6acd43

File tree

3 files changed

+153
-1
lines changed

3 files changed

+153
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public final class io/github/typesafegithub/workflows/actionbindinggenerator/gen
8484
public final class io/github/typesafegithub/workflows/actionbindinggenerator/generation/ClientType : java/lang/Enum {
8585
public static final field BUNDLED_WITH_LIB Lio/github/typesafegithub/workflows/actionbindinggenerator/generation/ClientType;
8686
public static final field CLIENT_SIDE_GENERATION Lio/github/typesafegithub/workflows/actionbindinggenerator/generation/ClientType;
87+
public static final field VERSIONED_JAR Lio/github/typesafegithub/workflows/actionbindinggenerator/generation/ClientType;
8788
public static fun getEntries ()Lkotlin/enums/EnumEntries;
8889
public static fun valueOf (Ljava/lang/String;)Lio/github/typesafegithub/workflows/actionbindinggenerator/generation/ClientType;
8990
public static fun values ()[Lio/github/typesafegithub/workflows/actionbindinggenerator/generation/ClientType;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public enum class ClientType {
5555
* via `@file:Import(...)`.
5656
*/
5757
CLIENT_SIDE_GENERATION,
58+
59+
/**
60+
* The binding is going to be provided in a versioned JAR.
61+
*/
62+
VERSIONED_JAR,
5863
}
5964

6065
private object Types {
@@ -118,7 +123,7 @@ private fun generateActionBindingSourceCode(
118123
): String {
119124
val fileSpec =
120125
FileSpec.builder(
121-
if (clientType == ClientType.BUNDLED_WITH_LIB) {
126+
if (clientType != ClientType.CLIENT_SIDE_GENERATION) {
122127
"io.github.typesafegithub.workflows.actions.${coords.owner.toKotlinPackageName()}"
123128
} else {
124129
""

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/generation/GenerationTest.kt

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,150 @@ class GenerationTest : FunSpec({
532532
533533
""".trimIndent()
534534
}
535+
536+
test("action binding generated for the versioned JAR") {
537+
// given
538+
val actionManifest =
539+
Metadata(
540+
name =
541+
"""
542+
Do something cool
543+
and describe it in multiple lines
544+
""".trimIndent(),
545+
description = "This is a test description that should be put in the KDoc comment for a class",
546+
inputs =
547+
mapOf(
548+
"foo-bar" to
549+
Input(
550+
description = "Short description",
551+
required = true,
552+
default = null,
553+
),
554+
"baz-goo" to
555+
Input(
556+
description =
557+
"""
558+
Just another input
559+
with multiline description
560+
""".trimIndent(),
561+
deprecationMessage = "this is deprecated",
562+
required = true,
563+
default = null,
564+
),
565+
),
566+
)
567+
val coords = ActionCoords("john-smith", "action-for-generated-jar", "v3")
568+
569+
// when
570+
val binding =
571+
coords.generateBinding(
572+
metadataRevision = FromLockfile,
573+
metadata = actionManifest,
574+
clientType = ClientType.VERSIONED_JAR,
575+
inputTypings =
576+
Pair(
577+
mapOf(
578+
"baz-goo" to EnumTyping(null, listOf("helloworld"), listOf("HelloWorld")),
579+
),
580+
ACTION,
581+
),
582+
)
583+
584+
// then
585+
//language=kotlin
586+
binding.kotlinCode shouldBe
587+
"""
588+
// This file was generated using action-binding-generator. Don't change it by hand, otherwise your
589+
// changes will be overwritten with the next binding code regeneration.
590+
// See https://github.com/typesafegithub/github-workflows-kt for more info.
591+
@file:Suppress(
592+
"DataClassPrivateConstructor",
593+
"UNUSED_PARAMETER",
594+
"DEPRECATION",
595+
)
596+
597+
package io.github.typesafegithub.workflows.actions.johnsmith
598+
599+
import io.github.typesafegithub.workflows.domain.actions.Action
600+
import io.github.typesafegithub.workflows.domain.actions.RegularAction
601+
import java.util.LinkedHashMap
602+
import kotlin.Deprecated
603+
import kotlin.String
604+
import kotlin.Suppress
605+
import kotlin.Unit
606+
import kotlin.collections.Map
607+
import kotlin.collections.toList
608+
import kotlin.collections.toTypedArray
609+
610+
/**
611+
* Action: Do something cool
612+
* and describe it in multiple lines
613+
*
614+
* This is a test description that should be put in the KDoc comment for a class
615+
*
616+
* [Action on GitHub](https://github.com/john-smith/action-for-generated-jar)
617+
*
618+
* @param fooBar Short description
619+
* @param bazGoo Just another input
620+
* with multiline description
621+
* @param _customInputs Type-unsafe map where you can put any inputs that are not yet supported by
622+
* the binding
623+
* @param _customVersion Allows overriding action's version, for example to use a specific minor
624+
* version, or a newer version that the binding doesn't yet know about
625+
*/
626+
public data class ActionForGeneratedJar private constructor(
627+
/**
628+
* Short description
629+
*/
630+
public val fooBar: String,
631+
/**
632+
* Just another input
633+
* with multiline description
634+
*/
635+
@Deprecated("this is deprecated")
636+
public val bazGoo: ActionForGeneratedJar.BazGoo,
637+
/**
638+
* Type-unsafe map where you can put any inputs that are not yet supported by the binding
639+
*/
640+
public val _customInputs: Map<String, String> = mapOf(),
641+
/**
642+
* Allows overriding action's version, for example to use a specific minor version, or a newer
643+
* version that the binding doesn't yet know about
644+
*/
645+
public val _customVersion: String? = null,
646+
) : RegularAction<Action.Outputs>("john-smith", "action-for-generated-jar", _customVersion ?: "v3")
647+
{
648+
public constructor(
649+
vararg pleaseUseNamedArguments: Unit,
650+
fooBar: String,
651+
bazGoo: ActionForGeneratedJar.BazGoo,
652+
_customInputs: Map<String, String> = mapOf(),
653+
_customVersion: String? = null,
654+
) : this(fooBar=fooBar, bazGoo=bazGoo, _customInputs=_customInputs,
655+
_customVersion=_customVersion)
656+
657+
@Suppress("SpreadOperator")
658+
override fun toYamlArguments(): LinkedHashMap<String, String> = linkedMapOf(
659+
*listOfNotNull(
660+
"foo-bar" to fooBar,
661+
"baz-goo" to bazGoo.stringValue,
662+
*_customInputs.toList().toTypedArray(),
663+
).toTypedArray()
664+
)
665+
666+
override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
667+
668+
public sealed class BazGoo(
669+
public val stringValue: String,
670+
) {
671+
public object HelloWorld : ActionForGeneratedJar.BazGoo("helloworld")
672+
673+
public class Custom(
674+
customStringValue: String,
675+
) : ActionForGeneratedJar.BazGoo(customStringValue)
676+
}
677+
}
678+
679+
""".trimIndent()
680+
}
535681
})

0 commit comments

Comments
 (0)