Skip to content

Commit a73a4be

Browse files
authored
Ensure publish actually fails on a failed upload (#3853)
1 parent 420ca08 commit a73a4be

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
984984
}
985985

986986
errors.toList match {
987-
case (h @ (_, _, e: Upload.Error.HttpError)) :: _
987+
case (h @ (_, _, e: Upload.Error.HttpError)) :: t
988988
if repoParams0.isSonatype && errors.distinctBy(_._3.getMessage()).size == 1 =>
989989
logger.log(s"Error message: ${e.getMessage}")
990990
val httpCodeRegex = "HTTP (\\d+)\n.*".r
@@ -1000,9 +1000,10 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
10001000
| -> have you registered your organisation yet?
10011001
|""".stripMargin
10021002
)
1003-
case _ => throw new UploadError(::(h, Nil))
1003+
value(Left(new UploadError(::(h, t))))
1004+
case _ => value(Left(new UploadError(::(h, t))))
10041005
}
1005-
case _ :: _ if repoParams0.isSonatype && errors.forall {
1006+
case h :: t if repoParams0.isSonatype && errors.forall {
10061007
case (_, _, _: Upload.Error.Unauthorized) => true
10071008
case _ => false
10081009
} =>
@@ -1017,6 +1018,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
10171018
| -> consult publish subcommand documentation
10181019
|""".stripMargin
10191020
)
1021+
value(Left(new UploadError(::(h, t))))
10201022
case h :: t =>
10211023
value(Left(new UploadError(::(h, t))))
10221024
case Nil =>

modules/integration/src/test/scala/scala/cli/integration/PublishTestDefinitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class PublishTestDefinitions extends ScalaCliSuite with TestScalaVersio
1313
_: TestScalaVersion =>
1414
protected def extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
1515

16-
private object TestCase {
16+
protected object TestCase {
1717
val expectedMessage = "Hello"
1818
val org = "org.virtuslab.scalacli.test"
1919
val name = "simple"

modules/integration/src/test/scala/scala/cli/integration/PublishTestsDefault.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package scala.cli.integration
22

33
import com.eed3si9n.expecty.Expecty.expect
44

5+
import java.nio.file.Paths
6+
57
class PublishTestsDefault extends PublishTestDefinitions with TestDefault {
68
test("Pure Java") {
79
val testOrg = "test-org.foo"
@@ -202,4 +204,41 @@ class PublishTestsDefault extends PublishTestDefinitions with TestDefault {
202204
checkCredentialsWarning(okRes.out.text())
203205
}
204206
}
207+
208+
test(s"simple failed upload") {
209+
val secretKey = {
210+
val uri = Thread.currentThread().getContextClassLoader
211+
.getResource("test-keys/key.skr")
212+
.toURI
213+
os.Path(Paths.get(uri))
214+
}
215+
216+
val signingOptions = Seq(
217+
"--secret-key",
218+
s"file:$secretKey",
219+
"--secret-key-password",
220+
"value:1234",
221+
"--signer",
222+
"bc"
223+
)
224+
225+
TestCase.testInputs().fromRoot { root =>
226+
val r = os.proc(
227+
TestUtil.cli,
228+
"--power",
229+
"publish",
230+
extraOptions,
231+
signingOptions,
232+
"project",
233+
"--publish-repository",
234+
"sonatype:central"
235+
).call(
236+
cwd = root,
237+
stdin = os.Inherit,
238+
stdout = os.Inherit,
239+
check = false
240+
)
241+
expect(r.exitCode != 0)
242+
}
243+
}
205244
}

0 commit comments

Comments
 (0)