Skip to content

Commit

Permalink
Fail on duplicate Github file names.
Browse files Browse the repository at this point in the history
Closes #64
  • Loading branch information
modmuss50 committed Nov 13, 2024
1 parent 1601ccb commit 0bf970b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/me/modmuss50/mpp/platforms/github/Github.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ abstract class Github @Inject constructor(name: String) : Platform(name), Github
files.add(file.get().asFile)
}

val noneUnique = files.groupingBy { it.name }.eachCount().filter { it.value > 1 }
if (noneUnique.isNotEmpty()) {
val noneUniqueNames = noneUnique.keys.joinToString(", ")
throw IllegalStateException("Github file names must be unique within a release, found duplicates: $noneUniqueNames")
}

for (file in files) {
release.uploadAsset(file, "application/java-archive")
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/kotlin/me/modmuss50/mpp/test/github/GithubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import me.modmuss50.mpp.test.IntegrationTest
import me.modmuss50.mpp.test.MockWebServer
import org.gradle.testkit.runner.TaskOutcome
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals

class GithubTest : IntegrationTest {
Expand Down Expand Up @@ -166,4 +167,34 @@ class GithubTest : IntegrationTest {

assertEquals(TaskOutcome.SUCCESS, result.task(":publishGithub")!!.outcome)
}

@Test
fun failOnDuplicateNames() {
val server = MockWebServer(MockGithubApi())

val result = gradleTest()
.buildScript(
"""
publishMods {
file = tasks.jar.flatMap { it.archiveFile }
changelog = "Hello!"
version = "1.0.0"
type = STABLE
github {
accessToken = "123"
repository = "test/example"
commitish = "main"
apiEndpoint = "${server.endpoint}"
tagName = "release/1.0.0"
additionalFiles.from(tasks.jar.flatMap { it.archiveFile })
}
}
""".trimIndent(),
)
.run("publishGithub")
server.close()

assertEquals(TaskOutcome.FAILED, result.task(":publishGithub")!!.outcome)
assertContains(result.output, "Github file names must be unique within a release, found duplicates: mpp-example.jar")
}
}

0 comments on commit 0bf970b

Please sign in to comment.