Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(abg): create JARs only when they are actually requested #1615

Merged
merged 2 commits into from
Sep 18, 2024
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 @@ -109,10 +109,10 @@ private fun Route.artifact(
val file = call.parameters["file"]!!
if (file in bindingArtifacts) {
when (val artifact = bindingArtifacts[file]) {
is TextArtifact -> call.respondText(artifact.data)
is TextArtifact -> call.respondText(text = artifact.data())
is JarArtifact ->
call.respondBytes(
bytes = artifact.data,
bytes = artifact.data(),
contentType = ContentType.parse("application/java-archive"),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import kotlin.io.path.div
import kotlin.io.path.writeText

internal data class Jars(
val mainJar: ByteArray,
val sourcesJar: ByteArray,
val mainJar: () -> ByteArray,
val sourcesJar: () -> ByteArray,
)

internal fun buildJars(
Expand All @@ -35,20 +35,28 @@ internal fun buildJars(
generateBinding(owner = owner, name = name, version = version).also {
if (it.isEmpty()) return null
}
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()

val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths)
val mainJarByteArrayOutputStream = ByteArrayOutputStream()
mainJarByteArrayOutputStream.createZipFile(pathWithJarContents)
pathWithJarContents.toFile().deleteRecursively()
val mainJar by lazy {
krzema12 marked this conversation as resolved.
Show resolved Hide resolved
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()
val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths)
val mainJarByteArrayOutputStream = ByteArrayOutputStream()
mainJarByteArrayOutputStream.createZipFile(pathWithJarContents)
pathWithJarContents.toFile().deleteRecursively()
compilationInputDir.toFile().deleteRecursively()
mainJarByteArrayOutputStream.toByteArray()
}

val sourcesJarByteArrayOutputStream = ByteArrayOutputStream()
sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir)
compilationInputDir.toFile().deleteRecursively()
val sourcesJar by lazy {
val (_, compilationInputDir) = binding.prepareDirectoryWithSources()
val sourcesJarByteArrayOutputStream = ByteArrayOutputStream()
sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir)
compilationInputDir.toFile().deleteRecursively()
sourcesJarByteArrayOutputStream.toByteArray()
}

return Jars(
mainJar = mainJarByteArrayOutputStream.toByteArray(),
sourcesJar = sourcesJarByteArrayOutputStream.toByteArray(),
mainJar = { mainJar },
sourcesJar = { sourcesJar },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCo
sealed interface Artifact

data class TextArtifact(
val data: String,
val data: () -> String,
) : Artifact

data class JarArtifact(
val data: ByteArray,
val data: () -> ByteArray,
) : Artifact

fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact>? {
Expand All @@ -18,12 +18,12 @@ fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact>? {
val module = buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version)
return mapOf(
"$name-$version.jar" to JarArtifact(jars.mainJar),
"$name-$version.jar.md5" to TextArtifact(jars.mainJar.md5Checksum()),
"$name-$version.jar.md5" to TextArtifact { jars.mainJar().md5Checksum() },
"$name-$version-sources.jar" to JarArtifact(jars.sourcesJar),
"$name-$version-sources.jar.md5" to TextArtifact(jars.sourcesJar.md5Checksum()),
"$name-$version.pom" to TextArtifact(pom),
"$name-$version.pom.md5" to TextArtifact(pom.md5Checksum()),
"$name-$version.module" to TextArtifact(module),
"$name-$version.module.md5" to TextArtifact(module.md5Checksum()),
"$name-$version-sources.jar.md5" to TextArtifact { jars.sourcesJar().md5Checksum() },
"$name-$version.pom" to TextArtifact { pom },
"$name-$version.pom.md5" to TextArtifact { pom.md5Checksum() },
"$name-$version.module" to TextArtifact { module },
"$name-$version.module.md5" to TextArtifact { module.md5Checksum() },
)
}
Loading