Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ private suspend fun ActionCoords.fetchTypingMetadata(
logger.info { " ... types from action $url" }
val response = httpClient.get(url)
when (response.status) {
HttpStatusCode.OK -> response.bodyAsText()
HttpStatusCode.OK -> {
response.bodyAsText()
}

HttpStatusCode.NotFound -> {
logger.info { " ... types from action were not found: $url" }
null
}
else -> throw IOException("Failed fetching from $url")

else -> {
throw IOException("Failed fetching from $url")
}
}
} ?: return null

Expand Down Expand Up @@ -124,12 +130,18 @@ private suspend fun fetchTypingsFromUrl(
val response = httpClient.get(url)
val typesMetadataYml =
when (response.status) {
HttpStatusCode.OK -> response.bodyAsText()
HttpStatusCode.OK -> {
response.bodyAsText()
}

HttpStatusCode.NotFound -> {
logger.info { " ... types from catalog were not found: $url" }
return null
}
else -> throw IOException("Failed fetching from $url")

else -> {
throw IOException("Failed fetching from $url")
}
}
return yaml.decodeFromStringOrDefaultIfEmpty(typesMetadataYml, ActionTypes())
}
Expand All @@ -143,8 +155,14 @@ private fun ActionCoords.toMajorVersion(): ActionCoords = this.copy(version = th

private fun ActionType.toTyping(fieldName: String): Typing =
when (this.type) {
ActionTypeEnum.String -> StringTyping
ActionTypeEnum.Boolean -> BooleanTyping
ActionTypeEnum.String -> {
StringTyping
}

ActionTypeEnum.Boolean -> {
BooleanTyping
}

ActionTypeEnum.Integer -> {
if (this.namedValues.isEmpty()) {
IntegerTyping
Expand All @@ -155,17 +173,24 @@ private fun ActionType.toTyping(fieldName: String): Typing =
)
}
}
ActionTypeEnum.Float -> FloatTyping
ActionTypeEnum.List ->

ActionTypeEnum.Float -> {
FloatTyping
}

ActionTypeEnum.List -> {
ListOfTypings(
delimiter = separator,
typing = listItem?.toTyping(fieldName) ?: error("Lists should have list-item set!"),
)
ActionTypeEnum.Enum ->
}

ActionTypeEnum.Enum -> {
EnumTyping(
items = allowedValues,
typeName = name?.toPascalCase() ?: fieldName.toPascalCase(),
)
}
}

private inline fun <reified T> Yaml.decodeFromStringOrDefaultIfEmpty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,61 @@ internal fun Typing.getClassName(
fieldName: String,
): TypeName =
when (this) {
BooleanTyping -> Boolean::class.asTypeName()
BooleanTyping -> {
Boolean::class.asTypeName()
}

is EnumTyping -> {
val typeName = this.typeName?.toPascalCase() ?: fieldName.toPascalCase()
ClassName("io.github.typesafegithub.workflows.actions.$actionPackageName", "$actionClassName.$typeName")
}
FloatTyping -> Float::class.asTypeName()
IntegerTyping -> Integer::class.asTypeName()

FloatTyping -> {
Float::class.asTypeName()
}

IntegerTyping -> {
Integer::class.asTypeName()
}

is IntegerWithSpecialValueTyping -> {
val typeName = this.typeName?.toPascalCase() ?: fieldName.toPascalCase()
ClassName("io.github.typesafegithub.workflows.actions.$actionPackageName", "$actionClassName.$typeName")
}
is ListOfTypings ->

is ListOfTypings -> {
List::class
.asClassName()
.parameterizedBy(typing.getClassName(actionPackageName, actionClassName, fieldName))
StringTyping -> String::class.asTypeName()
}

StringTyping -> {
String::class.asTypeName()
}
}

internal fun Typing.asString(): String =
when (this) {
BooleanTyping -> ".toString()"
is EnumTyping -> ".stringValue"
FloatTyping -> ".toString()"
IntegerTyping -> ".toString()"
is IntegerWithSpecialValueTyping -> ".integerValue.toString()"
BooleanTyping -> {
".toString()"
}

is EnumTyping -> {
".stringValue"
}

FloatTyping -> {
".toString()"
}

IntegerTyping -> {
".toString()"
}

is IntegerWithSpecialValueTyping -> {
".integerValue.toString()"
}

is ListOfTypings -> {
val mapValue: String =
when (typing) {
Expand All @@ -56,7 +86,10 @@ internal fun Typing.asString(): String =
}
".joinToString(\"${if (delimiter == "\n") "\\n" else delimiter}\")$mapValue"
}
else -> ""

else -> {
""
}
}

