From b5e4c566cda9a93eaefe38b87dae75fc65990f8b Mon Sep 17 00:00:00 2001 From: Daniel Spiewak Date: Fri, 6 Mar 2020 22:08:05 -0700 Subject: [PATCH] Added githubSuppressPublicationWarning setting to better support resolver use-cases --- README.md | 1 + src/main/scala/sbtghpackages/GitHubPackagesKeys.scala | 2 ++ src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6f864e..0538323 100644 --- a/README.md +++ b/README.md @@ -130,5 +130,6 @@ The following setting keys are defined: - `githubRepository : String` The repository which hosts this project under the organization/user defined in the other setting - `githubActor : String` (*defaults to `GITHUB_ACTOR`*) *Your* GitHub username. This should almost never be specified in the build itself, but rather read from some external source. By default, it will read the `GITHUB_ACTOR` environment variable. To be extremely clear, this is the user who ran the `sbt` command, it is not *necessarily* the repository owner! - `githubTokenSource : TokenSource` (*defaults to `Environment("GITHUB_TOKEN")`*) Where the plugin should go to read the GitHub API token to use in authentication. `TokenSource` has two possible values: `Environment(variable: String)` and `GitConfig(key: String)`. You can compose multiple sources together using `||`, which will result in each being attempted in order from left to right. This is mostly just a convenience. You're free to do whatever you want. Just don't, like, put it in your build. +- `githubSuppressPublicationWarning : Boolean` (*defaults to `false`*) If you're just using this plugin as a means to *resolve* artifacts, not to publish them, the publication warning may serve as an annoyance more than anything else. Setting this to `true` will suppress the normal warning text when you fail to define `githubOwner` or `githubRepository`. `homepage` and `scmInfo` will be automatically set for you if `githubOwner` and `githubRepository` are themselves set. diff --git a/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala b/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala index 8a72af2..ade067e 100644 --- a/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala +++ b/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala @@ -24,6 +24,8 @@ trait GitHubPackagesKeys { val githubActor = settingKey[String]("The github user to use when authenticating (defaults to github.actor in the git config)") val githubTokenSource = settingKey[TokenSource]("Where to get the API token used in publication (defaults to github.token in the git config)") + + val githubSuppressPublicationWarning = settingKey[Boolean]("Whether or not to suppress the publication warning (default: false, meaning the warning will be printed)") } object GitHubPackagesKeys extends GitHubPackagesKeys diff --git a/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala b/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala index 0fcdb27..a743fdd 100644 --- a/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala +++ b/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala @@ -58,6 +58,7 @@ object GitHubPackagesPlugin extends AutoPlugin { val packagePublishSettings = Seq( publishTo := { + val suppress = githubSuppressPublicationWarning.value val log = streams.value.log val ms = publishMavenStyle.value val back = for { @@ -73,7 +74,7 @@ object GitHubPackagesPlugin extends AutoPlugin { back orElse { GitHubPackagesPlugin synchronized { - if (!alreadyWarned) { + if (!alreadyWarned && !suppress) { log.warn("undefined keys `githubOwner` and `githubRepository`") log.warn("retaining pre-existing publication settings") alreadyWarned = true @@ -132,4 +133,6 @@ object GitHubPackagesPlugin extends AutoPlugin { s"GitHub Package Registry (${owner}${if (repo != "_") s"/$repo" else ""})" override def projectSettings = packagePublishSettings + + override def buildSettings = Seq(githubSuppressPublicationWarning := false) }