Skip to content
Closed
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
1 change: 1 addition & 0 deletions action-binding-generator/api/action-binding-generator.api
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public final class io/github/typesafegithub/workflows/actionbindinggenerator/dom
}

public final class io/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion : java/lang/Enum {
public static final field COMMIT_LENIENT Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
public static final field FULL Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
public static final field MAJOR Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
public static final field MINOR Lio/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.typesafegithub.workflows.actionbindinggenerator.domain

import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.COMMIT_LENIENT
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL

public data class ActionCoords(
Expand Down Expand Up @@ -36,6 +37,8 @@ public val ActionCoords.prettyPrint: String get() = "$prettyPrintWithoutVersion@

public val ActionCoords.prettyPrintWithoutVersion: String get() = "$owner/$fullName${
significantVersion.takeUnless { it == FULL }?.let { " with $it version" } ?: ""
}${
if ((significantVersion == COMMIT_LENIENT) && (comment != null)) " and comment '$comment'" else ""
}"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public enum class SignificantVersion {
*/
MINOR,

/**
* Write the commit ID as the version to the generated YAML.
*/
COMMIT_LENIENT,

/**
* Write the full version to the generated YAML.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.squareup.kotlinpoet.buildCodeBlock
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionTypings
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.MetadataRevision
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.COMMIT_LENIENT
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MAJOR
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MINOR
Expand Down Expand Up @@ -465,7 +466,7 @@ private fun TypeSpec.Builder.inheritsFromRegularAction(
when (coords.significantVersion) {
MAJOR -> coords.version.majorVersion
MINOR -> coords.version.minorVersion
FULL -> coords.version
COMMIT_LENIENT, FULL -> coords.version
},
).also {
if (coords.comment != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.github.typesafegithub.workflows.jitbindingserver

import com.sksamuel.aedile.core.LoadingCache
import io.github.oshai.kotlinlogging.KotlinLogging.logger
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPrint
import io.github.typesafegithub.workflows.mavenbinding.BindingsServerRequest
Expand Down Expand Up @@ -105,19 +104,11 @@ private fun Route.getArtifact(
}

internal fun prefetchBindingArtifacts(
coords: Collection<ActionCoords>,
coords: Collection<BindingsServerRequest>,
bindingsCache: LoadingCache<BindingsServerRequest, CachedVersionArtifact>,
) {
prefetchScope.launch {
bindingsCache.getAll(
coords.map {
BindingsServerRequest(
rawName = it.name,
rawVersion = it.version,
actionCoords = it,
)
},
)
bindingsCache.getAll(coords)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.sksamuel.aedile.core.LoadingCache
import com.sksamuel.aedile.core.asLoadingCache
import com.sksamuel.aedile.core.refreshAfterWrite
import io.github.oshai.kotlinlogging.KotlinLogging.logger
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.mavenbinding.BindingsServerRequest
import io.github.typesafegithub.workflows.mavenbinding.VersionArtifacts
import io.github.typesafegithub.workflows.mavenbinding.buildPackageArtifacts
Expand Down Expand Up @@ -72,7 +71,7 @@ fun Application.appModule(
buildPackageArtifacts: suspend (
BindingsServerRequest,
String,
(Collection<ActionCoords>) -> Unit,
(Collection<BindingsServerRequest>) -> Unit,
MeterRegistry,
) -> Map<String, String>,
getGithubAuthToken: () -> String,
Expand Down Expand Up @@ -119,7 +118,7 @@ private fun buildMetadataCache(
buildPackageArtifacts: suspend (
BindingsServerRequest,
String,
(Collection<ActionCoords>) -> Unit,
(Collection<BindingsServerRequest>) -> Unit,
MeterRegistry,
) -> Map<String, String>,
getGithubAuthToken: () -> String,
Expand All @@ -128,7 +127,7 @@ private fun buildMetadataCache(
.newBuilder()
.refreshAfterWrite(1.hours)
.recordStats()
.asLoadingCache<BindingsServerRequest, CachedMetadataArtifact> {
.asLoadingCache {
buildPackageArtifacts(
it,
getGithubAuthToken(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.typesafegithub.workflows.jitbindingserver

import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.COMMIT_LENIENT
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
import io.github.typesafegithub.workflows.mavenbinding.BindingsServerRequest
import io.ktor.http.Parameters
Expand All @@ -23,11 +24,6 @@ fun Parameters.parseRequest(extractVersion: Boolean): BindingsServerRequest? {
.entries
.find { "$it" == significantVersionString }
} ?: FULL
val pinToCommit =
nameAndPathAndSignificantVersionParts
.drop(1)
.takeIf { it.isNotEmpty() }
?.single() == "commit_lenient"
val nameAndPathParts = nameAndPath.split("__")
val name = nameAndPathParts.first()
val path =
Expand All @@ -38,7 +34,7 @@ fun Parameters.parseRequest(extractVersion: Boolean): BindingsServerRequest? {
val version =
if (extractVersion) {
val versionPart = this["version"]!!
if (pinToCommit) {
if (significantVersion == COMMIT_LENIENT) {
val versionParts = versionPart.split("__")
if (versionParts.size < 2) {
return null
Expand All @@ -50,7 +46,8 @@ fun Parameters.parseRequest(extractVersion: Boolean): BindingsServerRequest? {
} else {
"irrelevant"
}
val comment = if (pinToCommit && extractVersion) this["version"]!!.split("__")[0] else null
val comment =
if ((significantVersion == COMMIT_LENIENT) && extractVersion) this["version"]!!.split("__")[0] else null
val versionForTypings = if (extractVersion) this["version"]!!.split("__")[0] else "irrelevant"

return BindingsServerRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.typesafegithub.workflows.jitbindingserver

import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingActualSource
import io.github.typesafegithub.workflows.mavenbinding.BindingsServerRequest
import io.github.typesafegithub.workflows.mavenbinding.TextArtifact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class MetadataRoutesTest :
(
BindingsServerRequest,
String,
(Collection<ActionCoords>) -> Unit,
(Collection<BindingsServerRequest>) -> Unit,
MeterRegistry?,
) -> Map<String, String>,
>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.typesafegithub.workflows.jitbindingserver

import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.COMMIT_LENIENT
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MAJOR
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MINOR
Expand Down Expand Up @@ -123,7 +124,7 @@ class RequestParsingTest :
owner = "o",
name = "act",
version = "323898970401d85df44b3324a610af9a862d54b3",
significantVersion = FULL,
significantVersion = COMMIT_LENIENT,
comment = "v1.2.3",
versionForTypings = "v1.2.3",
path = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import arrow.core.Either
import arrow.core.getOrElse
import io.github.oshai.kotlinlogging.KotlinLogging.logger
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.COMMIT_LENIENT
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
import io.github.typesafegithub.workflows.shared.internal.fetchAvailableVersions
import io.github.typesafegithub.workflows.shared.internal.model.Version
Expand All @@ -12,7 +13,7 @@ import java.time.format.DateTimeFormatter

private val logger = logger { }

internal suspend fun ActionCoords.buildMavenMetadataFile(
internal suspend fun BindingsServerRequest.buildMavenMetadataFile(
githubAuthToken: String,
meterRegistry: MeterRegistry? = null,
fetchAvailableVersions: suspend (
Expand All @@ -21,15 +22,28 @@ internal suspend fun ActionCoords.buildMavenMetadataFile(
githubAuthToken: String?,
meterRegistry: MeterRegistry?,
) -> Either<String, List<Version>> = ::fetchAvailableVersions,
prefetchBindingArtifacts: (Collection<ActionCoords>) -> Unit = {},
prefetchBindingArtifacts: (Collection<BindingsServerRequest>) -> Unit = {},
): String? {
val availableVersions =
fetchAvailableVersions(owner, name, githubAuthToken, meterRegistry)
fetchAvailableVersions(actionCoords.owner, actionCoords.name, githubAuthToken, meterRegistry)
.getOrElse {
logger.error { it }
emptyList()
}.filter { it.isMajorVersion() || (significantVersion < FULL) }
prefetchBindingArtifacts(availableVersions.map { copy(version = "$it") })
}.filter { it.isMajorVersion() || (actionCoords.significantVersion < FULL) }
val commitLenient = actionCoords.significantVersion == COMMIT_LENIENT
prefetchBindingArtifacts(
availableVersions.map {
copy(
rawVersion = "$it${if (commitLenient) "__${it.sha}" else ""}",
actionCoords =
actionCoords.copy(
version = if (commitLenient) it.sha!! else "$it",
comment = if (commitLenient) "$it" else null,
versionForTypings = "$it",
),
)
},
)
val newest = availableVersions.maxOrNull() ?: return null
val lastUpdated =
DateTimeFormatter
Expand All @@ -38,14 +52,14 @@ internal suspend fun ActionCoords.buildMavenMetadataFile(
return """
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>$owner</groupId>
<artifactId>$name</artifactId>
<groupId>${actionCoords.owner}</groupId>
<artifactId>$rawName</artifactId>
<versioning>
<latest>$newest</latest>
<release>$newest</release>
<latest>$newest${if (commitLenient) "__${newest.sha}" else ""}</latest>
<release>$newest${if (commitLenient) "__${newest.sha}" else ""}</release>
<versions>
${availableVersions.joinToString(separator = "\n") {
" <version>$it</version>"
" <version>$it${if (commitLenient) "__${it.sha}" else ""}</version>"
}}
</versions>
<lastUpdated>$lastUpdated</lastUpdated>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ internal fun BindingsServerRequest.buildModuleFile(
"formatVersion": "1.1",
"component": {
"group": "${actionCoords.owner}",
"module": "${actionCoords.name}",
"version": "${actionCoords.version}",
"module": "$rawName",
"version": "$rawVersion",
"attributes": {
"org.gradle.status": "release"
}
Expand All @@ -42,7 +42,7 @@ internal fun BindingsServerRequest.buildModuleFile(
"files": [
{
"name": "$rawName-$rawVersion.jar",
"url": "$rawName-$rawName.jar",
"url": "$rawName-$rawVersion.jar",
"size": $mainJarSize,
"sha512": "$mainJarSha512Checksum",
"sha256": "$mainJarSha256Checksum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import io.micrometer.core.instrument.MeterRegistry
suspend fun buildPackageArtifacts(
bindingsServerRequest: BindingsServerRequest,
githubAuthToken: String,
prefetchBindingArtifacts: (Collection<ActionCoords>) -> Unit,
prefetchBindingArtifacts: (Collection<BindingsServerRequest>) -> Unit,
meterRegistry: MeterRegistry,
): Map<String, String> {
val mavenMetadata =
bindingsServerRequest.actionCoords.buildMavenMetadataFile(
bindingsServerRequest.buildMavenMetadataFile(
githubAuthToken = githubAuthToken,
prefetchBindingArtifacts = prefetchBindingArtifacts,
meterRegistry = meterRegistry,
Expand Down
Loading
Loading