Skip to content

Commit

Permalink
Credentials should remain optional
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Jul 29, 2021
1 parent 6e490d4 commit 0d28225
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ You may also *optionally* specify a repository as the second argument. **This is

This resolver will give you access to packages published on *any* repository within the organization. If the token provided in the authentication information only has access to public repositories, then packages published on private repositories will report "not found". If the token has access to private repositories as well as public, then all packages will be visible.

You will need to ensure that `githubTokenSource` is set to *your* details (i.e. the authentication information for the individual who ran `sbt`). The `TokenSource` ADT has the following possibilities:
### Authentication

You will need to ensure that `githubTokenSource` is set to *your* details (i.e. the authentication information for the individual who ran `sbt`). If you do
not establish a token source then you will be unable to authenticate, and you will receive the following message when you attempt to publish:

```
[error] Unable to find credentials for [GitHub Package Registry @ maven.pkg.github.com].
```

The `TokenSource` ADT has the following possibilities:

```scala
sealed trait TokenSource extends Product with Serializable {
Expand Down
17 changes: 13 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

name := "sbt-github-packages"

ThisBuild / baseVersion := "0.5"
ThisBuild / baseVersion := "0.6"

ThisBuild / organization := "com.codecommit"
ThisBuild / publishGithubUser := "djspiewak"
Expand All @@ -27,12 +27,21 @@ ThisBuild / sbtVersion := "1.3.3"

enablePlugins(SbtPlugin)

homepage := Some(url("https://github.com/djspiewak/sbt-github-packages"))
githubOwner := "openlawteam"
githubRepository := "sbt-github-packages"
githubTokenSource := TokenSource.GitConfig("github.token") || TokenSource
.Environment("GITHUB_TOKEN")

publishTo := Some(
"GitHub Packages Propeller Scala" at "https://maven.pkg.github.com/openlawteam/sbt-github-packages"
)

homepage := Some(url("https://github.com/openlawteam/sbt-github-packages"))

scmInfo := Some(
ScmInfo(
url("https://github.com/djspiewak/sbt-github-packages"),
"scm:[email protected]:djspiewak/sbt-github-packages.git"))
url("https://github.com/openlawteam/sbt-github-packages"),
"scm:[email protected]:openlawteam/sbt-github-packages.git"))

developers := List(
Developer(id="djspiewak", name="Daniel Spiewak", email="[email protected]", url=url("https://github.com/djspiewak")))
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.9.1")
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.3")
6 changes: 3 additions & 3 deletions src/main/scala/sbtghpackages/GitHubPackagesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ object GitHubPackagesPlugin extends AutoPlugin {
val authenticationSettings = Seq(
githubTokenSource := TokenSource.Environment("GITHUB_TOKEN"),

credentials += {
credentials ++= {
val src = githubTokenSource.value
inferredGitHubCredentials("_", src) match { // user is ignored by GitHub, so just use "_"
case Some(creds) =>
creds
Seq(creds)

case None =>
sys.error(s"unable to locate a valid GitHub token from $src")
Seq.empty
}
})

Expand Down

0 comments on commit 0d28225

Please sign in to comment.