Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sbt-github-packages with call to maven #9

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,24 @@ lazy val assemblySettings = List(
assembly / mainClass := Some("org.broadinstitute.gpp.poolq3.PoolQ")
)

lazy val publishSettings = List(
// Publish to GitHub Packages:
githubOwner := "broadinstitute",
githubRepository := artifactId,
githubTokenSource := TokenSource.Environment("GITHUB_TOKEN") || TokenSource.GitConfig("github.token")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you not just set it to some empty default otherwise? Coming to think of it it's a bit weird that env variable needs to be set in order to build the project.

This might also be an issue within sbt-github-packages. This should be checked lazily when publishing.

Setting "GITHUB_TOKEN" in Scala Steward might be a bit of a hack I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's definitely an issue within sbt-github-packages, which absolutely should be loading this value lazily but isn't. It's been noted in issues and even PRs in the repository, but there hasn't been any action there. I assume that TokenSource doesn't define a Literal instance in the ADT to prevent people from committing sensitive data in their builds.

That's one of the reasons why this PR is appealing to me - GitHub doesn't really support SBT publishing to the GitHub Package Repository anyway, but it does support using Maven, so publishing this way, while less "scala-like", is more in line with GitHub's expectations.

I was working on this a bit during my spare time on vacation, and at the time, I didn't see an easy way to set a default but I might have been looking in the wrong places. I wonder if SBT has a way to do a conditional assignment somehow, will take a quick look.

)
lazy val publishToGithubPackages = taskKey[Unit]("Publish jar to Github Packages")

publishToGithubPackages := {
if (!sys.env.keySet.contains("GITHUB_TOKEN")) throw new Exception("You must set environmental variable GITHUB_TOKEN")
val mvn =
s"""mvn deploy:deploy-file
|-Durl=https://maven.pkg.github.com/poolq
|-DrepositoryId=github
|-Dfile=${(Compile / packageBin).value}
|-DpomFile=${(Compile / makePom).value}
|-Dsources=${(Compile / packageSrc).value}
|-Djavadoc=${(Compile / packageDoc).value}
|--settings=settings.xml""".stripLineEnd

println(s"Executing shell command $mvn")
import scala.sys.process._
if (mvn.! != 0) throw new Exception("publish failed")
}

lazy val poolq = project
.in(file("."))
Expand All @@ -144,4 +156,7 @@ lazy val poolq = project
)
.settings(headerSettings: _*)
.settings(assemblySettings: _*)
.settings(publishSettings: _*)
.settings(
// override the normal publish tasks with the maven task
publish := publishToGithubPackages.value
)
1 change: 0 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
addSbtPlugin("ch.epfl.scala" % "sbt-missinglink" % "0.3.3")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4")
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16")
Expand Down
29 changes: 29 additions & 0 deletions settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/poolq</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>broadinstitute</username>
<password>${GITHUB_TOKEN}</password>
</server>
</servers>
</settings>