Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

Skip unpublish on projects marked skip on publish #168

Merged
merged 2 commits into from
May 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/main/scala/BintrayPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ object BintrayPlugin extends AutoPlugin {
}
},
bintrayEnsureBintrayPackageExists := ensurePackageTask.value,
bintrayUnpublish := Def.task {
val repo = bintrayRepo.value
repo.unpublish(bintrayPackage.value, version.value, streams.value.log)
}.dependsOn(bintrayEnsureBintrayPackageExists, bintrayEnsureLicenses).value,
bintrayUnpublish := dynamicallyBintrayUnpublish.value,
bintrayRemoteSign := {
val repo = bintrayRepo.value
repo.remoteSign(bintrayPackage.value, version.value, streams.value.log)
Expand Down Expand Up @@ -155,6 +152,26 @@ object BintrayPlugin extends AutoPlugin {
(if (bintrayReleaseOnPublish.value) bintrayRelease else warnToRelease).dependsOn(publishTask(publishConfiguration, deliver))
} dependsOn(bintrayEnsureBintrayPackageExists, bintrayEnsureLicenses)

// uses taskDyn because it can return one of two potential tasks
// as its result, each with their own dependencies
// see also: http://www.scala-sbt.org/0.13/docs/Tasks.html#Dynamic+Computations+with
private def dynamicallyBintrayUnpublish: Initialize[Task[Unit]] =
taskDyn {
val repo = bintrayRepo.value
val sk = ((skip in publish) ?? false).value
val s = streams.value
val ref = thisProjectRef.value
if (sk) Def.task {
s.log.debug(s"Skipping bintrayUnpublish for ${ref.project}")
} else dynamicallyBintrayUnpublish0
}

private def dynamicallyBintrayUnpublish0: Initialize[Task[Unit]] =
Def.task {
val repo = bintrayRepo.value
repo.unpublish(bintrayPackage.value, version.value, streams.value.log)
}.dependsOn(bintrayEnsureBintrayPackageExists, bintrayEnsureLicenses)

private def warnToRelease: Initialize[Task[Unit]] =
task {
val log = streams.value.log
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/BintrayRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ case class BintrayRepo(credential: BintrayCredentials, org: Option[String], repo
/** unpublish (delete) a version of a package */
def unpublish(packageName: String, vers: String, log: Logger): Unit =
await.result(repo.get(packageName).version(vers).delete(asStatusAndBody)) match {
case (200, _) => log.info(s"$owner/$packageName@$vers was discarded")
case (200, _) => log.info(s"$owner/$packageName@$vers was discarded")
case (404, _) => log.warn(s"$owner/$packageName@$vers was not found")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll include this anyway. Seems reasonable to just warn the user when an arifact is not found.

case (_, fail) => sys.error(s"failed to discard $owner/$packageName@$vers: $fail")
}

Expand Down