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

site plugin improvements #124

Merged
merged 7 commits into from
Feb 10, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: mdocs/target/docs/site
publish_branch: gh-pages
keep_files: true
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ lazy val site = project
.settings(
name := "sbt-typelevel-site"
)
.dependsOn(kernel, githubActions, noPublish)
.dependsOn(kernel, github, githubActions, noPublish)

lazy val docs = project
.in(file("mdocs"))
Expand Down
32 changes: 20 additions & 12 deletions github/src/main/scala/org/typelevel/sbt/TypelevelGitHubPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,30 @@ object TypelevelGitHubPlugin extends AutoPlugin {
def tlGitHubDev(user: String, fullName: String): Developer = {
Developer(user, fullName, s"@$user", url(s"https://github.com/$user"))
}

lazy val tlGitHubRepo = settingKey[Option[String]]("The name of this repository on GitHub")
}

import autoImport._

override def buildSettings = Seq(
scmInfo := getScmInfo(),
tlGitHubRepo := gitHubUserRepo.value.map(_._2),
scmInfo := gitHubUserRepo.value.map {
case (user, repo) =>
gitHubScmInfo(user, repo)
},
homepage := homepage.value.orElse(scmInfo.value.map(_.browseUrl))
)

private def getScmInfo(): Option[ScmInfo] = {
import scala.sys.process._
private def gitHubScmInfo(user: String, repo: String) =
ScmInfo(
url(s"https://github.com/$user/$repo"),
s"scm:git:https://github.com/$user/$repo.git",
s"scm:git:git@github.com:$user/$repo.git"
)

def gitHubScmInfo(user: String, repo: String) =
ScmInfo(
url(s"https://github.com/$user/$repo"),
s"scm:git:https://github.com/$user/$repo.git",
s"scm:git:git@github.com:$user/$repo.git"
)
private[sbt] def gitHubUserRepo = Def.setting {
import scala.sys.process._

val identifier = """([^\/]+?)"""
val GitHubHttps = s"https://github.com/$identifier/$identifier(?:\\.git)?".r
Expand All @@ -57,9 +65,9 @@ object TypelevelGitHubPlugin extends AutoPlugin {
Try {
val remote = List("git", "ls-remote", "--get-url", "origin").!!.trim()
remote match {
case GitHubHttps(user, repo) => Some(gitHubScmInfo(user, repo))
case GitHubGit(user, repo) => Some(gitHubScmInfo(user, repo))
case GitHubSsh(user, repo) => Some(gitHubScmInfo(user, repo))
case GitHubHttps(user, repo) => Some((user, repo))
case GitHubGit(user, repo) => Some((user, repo))
case GitHubSsh(user, repo) => Some((user, repo))
case _ => None
}
}.toOption.flatten
Expand Down
19 changes: 15 additions & 4 deletions site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ object TypelevelSitePlugin extends AutoPlugin {
object autoImport {
lazy val tlSiteHeliumConfig = settingKey[Helium]("The Helium configuration")
lazy val tlSiteApiUrl = settingKey[Option[URL]]("URL to the API docs")
lazy val tlSiteKeepFiles =
settingKey[Boolean]("Whether to keep existing files when deploying site (default: true)")
lazy val tlSiteGenerate = settingKey[Seq[WorkflowStep]](
"A sequence of workflow steps which generates the site (default: [Sbt(List(\"tlSite\"))])")
lazy val tlSitePublish = settingKey[Seq[WorkflowStep]](
Expand All @@ -44,12 +46,21 @@ object TypelevelSitePlugin extends AutoPlugin {
}

import autoImport._
import TypelevelGitHubPlugin._

override def requires = MdocPlugin && LaikaPlugin && GenerativePlugin && NoPublishPlugin
override def requires =
MdocPlugin && LaikaPlugin && TypelevelGitHubPlugin && GenerativePlugin && NoPublishPlugin

override def buildSettings = Seq(
tlSitePublishBranch := Some("main"),
tlSiteApiUrl := None
tlSiteApiUrl := None,
tlSiteKeepFiles := true,
homepage := {
gitHubUserRepo.value.map {
case ("typelevel", repo) => url(s"https://typelevel.org/$repo")
case (user, repo) => url(s"https://$user.github.io/$repo")
}
}
)

override def projectSettings = Seq(
Expand All @@ -63,7 +74,7 @@ object TypelevelSitePlugin extends AutoPlugin {
laikaTheme := tlSiteHeliumConfig.value.build,
mdocVariables ++= Map(
"VERSION" -> GitHelper
.previousReleases()
.previousReleases(fromHead = true)
.filterNot(_.isPrerelease)
.headOption
.fold(version.value)(_.toString),
Expand Down Expand Up @@ -128,7 +139,7 @@ object TypelevelSitePlugin extends AutoPlugin {
.toAbsolutePath
.relativize(((Laika / target).value / "site").toPath)
.toString,
"publish_branch" -> "gh-pages"
"keep_files" -> tlSiteKeepFiles.value.toString
),
name = Some("Publish site"),
cond = {
Expand Down