Skip to content

Commit

Permalink
djspiewak#15: Add githubPublishTo setting
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Apr 18, 2020
1 parent d3ed869 commit 9d186c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -134,5 +134,13 @@ The following setting keys are defined:
- `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.
- `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:

```scala
// Switch publishTo target for using Sonatype if RELEASE_SONATYPE env is true,
// 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.
2 changes: 2 additions & 0 deletions src/main/scala/sbtghpackages/GitHubPackagesKeys.scala
Expand Up @@ -25,6 +25,8 @@ trait GitHubPackagesKeys {
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
3 changes: 2 additions & 1 deletion src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala
Expand Up @@ -55,7 +55,8 @@ object GitHubPackagesPlugin extends AutoPlugin {
})

val packagePublishSettings = Seq(
publishTo := {
publishTo := githubPublishTo.value,
githubPublishTo := {
val suppress = githubSuppressPublicationWarning.value
val log = streams.value.log
val ms = publishMavenStyle.value
Expand Down

0 comments on commit 9d186c4

Please sign in to comment.