@@ -5,11 +5,16 @@ import io.github.typesafegithub.workflows.domain.Job
55import io.github.typesafegithub.workflows.domain.JobOutputs
66import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
77import io.github.typesafegithub.workflows.domain.actions.CustomAction
8+ import io.github.typesafegithub.workflows.domain.actions.RegularAction
89import io.github.typesafegithub.workflows.dsl.WorkflowBuilder
910import io.github.typesafegithub.workflows.dsl.expressions.expr
1011import io.github.typesafegithub.workflows.internal.relativeToAbsolute
1112import java.nio.file.Path
1213import kotlin.io.path.invariantSeparatorsPathString
14+ import kotlin.reflect.KParameter
15+ import kotlin.reflect.full.memberProperties
16+ import kotlin.reflect.full.primaryConstructor
17+ import kotlin.reflect.jvm.isAccessible
1318
1419@Suppress(" LongMethod" )
1520internal fun WorkflowBuilder.consistencyCheckJob (
@@ -109,13 +114,14 @@ internal fun WorkflowBuilder.consistencyCheckJob(
109114
110115private fun inferCheckoutActionVersionFromClasspath (): String {
111116 val clazz = Class .forName(" io.github.typesafegithub.workflows.actions.actions.Checkout" )
112- // HACK: Ideally we'd instantiate the binding class and ask it for version, however
113- // it turned out to be difficult due to default arguments in Kotlin. Using Java's
114- // reflection, the constructors require passing ~40 arguments. As a workaround,
115- // the version is extracted from JAR's name, like: 'checkout-v4.jar' -> 'v4'.
116- val jarName =
117- clazz.protectionDomain.codeSource.location
118- .toString()
119- .substringAfterLast(" /" )
120- return jarName.substringAfterLast(" -" ).substringBeforeLast(" ." )
117+ // It's easier to call the primary constructor, even though it's private, because
118+ // the public constructor requires named arguments, and I'm not sure how to call
119+ // it with these.
120+ val constructor =
121+ clazz.kotlin.primaryConstructor!! .also {
122+ it.isAccessible = true
123+ }
124+ val args: Map <KParameter , Any ?> = constructor .parameters.associateWith { null }
125+ val bindingObject = constructor .callBy(args) as RegularAction <* >
126+ return bindingObject.actionVersion
121127}
0 commit comments