Skip to content

Commit 7b90b6b

Browse files
authored
feat(server): provide checksums for Maven artifacts (#1357)
Part of #1318. Otherwise, Kotlin Script prints long warnings including scary stacktraces for each artifact, see PR description.
1 parent 8e6e794 commit 7b90b6b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.typesafegithub.workflows.mavenbinding
22

3+
import java.security.MessageDigest
4+
35
sealed interface Artifact
46

57
data class TextArtifact(val data: String) : Artifact
@@ -19,9 +21,24 @@ data class JarArtifact(val data: ByteArray) : Artifact {
1921
}
2022
}
2123

22-
fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact> =
23-
mapOf(
24-
"$name-$version.jar" to JarArtifact(buildJar(owner = owner, name = name.replace("__", "/"), version = version)),
25-
"$name-$version.pom" to TextArtifact(buildPomFile(owner = owner, name = name.replace("__", "/"), version = version)),
26-
"$name-$version.module" to TextArtifact(buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version)),
24+
fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact> {
25+
val jar = buildJar(owner = owner, name = name.replace("__", "/"), version = version)
26+
val pom = buildPomFile(owner = owner, name = name.replace("__", "/"), version = version)
27+
val module = buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version)
28+
return mapOf(
29+
"$name-$version.jar" to JarArtifact(jar),
30+
"$name-$version.jar.md5" to TextArtifact(jar.md5Checksum()),
31+
"$name-$version.pom" to TextArtifact(pom),
32+
"$name-$version.pom.md5" to TextArtifact(pom.md5Checksum()),
33+
"$name-$version.module" to TextArtifact(module),
34+
"$name-$version.module.md5" to TextArtifact(module.md5Checksum()),
2735
)
36+
}
37+
38+
private fun ByteArray.md5Checksum(): String {
39+
val md5 = MessageDigest.getInstance("MD5")
40+
val hashBytes = md5.digest(this)
41+
return hashBytes.joinToString("") { "%02x".format(it) }
42+
}
43+
44+
private fun String.md5Checksum(): String = this.toByteArray(charset = Charsets.UTF_8).md5Checksum()

0 commit comments

Comments
 (0)