From 692b0de8a11a07fe32bfe09ddc4a3d0104e2be1c Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 29 Jan 2022 20:24:11 +0000 Subject: [PATCH 1/7] Expose github repo as setting --- .../typelevel/sbt/TypelevelGitHubPlugin.scala | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/github/src/main/scala/org/typelevel/sbt/TypelevelGitHubPlugin.scala b/github/src/main/scala/org/typelevel/sbt/TypelevelGitHubPlugin.scala index d8826694..dd9cfe10 100644 --- a/github/src/main/scala/org/typelevel/sbt/TypelevelGitHubPlugin.scala +++ b/github/src/main/scala/org/typelevel/sbt/TypelevelGitHubPlugin.scala @@ -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 @@ -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 From df30774638d1dcdc772a06ee291740f6241f644d Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 29 Jan 2022 20:46:03 +0000 Subject: [PATCH 2/7] Auto-populate homepage --- build.sbt | 2 +- .../org/typelevel/sbt/TypelevelSitePlugin.scala | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 3f29674c..8962effb 100644 --- a/build.sbt +++ b/build.sbt @@ -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")) diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index d57a1b95..3bde9989 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -44,12 +44,20 @@ 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, + 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( From 6ac3a9238e25f426a8714ba82dedec7046f9c8b1 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 29 Jan 2022 20:53:45 +0000 Subject: [PATCH 3/7] Add keepFiles setting for site deploy --- .github/workflows/ci.yml | 1 + .../main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b65a27e..1fdabc6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -191,3 +191,4 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: mdocs/target/docs/site publish_branch: gh-pages + keep_files: true diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index 3bde9989..d203fad2 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -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]]( @@ -52,6 +54,7 @@ object TypelevelSitePlugin extends AutoPlugin { override def buildSettings = Seq( tlSitePublishBranch := Some("main"), tlSiteApiUrl := None, + tlSiteKeepFiles := true, homepage := { gitHubUserRepo.value.map { case ("typelevel", repo) => url(s"https://typelevel.org/$repo") @@ -136,7 +139,8 @@ object TypelevelSitePlugin extends AutoPlugin { .toAbsolutePath .relativize(((Laika / target).value / "site").toPath) .toString, - "publish_branch" -> "gh-pages" + "publish_branch" -> "gh-pages", + "keep_files" -> tlSiteKeepFiles.value.toString ), name = Some("Publish site"), cond = { From 87965fa7d4a99071fbdbacbfced2bf0404630c34 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 29 Jan 2022 21:07:17 +0000 Subject: [PATCH 4/7] Populate mdoc VERSION from tags on branch --- site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index d203fad2..59df770a 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -74,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), From 059730745011cf8d2f68779cb8daf6fdbf9f87cb Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 29 Jan 2022 21:25:40 +0000 Subject: [PATCH 5/7] Remove redundant setting --- .github/workflows/ci.yml | 1 - site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fdabc6a..c66262f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -190,5 +190,4 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: mdocs/target/docs/site - publish_branch: gh-pages keep_files: true diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index 59df770a..0ef096c8 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -139,7 +139,6 @@ 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"), From cd336ad99ffd00d559190c8cdbaa4194b2c3d559 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 1 Feb 2022 00:10:03 +0000 Subject: [PATCH 6/7] Deprecate tlSiteApiUrl for apiURL --- .../main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index 0ef096c8..63539c9d 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -33,6 +33,7 @@ object TypelevelSitePlugin extends AutoPlugin { object autoImport { lazy val tlSiteHeliumConfig = settingKey[Helium]("The Helium configuration") + @deprecated("Use apiURL instead", "0.4.4") 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)") @@ -53,7 +54,7 @@ object TypelevelSitePlugin extends AutoPlugin { override def buildSettings = Seq( tlSitePublishBranch := Some("main"), - tlSiteApiUrl := None, + tlSiteApiUrl := None: @nowarn, tlSiteKeepFiles := true, homepage := { gitHubUserRepo.value.map { @@ -102,7 +103,7 @@ object TypelevelSitePlugin extends AutoPlugin { "https://typelevel.org", Image.external(s"data:image/svg+xml;base64,$getSvgLogo") ), - navLinks = tlSiteApiUrl.value.toList.map { url => + navLinks = apiURL.value.orElse(tlSiteApiUrl.value: @nowarn).toList.map { url => IconLink.external( url.toString, HeliumIcon.api, From 2ede5fe9d62fd15b06a7902dc09f536692b57212 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 1 Feb 2022 00:18:08 +0000 Subject: [PATCH 7/7] Revert "Deprecate tlSiteApiUrl for apiURL" The API URL you want on the site is for the last stable release. This might not match the API URL for the version in ThisBuild. This reverts commit cd336ad99ffd00d559190c8cdbaa4194b2c3d559. --- .../main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index 63539c9d..0ef096c8 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -33,7 +33,6 @@ object TypelevelSitePlugin extends AutoPlugin { object autoImport { lazy val tlSiteHeliumConfig = settingKey[Helium]("The Helium configuration") - @deprecated("Use apiURL instead", "0.4.4") 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)") @@ -54,7 +53,7 @@ object TypelevelSitePlugin extends AutoPlugin { override def buildSettings = Seq( tlSitePublishBranch := Some("main"), - tlSiteApiUrl := None: @nowarn, + tlSiteApiUrl := None, tlSiteKeepFiles := true, homepage := { gitHubUserRepo.value.map { @@ -103,7 +102,7 @@ object TypelevelSitePlugin extends AutoPlugin { "https://typelevel.org", Image.external(s"data:image/svg+xml;base64,$getSvgLogo") ), - navLinks = apiURL.value.orElse(tlSiteApiUrl.value: @nowarn).toList.map { url => + navLinks = tlSiteApiUrl.value.toList.map { url => IconLink.external( url.toString, HeliumIcon.api,