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

Commit

Permalink
Merge pull request #168 from seglo/seglo/skip-on-unpublish
Browse files Browse the repository at this point in the history
Skip unpublish on projects marked skip on publish
  • Loading branch information
eed3si9n authored May 11, 2019
2 parents 27a6323 + 235b89f commit bfe0265
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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")
case (_, fail) => sys.error(s"failed to discard $owner/$packageName@$vers: $fail")
}

Expand Down

0 comments on commit bfe0265

Please sign in to comment.