Skip to content

Commit 59adfbc

Browse files
Merge pull request #1534 from alexarchambault/missing-org-name
Check for missing org and version at the same time in publish
2 parents 058a092 + 287f336 commit 59adfbc

File tree

2 files changed

+77
-27
lines changed

2 files changed

+77
-27
lines changed

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

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -407,35 +407,29 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
407407
}
408408
}
409409

410-
private def buildFileSet(
411-
build: Build.Successful,
412-
docBuildOpt: Option[Build.Successful],
413-
workingDir: os.Path,
414-
now: Instant,
415-
isIvy2LocalLike: Boolean,
416-
isCi: Boolean,
417-
logger: Logger
418-
): Either[BuildException, (FileSet, (coursier.core.Module, String))] = either {
419-
420-
logger.debug(s"Preparing project ${build.project.projectName}")
421-
422-
val publishOptions = build.options.notForBloopOptions.publishOptions
410+
private def orgNameVersion(
411+
publishOptions: scala.build.options.PublishOptions,
412+
workspace: os.Path,
413+
logger: Logger,
414+
scalaArtifactsOpt: Option[ScalaArtifacts],
415+
isCi: Boolean
416+
): Either[BuildException, (String, String, String)] = {
423417

424-
lazy val orgNameOpt = GitRepo.maybeGhRepoOrgName(build.inputs.workspace, logger)
418+
lazy val orgNameOpt = GitRepo.maybeGhRepoOrgName(workspace, logger)
425419

426-
val org = publishOptions.organization match {
427-
case Some(org0) => org0.value
428-
case None => value(defaultOrganization(orgNameOpt.map(_._1), logger))
420+
val maybeOrg = publishOptions.organization match {
421+
case Some(org0) => Right(org0.value)
422+
case None => defaultOrganization(orgNameOpt.map(_._1), logger)
429423
}
430424

431425
val moduleName = publishOptions.moduleName match {
432426
case Some(name0) => name0.value
433427
case None =>
434428
val name = publishOptions.name match {
435429
case Some(name0) => name0.value
436-
case None => defaultName(build.inputs.workspace, logger)
430+
case None => defaultName(workspace, logger)
437431
}
438-
build.artifacts.scalaOpt.map(_.params) match {
432+
scalaArtifactsOpt.map(_.params) match {
439433
case Some(scalaParams) =>
440434
val pf = publishOptions.scalaPlatformSuffix.getOrElse {
441435
scalaParams.platform.fold("")("_" + _)
@@ -450,26 +444,57 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
450444
}
451445
}
452446

453-
val ver = publishOptions.version match {
454-
case Some(ver0) => ver0.value
447+
val maybeVer = publishOptions.version match {
448+
case Some(ver0) => Right(ver0.value)
455449
case None =>
456450
val computeVer = publishOptions.contextual(isCi).computeVersion.orElse {
457-
def isGitRepo = GitRepo.gitRepoOpt(build.inputs.workspace).isDefined
451+
def isGitRepo = GitRepo.gitRepoOpt(workspace).isDefined
458452
val default = defaultComputeVersion(!isCi && isGitRepo)
459453
if (default.isDefined)
460454
logger.message(
461455
s"Using directive ${defaultVersionError.directiveName} not set, assuming git:tag as publish.computeVersion"
462456
)
463457
default
464458
}
465-
value {
466-
computeVer match {
467-
case Some(cv) => cv.get(build.inputs.workspace)
468-
case None => defaultVersion
469-
}
459+
computeVer match {
460+
case Some(cv) => cv.get(workspace)
461+
case None => defaultVersion
470462
}
471463
}
472464

465+
(maybeOrg, maybeVer)
466+
.traverseN
467+
.left.map(CompositeBuildException(_))
468+
.map {
469+
case (org, ver) =>
470+
(org, moduleName, ver)
471+
}
472+
}
473+
474+
private def buildFileSet(
475+
build: Build.Successful,
476+
docBuildOpt: Option[Build.Successful],
477+
workingDir: os.Path,
478+
now: Instant,
479+
isIvy2LocalLike: Boolean,
480+
isCi: Boolean,
481+
logger: Logger
482+
): Either[BuildException, (FileSet, (coursier.core.Module, String))] = either {
483+
484+
logger.debug(s"Preparing project ${build.project.projectName}")
485+
486+
val publishOptions = build.options.notForBloopOptions.publishOptions
487+
488+
val (org, moduleName, ver) = value {
489+
orgNameVersion(
490+
publishOptions,
491+
build.inputs.workspace,
492+
logger,
493+
build.artifacts.scalaOpt,
494+
isCi
495+
)
496+
}
497+
473498
logger.message(s"Publishing $org:$moduleName:$ver")
474499

475500
val mainJar = {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,29 @@ class PublishTestsDefault extends PublishTestDefinitions(scalaVersionOpt = None)
177177
expect(output == "Hello from Python")
178178
}
179179
}
180+
181+
test("missing org and version") {
182+
// Missing org and missing version should be reported at the same time,
183+
// rather than one at a time.
184+
val inputs = TestInputs(
185+
os.rel / "Messages.scala" ->
186+
"""package messages
187+
|
188+
|object Messages {
189+
| def hello = "Hello"
190+
|}
191+
|""".stripMargin
192+
)
193+
inputs.fromRoot { root =>
194+
val tmpDir = os.temp.dir(prefix = "scala-cli-publish-test")
195+
for (f <- os.list(root))
196+
os.copy.into(f, tmpDir)
197+
val publishRepo = root / "the-repo"
198+
val res = os.proc(TestUtil.cli, "publish", "--publish-repo", publishRepo, tmpDir)
199+
.call(cwd = root, check = false, mergeErrIntoOut = true)
200+
val output = res.out.text()
201+
expect(output.contains("Missing organization"))
202+
expect(output.contains("Missing version"))
203+
}
204+
}
180205
}

0 commit comments

Comments
 (0)