From 5f5cf7583e2f35dc8deb338638279230897ee2e0 Mon Sep 17 00:00:00 2001 From: Maksim Ochenashko Date: Wed, 15 Dec 2021 11:49:19 +0200 Subject: [PATCH 1/3] Introduce Publisher and Resolver plugins. --- README.md | 41 +++++-- build.sbt | 43 ++++++- .../sbtghpackages/GitHubRepository.scala | 38 ++++++ .../scala/sbtghpackages/TokenSource.scala | 1 + .../src/main/scala/sbtghpackages/Utils.scala | 73 +++++++++++ .../GitHubPackagesPublisherKeys.scala | 27 +++++ .../GitHubPackagesPublisherPlugin.scala | 112 +++++++++++++++++ .../publish-missing-token/build.sbt | 5 + .../project/build.properties | 1 + .../publish-missing-token/project/plugins.sbt | 5 + .../sbtghpackages/publish-missing-token/test | 3 + .../startup-empty-settings/build.sbt | 2 + .../project/build.properties | 1 + .../project/plugins.sbt | 5 + .../sbtghpackages/startup-empty-settings/test | 3 + .../sbt-test/sbtghpackages/startup/build.sbt | 5 + .../startup/project/build.properties | 1 + .../sbtghpackages/startup/project/plugins.sbt | 5 + .../src/sbt-test/sbtghpackages/startup/test | 3 + .../GitHubPackagesResolverKeys.scala | 25 ++++ .../GitHubPackagesResolverPlugin.scala | 59 +++++++++ .../resolve-missing-token/build.sbt | 5 + .../project/build.properties | 1 + .../resolve-missing-token/project/plugins.sbt | 5 + .../sbtghpackages/resolve-missing-token/test | 2 + .../startup-empty-settings/build.sbt | 2 + .../project/build.properties | 1 + .../project/plugins.sbt | 5 + .../sbtghpackages/startup-empty-settings/test | 1 + .../sbt-test/sbtghpackages/startup/build.sbt | 5 + .../startup/project/build.properties | 1 + .../sbtghpackages/startup/project/plugins.sbt | 5 + .../src/sbt-test/sbtghpackages/startup/test | 1 + project/build.properties | 2 +- .../sbtghpackages/GitHubPackagesKeys.scala | 8 +- .../sbtghpackages/GitHubPackagesPlugin.scala | 114 +++--------------- .../sbtghpackages/property-token/build.sbt | 5 + .../property-token/project/build.properties | 1 + .../property-token/project/plugins.sbt | 5 + .../sbtghpackages/property-token/test | 2 + .../publish/project/build.properties | 2 +- .../startup/project/build.properties | 2 +- 42 files changed, 515 insertions(+), 118 deletions(-) create mode 100644 modules/common/src/main/scala/sbtghpackages/GitHubRepository.scala rename {src => modules/common/src}/main/scala/sbtghpackages/TokenSource.scala (94%) create mode 100644 modules/common/src/main/scala/sbtghpackages/Utils.scala create mode 100644 modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherKeys.scala create mode 100644 modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherPlugin.scala create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/build.sbt create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/build.properties create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/plugins.sbt create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/test create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/test create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup/build.sbt create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup/project/build.properties create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup/project/plugins.sbt create mode 100644 modules/publisher/src/sbt-test/sbtghpackages/startup/test create mode 100644 modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverKeys.scala create mode 100644 modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverPlugin.scala create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/build.sbt create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/build.properties create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/plugins.sbt create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/test create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/test create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup/build.sbt create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup/project/build.properties create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup/project/plugins.sbt create mode 100644 modules/resolver/src/sbt-test/sbtghpackages/startup/test create mode 100644 src/sbt-test/sbtghpackages/property-token/build.sbt create mode 100644 src/sbt-test/sbtghpackages/property-token/project/build.properties create mode 100644 src/sbt-test/sbtghpackages/property-token/project/plugins.sbt create mode 100644 src/sbt-test/sbtghpackages/property-token/test diff --git a/README.md b/README.md index 2bbc360..a701770 100644 --- a/README.md +++ b/README.md @@ -12,23 +12,22 @@ addSbtPlugin("com.codecommit" % "sbt-github-packages" % "") Published for sbt 1.x. No dependencies. -In order to *publish* artifacts via this plugin, you will need to override the `githubOwner` and `githubRepository` setting keys to the relevant values for your project. For example: +In order to *publish* artifacts via this plugin, you will need to override the `githubPublishToRepository` setting key to the relevant values for your project. For example: ```sbt -githubOwner := "djspiewak" -githubRepository := "sbt-github-packages" +githubPublishToRepository := GitHubRepository("djspiewak", "sbt-github-packages", TokenSource.Environment("GH_TOKEN")) ``` In the event that you do *not* override these values, you will see a warning like the following: ``` -[warn] undefined keys `githubOwner` and `githubRepository` +[warn] undefined keys `githubPublishToRepository` [warn] retaining pre-existing publication settings ``` The reason this functionality is disabled by default is you may wish to utilize the `Resolver` syntax (described below) *without* overriding your default publication mechanism. In general, I wouldn't necessarily recommend this, since it means that your publication will not be self-contained within a single artifact realm, but that's a relatively common problem anyway these days so it's probably not a big deal. -As a note on publication, *only* `publishMavenStyle := true` (the default) is supported. If you explicitly override this setting to `false`, the sbt-github-packages plugin will produce an error and refuse to load (unless `githubOwner` and/or `githubRepository` are undefined). The reason for this is to remove a bit of a foot-gun: GitHub Packages will silently allow you to publish Ivy-style packages, and will even show it within the UI, but will not allow you to *resolve* them. +As a note on publication, *only* `publishMavenStyle := true` (the default) is supported. If you explicitly override this setting to `false`, the sbt-github-packages plugin will produce an error and refuse to load (unless `githubPublishToRepository` is undefined). The reason for this is to remove a bit of a foot-gun: GitHub Packages will silently allow you to publish Ivy-style packages, and will even show it within the UI, but will not allow you to *resolve* them. Once everything is configured, run `sbt publish` to publish the package. @@ -54,6 +53,7 @@ sealed trait TokenSource extends Product with Serializable { object TokenSource { final case class Environment(variable: String) extends TokenSource + final case class Property(variable: String) extends TokenSource final case class GitConfig(key: String) extends TokenSource final case class Or(primary: TokenSource, secondary: TokenSource) extends TokenSource } @@ -80,6 +80,18 @@ This assumes you have your token stored there like this: token = TOKEN_DATA ``` +To use a token from the process properties it should be specified when running sbt: +```bash +$ sbt -DGITHUB_TOKEN=abcdef12345cafebab +``` + +or create `.sbtopts` file in the project directory with the following content: +``` +-DGITHUB_TOKEN=abcdef12345cafeba +``` + +The option above is suitable for importing the project into IntelliJ IDEA. + The `||` combinator allows you to configure multiple token sources which will be tried in order on first-read of the setting. Note that your CI server will need to set the `GITHUB_TOKEN` environment variable as well (if using the `Environment` token source), as well as any collaborators on your project. The environment-specific nature of these login credentials are a major part of why they are *not* just strings sitting in the `build.sbt` file. As an example, if you're using Travis, you can do something like the following: @@ -134,9 +146,20 @@ It will NOT allow for read access to *private* packages within the same organiza The following setting keys are defined: -- `githubOwner : String` Defines the organization or user name that owns the package registry to which this project will be published -- `githubRepository : String` The repository which hosts this project under the organization/user defined in the other setting -- `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. +- `githubOwner : String` **deprecated** Defines the organization or user name that owns the package registry to which this project will be published +- `githubRepository : String` **deprecated** The repository which hosts this project under the organization/user defined in the other setting +- `githubTokenSource : TokenSource` **deprecated** (*defaults to `Environment("GITHUB_TOKEN")`*) Where the plugin should go to read the GitHub API token to use in authentication. `TokenSource` has three possible values: `Environment(variable: String)`, `Property(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. +- `githubRepositories: Seq[GitHubRepository]` Defines GitHub repositories that should be used for the dependencies lookup. A different token source can be used per repository. + ```scala + githubRepositories ++= Seq( + GitHubRepositry("owner1", "public-repo", TokenSource.Property("PUBLIC_TOKEN")), + GitHubRepositry("owner1", "private-repo", TokenSource.ENVIRONMENT("PRIVATE_TOKEN")) + ) + ``` +- `githubPublishToRepository: GitHubRepository` Defines a GitHub repository the package should be published to. + ```scala + githubPublishToRepository := GitHubRepository("owner2", "private-repo", TokenSource.Property("PRIVATE_TOKEN")) + ``` - `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`. - `githubPublishTo : Option[Resolver]` The default `publishTo` target for GitHub Packages. This setting is useful for switching `publishTo` target to [sbt-sonatype](https://github.com/xerial/sbt-sonatype) or GitHub Packages: @@ -145,5 +168,5 @@ The following setting keys are defined: // otherwise publish to GitHub Packages: val RELEASE_TO_SONATYPE = sys.env.getOrElse("RELEASE_SONATYPE", "false").toBoolean publishTo := if(RELEASE_SONATYPE) sonatypePublishTo.value else githubPublishTo.value - + ``` `homepage` and `scmInfo` will be automatically set for you if `githubOwner` and `githubRepository` are themselves set. diff --git a/build.sbt b/build.sbt index 1364f50..a2b1db5 100644 --- a/build.sbt +++ b/build.sbt @@ -14,7 +14,36 @@ * limitations under the License. */ -name := "sbt-github-packages" +lazy val `sbt-github-packages` = project + .in(file(".")) + .enablePlugins(SbtPlugin) + .settings( + name := "sbt-github-packages" + ) + .dependsOn(common, `gh-publisher`, `gh-resolver`) + .aggregate(common, `gh-publisher`, `gh-resolver`) + +lazy val `gh-publisher` = project + .in(file("modules/publisher")) + .enablePlugins(SbtPlugin) + .settings( + name := "sbt-github-packages-publisher" + ) + .dependsOn(common) + +lazy val `gh-resolver` = project + .in(file("modules/resolver")) + .enablePlugins(SbtPlugin) + .settings( + name := "sbt-github-packages-resolver" + ) + .dependsOn(common) + +lazy val common = project + .in(file("modules/common")) + .settings( + name := "sbt-github-packages-common" + ) ThisBuild / baseVersion := "0.5" @@ -23,9 +52,7 @@ ThisBuild / publishGithubUser := "djspiewak" ThisBuild / publishFullName := "Daniel Spiewak" ThisBuild / sbtPlugin := true -ThisBuild / sbtVersion := "1.3.3" - -enablePlugins(SbtPlugin) +ThisBuild / sbtVersion := "1.5.6" homepage := Some(url("https://github.com/djspiewak/sbt-github-packages")) @@ -39,5 +66,9 @@ developers := List( publishMavenStyle := true -scriptedLaunchOpts ++= Seq("-Dplugin.version=" + version.value) -scriptedBufferLog := true +ThisBuild / scriptedLaunchOpts ++= Seq( + "-Dplugin.version=" + version.value, + "-DSTARTUP_PROPERTY_TOKEN=ghp_123321" +) + +ThisBuild / scriptedBufferLog := true diff --git a/modules/common/src/main/scala/sbtghpackages/GitHubRepository.scala b/modules/common/src/main/scala/sbtghpackages/GitHubRepository.scala new file mode 100644 index 0000000..1279554 --- /dev/null +++ b/modules/common/src/main/scala/sbtghpackages/GitHubRepository.scala @@ -0,0 +1,38 @@ +/* + * Copyright 2019 Daniel Spiewak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sbtghpackages + +final class GitHubRepository( + val owner: String, + val repository: String, + val tokenSource: TokenSource +) { + def realm: String = s"GitHub Package Registry ($owner${if (repository != "_") s"/$repository" else ""})" + + def mavenUrl: String = s"https://maven.pkg.github.com/$owner/$repository" + + def repoUrl: String = s"https://github.com/$owner/$repository" + + def scm: String = s"scm:git@github.com:$owner/$repository.git" +} + +object GitHubRepository { + + def apply(owner: String, repository: String, source: TokenSource): GitHubRepository = + new GitHubRepository(owner, repository, source) + +} \ No newline at end of file diff --git a/src/main/scala/sbtghpackages/TokenSource.scala b/modules/common/src/main/scala/sbtghpackages/TokenSource.scala similarity index 94% rename from src/main/scala/sbtghpackages/TokenSource.scala rename to modules/common/src/main/scala/sbtghpackages/TokenSource.scala index 85ad3ae..78566dc 100644 --- a/src/main/scala/sbtghpackages/TokenSource.scala +++ b/modules/common/src/main/scala/sbtghpackages/TokenSource.scala @@ -23,6 +23,7 @@ sealed trait TokenSource extends Product with Serializable { object TokenSource { final case class Environment(variable: String) extends TokenSource + final case class Property(key: String) extends TokenSource final case class GitConfig(key: String) extends TokenSource final case class Or(primary: TokenSource, secondary: TokenSource) extends TokenSource } diff --git a/modules/common/src/main/scala/sbtghpackages/Utils.scala b/modules/common/src/main/scala/sbtghpackages/Utils.scala new file mode 100644 index 0000000..e186ea1 --- /dev/null +++ b/modules/common/src/main/scala/sbtghpackages/Utils.scala @@ -0,0 +1,73 @@ +/* + * Copyright 2019 Daniel Spiewak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sbtghpackages + +import sbt.{Credentials, Logger} + +import scala.sys.process._ +import scala.util.Try + +private[sbtghpackages] object Utils { + + def reportUnresolvedToken(log: Logger, repo: GitHubRepository): Unit = + log.error( + s"""|Cannot resolve token for ${repo.realm} + |Make sure at least one token source is configured properly: + ${helpMessages(repo.tokenSource).map(message => s"| * $message").mkString("\n")} + |""".stripMargin + ) + + def inferredGitHubCredentials(repo: GitHubRepository): Option[Credentials] = + for { + token <- resolveTokenSource(repo.tokenSource) + } yield Credentials(repo.realm, "maven.pkg.github.com", "_", token) // user is ignored by GitHub, so just use "_" + + def resolveTokenSource(tokenSource: TokenSource): Option[String] = + tokenSource match { + case TokenSource.Or(primary, secondary) => + resolveTokenSource(primary).orElse(resolveTokenSource(secondary)) + + case TokenSource.Environment(variable) => + sys.env.get(variable) + + case TokenSource.Property(key) => + sys.props.get(key) + + case TokenSource.GitConfig(key) => + Try(s"git config $key".!!).map(_.trim).toOption + } + + def helpMessages(tokenSource: TokenSource): List[String] = { + def loop(input: TokenSource, output: List[String]): List[String] = + input match { + case TokenSource.Or(primary, secondary) => + loop(primary, Nil) ::: loop(secondary, Nil) ::: output + + case TokenSource.Environment(variable) => + s"Use `$variable= sbt` or `export $variable=; sbt`." :: output + + case TokenSource.Property(key) => + s"Use `sbt -D$key=` or update `.sbtopts` file." :: output + + case TokenSource.GitConfig(key) => + s"Use `git config $key `." :: output + } + + loop(tokenSource, Nil) + } + +} diff --git a/modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherKeys.scala b/modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherKeys.scala new file mode 100644 index 0000000..ad22cbc --- /dev/null +++ b/modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherKeys.scala @@ -0,0 +1,27 @@ +/* + * Copyright 2019 Daniel Spiewak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sbtghpackages + +import sbt._ + +trait GitHubPackagesPublisherKeys { + val githubPublishToRepository = settingKey[GitHubRepository]("The GitHub repository the package should be published to") + val githubSuppressPublicationWarning = settingKey[Boolean]("Whether or not to suppress the publication warning (default: false, meaning the warning will be printed)") + val githubPublishTo = taskKey[Option[Resolver]]("publishTo setting for deploying artifacts to GitHub packages") +} + +object GitHubPackagesPublisherKeys extends GitHubPackagesPublisherKeys diff --git a/modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherPlugin.scala b/modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherPlugin.scala new file mode 100644 index 0000000..1108382 --- /dev/null +++ b/modules/publisher/src/main/scala/sbtghpackages/GitHubPackagesPublisherPlugin.scala @@ -0,0 +1,112 @@ +/* + * Copyright 2019 Daniel Spiewak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sbtghpackages + +import sbt._, Keys._ + +object GitHubPackagesPublisherPlugin extends AutoPlugin { + @volatile + private[this] var alreadyWarned = false + + override def requires = plugins.JvmPlugin + override def trigger = allRequirements + + object autoImport extends GitHubPackagesPublisherKeys + + import autoImport._ + + @deprecated("Remove once `githubOwner` and `githubRepository` keys are eliminated", "0.6") + private[sbtghpackages] lazy val githubPublishToRepositoryOpt = + settingKey[Option[GitHubRepository]]("Internal setting for bin-compat. Do not override manually") + + val packagePublishSettings = Seq( + githubPublishToRepositoryOpt := githubPublishToRepository.?.value, + + credentials ++= githubPublishToRepositoryOpt.value.flatMap(repo => Utils.inferredGitHubCredentials(repo)), + + githubPublishTo := { + val ms = publishMavenStyle.value + val back = for { + repo <- githubPublishToRepositoryOpt.value + } yield repo.realm at repo.mavenUrl + + back.foreach { _ => + if (!ms) { + sys.error("GitHub Packages does not support Ivy-style publication") + } + } + + back + }, + + publishTo := { + val suppress = githubSuppressPublicationWarning.value + val log = streams.value.log + + githubPublishTo.value orElse { + GitHubPackagesPublisherPlugin synchronized { + if (!alreadyWarned && !suppress) { + log.warn("undefined key `githubPublishToRepository`") + log.warn("retaining pre-existing publication settings") + alreadyWarned = true + } + } + + publishTo.value + } + }, + + publish := { + val log = streams.value.log + val repo = githubPublishToRepositoryOpt.value + + repo.foreach { r => + if (Utils.inferredGitHubCredentials(r).isEmpty) { + Utils.reportUnresolvedToken(log, r) + sys.error(s"Unable to locate a valid GitHub token for ${r.realm} from ${r.tokenSource}") + } + } + + update.value + }, + + scmInfo := { + val back = for { + repo <- githubPublishToRepositoryOpt.value + } yield ScmInfo(url(repo.repoUrl), repo.scm) + + back.orElse(scmInfo.value) + }, + + homepage := { + val back = for { + repo <- githubPublishToRepositoryOpt.value + } yield url(repo.repoUrl) + + back.orElse(homepage.value) + }, + + pomIncludeRepository := (_ => false), + + publishMavenStyle := true + ) + + override def projectSettings = packagePublishSettings + + override def buildSettings = Seq(githubSuppressPublicationWarning := false) +} + diff --git a/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/build.sbt b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/build.sbt new file mode 100644 index 0000000..254b115 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/build.sbt @@ -0,0 +1,5 @@ +import sbtghpackages.{GitHubRepository, TokenSource} + +name := "publish-missing-token-test" + +githubPublishToRepository := GitHubRepository("owner", "repo", TokenSource.Property("UNKNOWN_PROPERTY")) diff --git a/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/build.properties b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/plugins.sbt b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/plugins.sbt new file mode 100644 index 0000000..7e71aad --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages-publisher" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/test b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/test new file mode 100644 index 0000000..22233e4 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/publish-missing-token/test @@ -0,0 +1,3 @@ +> show publishTo +> update +-> publish diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt new file mode 100644 index 0000000..d171722 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt @@ -0,0 +1,2 @@ +name := "startup-empty-settings-test" + diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt new file mode 100644 index 0000000..7e71aad --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages-publisher" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/test b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/test new file mode 100644 index 0000000..d9f791c --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup-empty-settings/test @@ -0,0 +1,3 @@ +> show publishTo +> update +> publish diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup/build.sbt b/modules/publisher/src/sbt-test/sbtghpackages/startup/build.sbt new file mode 100644 index 0000000..4184011 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup/build.sbt @@ -0,0 +1,5 @@ +import sbtghpackages.{GitHubRepository, TokenSource} + +name := "startup-test" + +githubPublishToRepository := GitHubRepository("owner", "repo", TokenSource.Property("STARTUP_PROPERTY_TOKEN")) diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup/project/build.properties b/modules/publisher/src/sbt-test/sbtghpackages/startup/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup/project/plugins.sbt b/modules/publisher/src/sbt-test/sbtghpackages/startup/project/plugins.sbt new file mode 100644 index 0000000..7e71aad --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages-publisher" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/modules/publisher/src/sbt-test/sbtghpackages/startup/test b/modules/publisher/src/sbt-test/sbtghpackages/startup/test new file mode 100644 index 0000000..d9f791c --- /dev/null +++ b/modules/publisher/src/sbt-test/sbtghpackages/startup/test @@ -0,0 +1,3 @@ +> show publishTo +> update +> publish diff --git a/modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverKeys.scala b/modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverKeys.scala new file mode 100644 index 0000000..2f57c70 --- /dev/null +++ b/modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverKeys.scala @@ -0,0 +1,25 @@ +/* + * Copyright 2019 Daniel Spiewak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sbtghpackages + +import sbt._ + +trait GitHubPackagesResolverKeys { + val githubRepositories = settingKey[Seq[GitHubRepository]]("The GitHub repositories to resolve packages at") +} + +object GitHubPackagesResolverKeys extends GitHubPackagesResolverKeys \ No newline at end of file diff --git a/modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverPlugin.scala b/modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverPlugin.scala new file mode 100644 index 0000000..8232808 --- /dev/null +++ b/modules/resolver/src/main/scala/sbtghpackages/GitHubPackagesResolverPlugin.scala @@ -0,0 +1,59 @@ +/* + * Copyright 2019 Daniel Spiewak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sbtghpackages + +import sbt.Keys._ +import sbt._ + +object GitHubPackagesResolverPlugin extends AutoPlugin { + + override def requires = plugins.JvmPlugin + override def trigger = allRequirements + + object autoImport extends GitHubPackagesResolverKeys + + import autoImport._ + + val packageResolverSettings = Seq( + credentials ++= { + val log = streams.value.log + val repos = githubRepositories.value + + val (unresolved, credentials) = + repos.foldLeft((List.empty[GitHubRepository], List.empty[Credentials])) { case ((unresolved, credentials), repo) => + Utils.inferredGitHubCredentials(repo) match { + case Some(creds) => (unresolved, credentials :+ creds) + case None => (unresolved :+ repo, credentials) + } + } + + if (unresolved.nonEmpty) { + unresolved.foreach(repo => Utils.reportUnresolvedToken(log, repo)) + + sys.error(s"Unable to locate valid GitHub tokens for ${unresolved.map(_.realm).mkString(", ")}") + } + + credentials + }, + githubRepositories := Nil, + resolvers ++= githubRepositories.?.value.toSeq.flatten.map(r => r.realm at r.mavenUrl) + ) + + override def projectSettings = packageResolverSettings + +} + diff --git a/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/build.sbt b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/build.sbt new file mode 100644 index 0000000..48c14af --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/build.sbt @@ -0,0 +1,5 @@ +import sbtghpackages.{GitHubRepository, TokenSource} + +name := "resolve-missing-token-test" + +githubRepositories += GitHubRepository("owner", "repo", TokenSource.Property("UNKNOWN_PROPERTY")) diff --git a/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/build.properties b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/plugins.sbt b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/plugins.sbt new file mode 100644 index 0000000..afa234c --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages-resolver" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/test b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/test new file mode 100644 index 0000000..3c77d75 --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/resolve-missing-token/test @@ -0,0 +1,2 @@ +> show publishTo +-> update diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt new file mode 100644 index 0000000..d171722 --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/build.sbt @@ -0,0 +1,2 @@ +name := "startup-empty-settings-test" + diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt new file mode 100644 index 0000000..afa234c --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages-resolver" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/test b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/test new file mode 100644 index 0000000..103bd8d --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup-empty-settings/test @@ -0,0 +1 @@ +> update diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup/build.sbt b/modules/resolver/src/sbt-test/sbtghpackages/startup/build.sbt new file mode 100644 index 0000000..d629191 --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup/build.sbt @@ -0,0 +1,5 @@ +import sbtghpackages.{GitHubRepository, TokenSource} + +name := "startup-test" + +githubRepositories += GitHubRepository("owner", "repo", TokenSource.Property("STARTUP_PROPERTY_TOKEN")) diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup/project/build.properties b/modules/resolver/src/sbt-test/sbtghpackages/startup/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup/project/plugins.sbt b/modules/resolver/src/sbt-test/sbtghpackages/startup/project/plugins.sbt new file mode 100644 index 0000000..afa234c --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages-resolver" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/modules/resolver/src/sbt-test/sbtghpackages/startup/test b/modules/resolver/src/sbt-test/sbtghpackages/startup/test new file mode 100644 index 0000000..103bd8d --- /dev/null +++ b/modules/resolver/src/sbt-test/sbtghpackages/startup/test @@ -0,0 +1 @@ +> update diff --git a/project/build.properties b/project/build.properties index 6adcdc7..bb3a9b7 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.3 +sbt.version=1.5.6 diff --git a/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala b/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala index 41d91fb..c76c852 100644 --- a/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala +++ b/src/main/scala/sbtghpackages/GitHubPackagesKeys.scala @@ -19,14 +19,14 @@ package sbtghpackages import sbt._ trait GitHubPackagesKeys { + @deprecated("Use `githubPublishToRepository` or `githubRepositories` instead", "0.6") val githubOwner = settingKey[String]("The github user or organization name") + + @deprecated("Use `githubPublishToRepository` or `githubRepositories` instead", "0.6") val githubRepository = settingKey[String]("The github repository hosting this package") + @deprecated("Use `githubPublishToRepository` or `githubRepositories` instead", "0.6") 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)") - - val githubPublishTo = taskKey[Option[Resolver]]("publishTo setting for deploying artifacts to GitHub packages") } object GitHubPackagesKeys extends GitHubPackagesKeys diff --git a/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala b/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala index ad2fdc7..bf3f48c 100644 --- a/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala +++ b/src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala @@ -16,22 +16,20 @@ package sbtghpackages -import sbt._, Keys._ - -import scala.sys.process._ -import scala.util.Try +import sbt._ object GitHubPackagesPlugin extends AutoPlugin { - @volatile - private[this] var alreadyWarned = false - override def requires = plugins.JvmPlugin + override def requires = GitHubPackagesResolverPlugin && GitHubPackagesPublisherPlugin override def trigger = allRequirements object autoImport extends GitHubPackagesKeys { type TokenSource = sbtghpackages.TokenSource val TokenSource = sbtghpackages.TokenSource + type GitHubRepository = sbtghpackages.GitHubRepository + val GitHubRepository = sbtghpackages.GitHubRepository + implicit class GHPackagesResolverSyntax(val resolver: Resolver.type) extends AnyVal { def githubPackages(owner: String, repo: String = "_"): MavenRepository = realm(owner, repo) at s"https://maven.pkg.github.com/$owner/$repo" @@ -39,103 +37,27 @@ object GitHubPackagesPlugin extends AutoPlugin { } import autoImport._ - - val authenticationSettings = Seq( - githubTokenSource := TokenSource.Environment("GITHUB_TOKEN"), - - credentials += { - val src = githubTokenSource.value - inferredGitHubCredentials("_", src) match { // user is ignored by GitHub, so just use "_" - case Some(creds) => - creds - - case None => - sys.error(s"unable to locate a valid GitHub token from $src") - } - }) + import GitHubPackagesPublisherKeys._ + import GitHubPackagesResolverKeys._ + import GitHubPackagesPublisherPlugin.githubPublishToRepositoryOpt val packagePublishSettings = Seq( - githubPublishTo := { - val log = streams.value.log - val ms = publishMavenStyle.value - val back = for { - owner <- githubOwner.?.value - repo <- githubRepository.?.value - } yield "GitHub Package Registry" at s"https://maven.pkg.github.com/$owner/$repo" - - back foreach { _ => - if (!ms) { - sys.error("GitHub Packages does not support Ivy-style publication") - } - } - - back - }, - - publishTo := { - val suppress = githubSuppressPublicationWarning.value - val log = streams.value.log - - githubPublishTo.value orElse { - GitHubPackagesPlugin synchronized { - if (!alreadyWarned && !suppress) { - log.warn("undefined keys `githubOwner` and `githubRepository`") - log.warn("retaining pre-existing publication settings") - alreadyWarned = true - } - } - - publishTo.value - } - }, - - resolvers ++= githubOwner.?.value.toSeq.map(Resolver.githubPackages(_)), - - scmInfo := { - val back = for { + githubTokenSource := TokenSource.Environment("GITHUB_TOKEN") || TokenSource.Property("GITHUB_TOKEN"), + githubPublishToRepositoryOpt := { + val source = githubTokenSource.value + for { owner <- githubOwner.?.value repo <- githubRepository.?.value - } yield ScmInfo(url(s"https://github.com/$owner/$repo"), s"scm:git@github.com:$owner/$repo.git") - - back.orElse(scmInfo.value) + } yield GitHubRepository(owner, repo, source) }, - - homepage := { - val back = for { + githubRepositories ++= { + val source = githubTokenSource.value + for { owner <- githubOwner.?.value repo <- githubRepository.?.value - } yield url(s"https://github.com/$owner/$repo") - - back.orElse(homepage.value) - }, - - pomIncludeRepository := (_ => false), - publishMavenStyle := true) ++ - authenticationSettings - - def resolveTokenSource(tokenSource: TokenSource): Option[String] = { - tokenSource match { - case TokenSource.Or(primary, secondary) => - resolveTokenSource(primary).orElse( - resolveTokenSource(secondary)) - - case TokenSource.Environment(variable) => - sys.env.get(variable) - - case TokenSource.GitConfig(key) => - Try(s"git config $key".!!).map(_.trim).toOption + } yield GitHubRepository(owner, repo, source) } - } - - def inferredGitHubCredentials(user: String, tokenSource: TokenSource): Option[Credentials] = { - resolveTokenSource(tokenSource) map { token => - Credentials( - "GitHub Package Registry", - "maven.pkg.github.com", - user, - token) - } - } + ) private def realm(owner: String, repo: String) = s"GitHub Package Registry (${owner}${if (repo != "_") s"/$repo" else ""})" diff --git a/src/sbt-test/sbtghpackages/property-token/build.sbt b/src/sbt-test/sbtghpackages/property-token/build.sbt new file mode 100644 index 0000000..57688cc --- /dev/null +++ b/src/sbt-test/sbtghpackages/property-token/build.sbt @@ -0,0 +1,5 @@ +name := "property-token-test" + +githubOwner := "djspiewak" +githubRepository := "sbt-github-packages" +githubTokenSource := TokenSource.Property("STARTUP_PROPERTY_TOKEN") diff --git a/src/sbt-test/sbtghpackages/property-token/project/build.properties b/src/sbt-test/sbtghpackages/property-token/project/build.properties new file mode 100644 index 0000000..bb3a9b7 --- /dev/null +++ b/src/sbt-test/sbtghpackages/property-token/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.6 diff --git a/src/sbt-test/sbtghpackages/property-token/project/plugins.sbt b/src/sbt-test/sbtghpackages/property-token/project/plugins.sbt new file mode 100644 index 0000000..28172ea --- /dev/null +++ b/src/sbt-test/sbtghpackages/property-token/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-packages" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/src/sbt-test/sbtghpackages/property-token/test b/src/sbt-test/sbtghpackages/property-token/test new file mode 100644 index 0000000..6adea53 --- /dev/null +++ b/src/sbt-test/sbtghpackages/property-token/test @@ -0,0 +1,2 @@ +> show publishTo +> update \ No newline at end of file diff --git a/src/sbt-test/sbtghpackages/publish/project/build.properties b/src/sbt-test/sbtghpackages/publish/project/build.properties index 6adcdc7..bb3a9b7 100644 --- a/src/sbt-test/sbtghpackages/publish/project/build.properties +++ b/src/sbt-test/sbtghpackages/publish/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.3 +sbt.version=1.5.6 diff --git a/src/sbt-test/sbtghpackages/startup/project/build.properties b/src/sbt-test/sbtghpackages/startup/project/build.properties index 797e7cc..bb3a9b7 100644 --- a/src/sbt-test/sbtghpackages/startup/project/build.properties +++ b/src/sbt-test/sbtghpackages/startup/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.10 +sbt.version=1.5.6 From bbf0f1af96c13b3d8eb3aca9f3434d0263782d27 Mon Sep 17 00:00:00 2001 From: Maksim Ochenashko Date: Wed, 15 Dec 2021 12:07:30 +0200 Subject: [PATCH 2/3] Update build.sbt: make `homepage` and `scmInfo` build-wide --- README.md | 2 +- build.sbt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a701770..4dd5fc4 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ The following setting keys are defined: ```scala githubRepositories ++= Seq( GitHubRepositry("owner1", "public-repo", TokenSource.Property("PUBLIC_TOKEN")), - GitHubRepositry("owner1", "private-repo", TokenSource.ENVIRONMENT("PRIVATE_TOKEN")) + GitHubRepositry("owner1", "private-repo", TokenSource.Property("PRIVATE_TOKEN")) ) ``` - `githubPublishToRepository: GitHubRepository` Defines a GitHub repository the package should be published to. diff --git a/build.sbt b/build.sbt index a2b1db5..b83b753 100644 --- a/build.sbt +++ b/build.sbt @@ -54,9 +54,9 @@ ThisBuild / publishFullName := "Daniel Spiewak" ThisBuild / sbtPlugin := true ThisBuild / sbtVersion := "1.5.6" -homepage := Some(url("https://github.com/djspiewak/sbt-github-packages")) +ThisBuild / homepage := Some(url("https://github.com/djspiewak/sbt-github-packages")) -scmInfo := Some( +ThisBuild / scmInfo := Some( ScmInfo( url("https://github.com/djspiewak/sbt-github-packages"), "scm:git@github.com:djspiewak/sbt-github-packages.git")) From b6c0eceaf0be1eb3fc84d505fed4df2961d3bf92 Mon Sep 17 00:00:00 2001 From: Maksim Ochenashko Date: Wed, 15 Dec 2021 12:10:20 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4dd5fc4..a1f67a9 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ The following setting keys are defined: ```scala githubPublishToRepository := GitHubRepository("owner2", "private-repo", TokenSource.Property("PRIVATE_TOKEN")) ``` -- `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`. +- `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 `githubPublishToRepository`. - `githubPublishTo : Option[Resolver]` The default `publishTo` target for GitHub Packages. This setting is useful for switching `publishTo` target to [sbt-sonatype](https://github.com/xerial/sbt-sonatype) or GitHub Packages: ```scala @@ -169,4 +169,4 @@ The following setting keys are defined: val RELEASE_TO_SONATYPE = sys.env.getOrElse("RELEASE_SONATYPE", "false").toBoolean publishTo := if(RELEASE_SONATYPE) sonatypePublishTo.value else githubPublishTo.value ``` -`homepage` and `scmInfo` will be automatically set for you if `githubOwner` and `githubRepository` are themselves set. +`homepage` and `scmInfo` will be automatically set for you if `githubPublishToRepository` is set.