internal fun Typing.buildCustomType(
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation("io.kotest:kotest-framework-plugin-gradle:6.0.7")

implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8")
implementation("org.jmailen.gradle:kotlinter-gradle:5.2.0")
implementation("org.jmailen.gradle:kotlinter-gradle:5.3.0")

implementation(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.10.2"))
implementation(("org.jetbrains.kotlinx:kotlinx-coroutines-core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ fun PayloadEventParams.findAllObjects(
element
.flatMap { (subpath, entry) ->
when (entry) {
is JsonObject -> findAllObjects(entry, "$path.$subpath")
is JsonObject -> {
findAllObjects(entry, "$path.$subpath")
}

is JsonArray -> {
(entry.firstOrNull() as? JsonObject)
?.let { firtSchild -> findAllObjects(firtSchild, "$path/$subpath") }
?: nothing
}
else -> nothing

else -> {
nothing
}
}.toList()
}.toMap()
return result + Pair(path, element)
Expand Down Expand Up @@ -149,11 +155,14 @@ fun Map.Entry<String, JsonElement>.generatePropertySpec(
.initializer("%S", "github.$key.$child")
.build()
}
is JsonObject ->

is JsonObject -> {
PropertySpec
.builder(child, ClassName(PACKAGE, payloadClassName("$key.$child", filename)))
.initializer("%L", payloadClassName("$key.$child", filename))
.build()
}

is JsonArray -> {
PropertySpec
.builder(child, listOfStrings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ internal fun WorkflowBuilder.consistencyCheckJob(
) {
val checkoutActionVersion =
when (consistencyCheckJobConfig.checkoutActionVersion) {
CheckoutActionVersionSource.BundledWithLibrary -> "v4"
is CheckoutActionVersionSource.Given -> consistencyCheckJobConfig.checkoutActionVersion.version
is CheckoutActionVersionSource.InferFromClasspath ->
CheckoutActionVersionSource.BundledWithLibrary -> {
"v4"
}

is CheckoutActionVersionSource.Given -> {
consistencyCheckJobConfig.checkoutActionVersion.version
}

is CheckoutActionVersionSource.InferFromClasspath -> {
inferCheckoutActionVersionFromClasspath(
consistencyCheckJobConfig.checkoutActionVersion.checkoutActionClassFQN,
)
}
}

uses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,62 @@ private fun Job<*>.toYaml(): Map<String, Any?> =
@Suppress("CyclomaticComplexMethod")
public fun RunnerType.toYaml(): Any =
when (this) {
is Custom -> runsOn
is Labelled -> labels.toList()
is RunnerType.Group ->
is Custom -> {
runsOn
}

is Labelled -> {
labels.toList()
}

is RunnerType.Group -> {
mapOfNotNullValues(
"group" to name,
"labels" to labels?.toList(),
)
UbuntuLatest -> "ubuntu-latest"
WindowsLatest -> "windows-latest"
MacOSLatest -> "macos-latest"
Windows2025 -> "windows-2025"
Windows2022 -> "windows-2022"
Windows2019 -> "windows-2019"
Windows2016 -> "windows-2016"
Ubuntu2004 -> "ubuntu-20.04"
Ubuntu1804 -> "ubuntu-18.04"
MacOS11 -> "macos-11"
MacOS1015 -> "macos-10.15"
}

UbuntuLatest -> {
"ubuntu-latest"
}

WindowsLatest -> {
"windows-latest"
}

MacOSLatest -> {
"macos-latest"
}

Windows2025 -> {
"windows-2025"
}

Windows2022 -> {
"windows-2022"
}

Windows2019 -> {
"windows-2019"
}

Windows2016 -> {
"windows-2016"
}

Ubuntu2004 -> {
"ubuntu-20.04"
}

Ubuntu1804 -> {
"ubuntu-18.04"
}

MacOS11 -> {
"macos-11"
}

MacOS1015 -> {
"macos-10.15"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ internal fun Any.toYaml(): String {

private fun Any?.elementToYaml(emitter: Emitter) {
when (this) {
is Map<*, *> -> this.mapToYaml(emitter)
is List<*> -> this.listToYaml(emitter)
is String, is Int, is Float, is Double, is Boolean, null -> this.scalarToYaml(emitter)
is Map<*, *> -> {
this.mapToYaml(emitter)
}

is List<*> -> {
this.listToYaml(emitter)
}

is String, is Int, is Float, is Double, is Boolean, null -> {
this.scalarToYaml(emitter)
}

is StringWithComment -> {
this.value.scalarToYaml(emitter)
(" " + this.comment).commentToYaml(emitter)
}
else -> error("Serializing $this is not supported!")

else -> {
error("Serializing $this is not supported!")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ private fun Schedule.toAdditionalYaml(): List<Map<String, String>> = triggers.ma

private fun WorkflowDispatch.toAdditionalYaml(): Map<String, Any?> =
when {
inputs.isEmpty() -> emptyMap()
else ->
inputs.isEmpty() -> {
emptyMap()
}

else -> {
mapOf(
"inputs" to inputs.mapValues { (_, value) -> value.toYaml() },
)
}
}

private fun WorkflowDispatch.Input.toYaml(): Map<String, Any> =
Expand All @@ -170,13 +174,17 @@ private fun WorkflowDispatch.Input.toYaml(): Map<String, Any> =

private fun WorkflowCall.toAdditionalYaml(): Map<String, Any?> =
when {
inputs.isEmpty() -> emptyMap()
else ->
inputs.isEmpty() -> {
emptyMap()
}

else -> {
mapOfNotNullValues(
"inputs" to inputs.mapValues { (_, value) -> value.toYaml() },
"outputs" to outputs?.mapValues { (_, value) -> value.toYaml() },
"secrets" to secrets?.mapValues { (_, value) -> value.toYaml() },
)
}
}

private fun WorkflowCall.Input.toYaml(): Map<String, Any> =
Expand Down
Loading