Skip to content

Commit

Permalink
fix(abg): provide a checksum for maven metadata or consumers are unhappy
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Sep 8, 2024
1 parent c741439 commit e617e74
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.typesafegithub.workflows.mavenbinding

import java.security.MessageDigest

internal fun ByteArray.md5Checksum(): String {
val md5 = MessageDigest.getInstance("MD5")
val hashBytes = md5.digest(this)
return hashBytes.joinToString("") { "%02x".format(it) }
}

internal fun String.md5Checksum(): String = this.toByteArray(charset = Charsets.UTF_8).md5Checksum()
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ suspend fun ActionCoords.buildPackageArtifacts(githubToken: String): Map<String,
val mavenMetadata = buildMavenMetadataFile(owner = owner, name = name, githubToken = githubToken)
return mapOf(
"maven-metadata.xml" to mavenMetadata,
"maven-metadata.xml.md5" to mavenMetadata.md5Checksum(),
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.typesafegithub.workflows.mavenbinding

import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
import java.security.MessageDigest

sealed interface Artifact

Expand All @@ -28,11 +27,3 @@ fun ActionCoords.buildVersionArtifacts(): Map<String, Artifact>? {
"$name-$version.module.md5" to TextArtifact(module.md5Checksum()),
)
}

private fun ByteArray.md5Checksum(): String {
val md5 = MessageDigest.getInstance("MD5")
val hashBytes = md5.digest(this)
return hashBytes.joinToString("") { "%02x".format(it) }
}

private fun String.md5Checksum(): String = this.toByteArray(charset = Charsets.UTF_8).md5Checksum()

0 comments on commit e617e74

Please sign in to comment.