8000 wip · Vampire/github-workflows-kt@87efab0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87efab0

Browse files
committed
wip
1 parent 62f85e6 commit 87efab0

File tree

114 files changed

+12795
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+12795
-431
lines changed

automation/typings/src/main/kotlin/it/krzeminski/githubactions/actionsmetadata/ActionsMetadataReading.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ private fun buildTypingsSource(
6060
println("There was a problem parsing action typing: $path")
6161
throw e
6262
}
63-
TypingsSource.WrapperGenerator(inputTypings = typings.toTypesMap())
63+
TypingsSource.WrapperGenerator(
64+
inputTypings = typings.toInputTypesMap(),
65+
outputTypings = typings.toOutputTypesMap(),
66+
)
6467
}
6568
"typings-hosted-by-action" -> TypingsSource.ActionTypes
6669
else -> error("An unexpected file found in $actionTypingsDirectory: '$fileName'")

automation/typings/src/main/kotlin/it/krzeminski/githubactions/actionsmetadata/TypesYamlReading.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import it.krzeminski.githubactions.actionsmetadata.model.ListOfTypings
1212
import it.krzeminski.githubactions.actionsmetadata.model.StringTyping
1313
import it.krzeminski.githubactions.actionsmetadata.model.Typing
1414

15-
internal fun ActionTypes.toTypesMap(): Map<String, Typing> {
16-
return inputs.mapValues { (key, value) ->
15+
internal fun Map<String, ActionType>.toTypesMap() =
16+
mapValues { (key, value) ->
1717
value.toTyping(key)
1818
}
19-
}
19+
20+
internal fun ActionTypes.toInputTypesMap(): Map<String, Typing> = inputs.toTypesMap()
21+
22+
internal fun ActionTypes.toOutputTypesMap(): Map<String, Typing> = outputs.toTypesMap()
2023

2124
private fun ActionType.toTyping(fieldName: String): Typing =
2225
when (this.type) {

automation/typings/src/main/kotlin/it/krzeminski/githubactions/actionsmetadata/model/WrapperRequest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package it.krzeminski.githubactions.actionsmetadata.model
22

33
sealed interface TypingsSource {
4-
data class WrapperGenerator(val inputTypings: Map<String, Typing> = emptyMap()) : TypingsSource
4+
data class WrapperGenerator(
5+
val inputTypings: Map<String, Typing> = emptyMap(),
6+
val outputTypings: Map<String, Typing> = emptyMap(),
7+
) : TypingsSource
58
object ActionTypes : TypingsSource
69
}
710

automation/wrapper-generator/src/main/kotlin/it/krzeminski/githubactions/wrappergenerator/GenerationEntryPoint.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import it.krzeminski.githubactions.wrappergenerator.generation.toKotlinPackageNa
1212
import it.krzeminski.githubactions.wrappergenerator.metadata.deleteActionYamlCacheIfObsolete
1313
import it.krzeminski.githubactions.wrappergenerator.metadata.prettyPrint
1414
import it.krzeminski.githubactions.wrappergenerator.types.deleteActionTypesYamlCacheIfObsolete
15-
import it.krzeminski.githubactions.wrappergenerator.types.provideTypes
15+
import it.krzeminski.githubactions.wrappergenerator.types.provideInputTypes
16+
import it.krzeminski.githubactions.wrappergenerator.types.provideOutputTypes
1617
import java.nio.file.Path
1718
import java.nio.file.Paths
1819

@@ -36,8 +37,9 @@ private fun generateWrappers() {
3637

3738
wrappersToGenerate.forEach { wrapperRequest ->
3839
println("Generating ${wrapperRequest.actionCoords.prettyPrint}")
39-
val inputTypings = wrapperRequest.provideTypes()
40-
val (code, path) = wrapperRequest.actionCoords.generateWrapper(inputTypings)
40+
val inputTypings = wrapperRequest.provideInputTypes()
41+
val outputTypings = wrapperRequest.provideOutputTypes()
42+
val (code, path) = wrapperRequest.actionCoords.generateWrapper(inputTypings, outputTypings)
4143
with(Paths.get(path).toFile()) {
4244
parentFile.mkdirs()
4345
writeText(code)

automation/wrapper-generator/src/main/kotlin/it/krzeminski/githubactions/wrappergenerator/generation/Generation.kt

Lines changed: 198 additions & 29 deletions
Large diffs are not rendered by default.

automation/wrapper-generator/src/main/kotlin/it/krzeminski/githubactions/wrappergenerator/types/TypesProviding.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,26 @@ import java.net.URI
2727
import java.nio.file.Path
2828
import java.time.LocalDate
2929

30-
fun WrapperRequest.provideTypes(
30+
fun WrapperRequest.provideInputTypes(
3131
fetchUri: (URI) -> String = ::fetchUri,
3232
getCommitHash: (ActionCoords) -> String = ::getCommitHash,
3333
): Map<String, Typing> =
3434
when (typingsSource) {
3535
is TypingsSource.WrapperGenerator -> (typingsSource as TypingsSource.WrapperGenerator).inputTypings
3636
TypingsSource.ActionTypes ->
37-
this@provideTypes.actionCoords
38-
.fetchTypingMetadata(fetchUri, getCommitHash).toTypesMap()
37+
this@provideInputTypes.actionCoords
38+
.fetchTypingMetadata(fetchUri, getCommitHash).toInputTypesMap()
39+
}
40+
41+
fun WrapperRequest.provideOutputTypes(
42+
fetchUri: (URI) -> String = ::fetchUri,
10000 43+
getCommitHash: (ActionCoords) -> String = ::getCommitHash,
44+
): Map<String, Typing> =
45+
when (typingsSource) {
46+
is TypingsSource.WrapperGenerator -> (typingsSource as TypingsSource.WrapperGenerator).outputTypings
47+
TypingsSource.ActionTypes ->
48+
this@provideOutputTypes.actionCoords
49+
.fetchTypingMetadata(fetchUri, getCommitHash).toOutputTypesMap()
3950
}
4051

4152
val actionTypesYamlDir = File("build/action-types-yaml")
@@ -86,11 +97,14 @@ internal fun getCommitHash(actionCoords: ActionCoords) =
8697
Path.of("actions", actionCoords.owner, actionCoords.name, actionCoords.version, "commit-hash.txt")
8798
.toFile().readText().trim()
8899

89-
internal fun ActionTypes.toTypesMap(): Map<String, Typing> {
90-
return inputs.mapValues { (key, value) ->
100+
internal fun Map<String, ActionType>.toTypesMap() =
101+
mapValues { (key, value) ->
91102
value.toTyping(key)
92103
}
93-
}
104+
105+
internal fun ActionTypes.toInputTypesMap(): Map<String, Typing> = inputs.toTypesMap()
106+
107+
internal fun ActionTypes.toOutputTypesMap(): Map<String, Typing> = outputs.toTypesMap()
94108

95109
private fun ActionType.toTyping(fieldName: String): Typing =
96110
when (this.type) {

automation/wrapper-generator/src/test/kotlin/it/krzeminski/githubactions/wrappergenerator/generation/wrappersfromunittests/ActionWithDeprecatedInputAndNameClashV2.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package it.krzeminski.githubactions.actions.johnsmith
55

66
import it.krzeminski.githubactions.actions.Action
7+
import it.krzeminski.githubactions.domain.Expression
78
import java.util.LinkedHashMap
89
import kotlin.String
910
import kotlin.Suppress
@@ -22,7 +23,11 @@ public data class ActionWithDeprecatedInputAndNameClashV2(
2223
/**
2324
* Foo bar - new
2425
*/
25-
public val fooBar: String,
26+
public val fooBar: String? = null,
27+
/**
28+
* Foo bar - new
29+
*/
30+
public val fooBarExpression: Expression<String>? = null,
2631
/**
2732
* Type-unsafe map where you can put any inputs that are not yet supported by the wrapper
2833
*/
@@ -33,10 +38,20 @@ public data class ActionWithDeprecatedInputAndNameClashV2(
3338
*/
3439
public val _customVersion: String? = null,
3540
) : Action("john-smith", "action-with-deprecated-input-and-name-clash", _customVersion ?: "v2") {
41+
init {
42+
require(!((fooBar != null) && (fooBarExpression != null))) {
43+
"Only fooBar or fooBarExpression must be set, but not both"
44+
}
45+
require((fooBar != null) || (fooBarExpression != null)) {
46+
"fooBar or fooBarExpression must be set, one of them is required"
47+
}
48+
}
49+
3650
@Suppress("SpreadOperator")
3751
public override fun toYamlArguments(): LinkedHashMap<String, String> = linkedMapOf(
3852
*listOfNotNull(
39-
"fooBar" to fooBar,
53+
fooBar?.let { "fooBar" to it },
54+
fooBarExpression?.let { "fooBar" to it.expressionString },
4055
*_customInputs.toList().toTypedArray(),
4156
).toTypedArray()
4257
)

automation/wrapper-generator/src/test/kotlin/it/krzeminski/githubactions/wrappergenerator/generation/wrappersfromunittests/ActionWithInputsSharingTypeV3.kt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package it.krzeminski.githubactions.actions.johnsmith
55

66
import it.krzeminski.githubactions.actions.Action
7+
import it.krzeminski.githubactions.domain.Expression
78
import java.util.LinkedHashMap
89
import kotlin.Int
910
import kotlin.String
@@ -20,9 +21,12 @@ import kotlin.collections.toTypedArray
2021
* [Action on GitHub](https://github.com/john-smith/action-with-inputs-sharing-type)
2122
*/
2223
public data class ActionWithInputsSharingTypeV3(
23-
public val fooOne: ActionWithInputsSharingTypeV3.Foo,
24-
public val fooTwo: ActionWithInputsSharingTypeV3.Foo,
24+
public val fooOne: ActionWithInputsSharingTypeV3.Foo? = null,
25+
public val fooOneExpression: Expression<ActionWithInputsSharingTypeV3.Foo>? = null,
26+
public val fooTwo: ActionWithInputsSharingTypeV3.Foo? = null,
27+
public val fooTwoExpression: Expression<ActionWithInputsSharingTypeV3.Foo>? = null,
2528
public val fooThree: ActionWithInputsSharingTypeV3.Foo? = null,
29+
public val fooThreeExpression: Expression<ActionWithInputsSharingTypeV3.Foo>? = null,
2630
/**
2731
* Type-unsafe map where you can put any inputs that are not yet supported by the wrapper
2832
*/
@@ -33,12 +37,35 @@ public data class ActionWithInputsSharingTypeV3(
3337
*/
3438
public val _customVersion: String? = null,
3539
) : Action("john-smith", "action-with-inputs-sharing-type", _customVersion ?: "v3") {
40+
init {
41+
require(!((fooOne != null) && (fooOneExpression != null))) {
42+
"Only fooOne or fooOneExpression must be set, but not both"
43+
}
44+
require((fooOne != null) || (fooOneExpression != null)) {
45+
"fooOne or fooOneExpression must be set, one of them is required"
46+
}
47+
48+
require(!((fooTwo != null) && (fooTwoExpression != null))) {
49+
"Only fooTwo or fooTwoExpression must be set, but not both"
50+
}
51+
require((fooTwo != null) || (fooTwoExpression != null)) {
52+
"fooTwo or fooTwoExpression must be set, one of them is required"
53+
}
54+
55+
require(!((fooThree != null) && (fooThreeExpression != null))) {
56+
"Only fooThree or fooThreeExpression must be set, but not both"
57+
}
58+
}
59+
3660
@Suppress("SpreadOperator")
3761
public override fun toYamlArguments(): LinkedHashMap<String, String> = linkedMapOf(
3862
*listOfNotNull(
39-
"foo-one" to fooOne.integerValue.toString(),
40-
"foo-two" to fooTwo.integerValue.toString(),
63+
fooOne?.let { "foo-one" to it.integerValue.toString() },
64+
fooOneExpression?.let { "foo-one" to it.expressionString },
65+
fooTwo?.let { "foo-two" to it.integerValue.toString() },
66+
fooTwoExpression?.let { "foo-two" to it.expressionString },
4167
fooThree?.let { "foo-three" to it.integerValue.toString() },
68+
fooThreeExpression?.let { "foo-three" to it.expressionString },
4269
*_customInputs.toList().toTypedArray(),
4370
).toTypedArray()
4471
)

0 commit comments

Comments
 (0)
0