Skip to content

Commit f173834

Browse files
committed
feat(abg): only create sources and jars when they are actually requested
1 parent 2118339 commit f173834

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ private fun Route.artifact(
109109
val file = call.parameters["file"]!!
110110
if (file in bindingArtifacts) {
111111
when (val artifact = bindingArtifacts[file]) {
112-
is TextArtifact -> call.respondText(artifact.data)
112+
is TextArtifact -> call.respondText(text = artifact.data())
113113
is JarArtifact ->
114114
call.respondBytes(
115-
bytes = artifact.data,
115+
bytes = artifact.data(),
116116
contentType = ContentType.parse("application/java-archive"),
117117
)
118118

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import kotlin.io.path.div
2222
import kotlin.io.path.writeText
2323

2424
internal data class Jars(
25-
val mainJar: ByteArray,
26-
val sourcesJar: ByteArray,
25+
val mainJar: () -> ByteArray,
26+
val sourcesJar: () -> ByteArray,
2727
)
2828

2929
internal fun buildJars(
@@ -35,18 +35,25 @@ internal fun buildJars(
3535
generateBinding(owner = owner, name = name, version = version).also {
3636
if (it.isEmpty()) return null
3737
}
38-
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()
3938

40-
val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths)
41-
val mainJarByteArrayOutputStream = ByteArrayOutputStream()
42-
mainJarByteArrayOutputStream.createZipFile(pathWithJarContents)
39+
val mainJar by lazy {
40+
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()
41+
val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths)
42+
val mainJarByteArrayOutputStream = ByteArrayOutputStream()
43+
mainJarByteArrayOutputStream.createZipFile(pathWithJarContents)
44+
mainJarByteArrayOutputStream.toByteArray()
45+
}
4346

44-
val sourcesJarByteArrayOutputStream = ByteArrayOutputStream()
45-
sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir)
47+
val sourcesJar by lazy {
48+
val (_, compilationInputDir) = binding.prepareDirectoryWithSources()
49+
val sourcesJarByteArrayOutputStream = ByteArrayOutputStream()
50+
sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir)
51+
sourcesJarByteArrayOutputStream.toByteArray()
52+
}
4653

4754
return Jars(
48-
mainJar = mainJarByteArrayOutputStream.toByteArray(),
49-
sourcesJar = sourcesJarByteArrayOutputStream.toByteArray(),
55+
mainJar = { mainJar },
56+
sourcesJar = { sourcesJar },
5057
)
5158
}
5259

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import java.security.MessageDigest
66
sealed interface Artifact
77

88
data class TextArtifact(
9-
val data: String,
9+
val data: () -> String,
1010
) : Artifact
1111

1212
data class JarArtifact(
13-
val data: ByteArray,
13+
val data: () -> ByteArray,
1414
) : Artifact
1515

1616
fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact>? {
@@ -19,13 +19,13 @@ fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact>? {
1919
val module = buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version)
2020
return mapOf(
2121
"$name-$version.jar" to JarArtifact(jars.mainJar),
22-
"$name-$version.jar.md5" to TextArtifact(jars.mainJar.md5Checksum()),
22+
"$name-$version.jar.md5" to TextArtifact { jars.mainJar().md5Checksum() },
2323
"$name-$version-sources.jar" to JarArtifact(jars.sourcesJar),
24-
"$name-$version-sources.jar.md5" to TextArtifact(jars.sourcesJar.md5Checksum()),
25-
"$name-$version.pom" to TextArtifact(pom),
26-
"$name-$version.pom.md5" to TextArtifact(pom.md5Checksum()),
27-
"$name-$version.module" to TextArtifact(module),
28-
"$name-$version.module.md5" to TextArtifact(module.md5Checksum()),
24+
"$name-$version-sources.jar.md5" to TextArtifact { jars.sourcesJar().md5Checksum() },
25+
"$name-$version.pom" to TextArtifact { pom },
26+
"$name-$version.pom.md5" to TextArtifact { pom.md5Checksum() },
27+
"$name-$version.module" to TextArtifact { module },
28+
"$name-$version.module.md5" to TextArtifact { module.md5Checksum() },
2929
)
3030
}
3131

0 commit comments

Comments
 (0)