diff --git a/README.md b/README.md index 1972056a..9a12bebf 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,12 @@ # ZIO SBT + _ZIO SBT_ is an sbt plugin for ZIO projects. It provides high-level SBT utilities that simplify the development of ZIO applications. -| Project Stage | CI | Release | Snapshot | Issues | Discord | -|---------------------------------------|-----------------|-----------------------------------------------------------------------|--------------------------------------------------------------------------|------------------------------------------------------------|----------------------------------| -| [![Project stage][Stage]][Stage-Page] | ![CI][Badge-CI] | [![Release Artifacts][Badge-SonatypeReleases]][Link-SonatypeReleases] | [![Snapshot Artifacts][Badge-SonatypeSnapshots]][Link-SonatypeSnapshots] | [![Average time to resolve an issue][badge-iim]][link-iim] | [![badge-discord]][link-discord] | +|Project Stage | CI | Release | Snapshot | Discord | Github | +|--------------|----|---------|----------|---------|--------| +|[![Production%20Ready](https://img.shields.io/badge/Project%20Stage-Production%20Ready-brightgreen.svg)](https://github.com/zio/zio/wiki/Project-Stages) |![CI Badge](https://github.com/zio/zio-sbt/workflows/CI/badge.svg) |[![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-query_2.12.svg)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-query_2.12/) |[![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-query_2.12.svg)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-query_2.12/) |[![Chat on Discord!](https://img.shields.io/discord/629491597070827530?logo=discord)](https://discord.gg/2ccFBr4) |[![ZIO SBT](https://img.shields.io/github/stars/zio/zio-sbt?style=social)](https://github.com/zio/zio-sbt) | ## Installation @@ -17,7 +18,7 @@ _ZIO SBT_ is an sbt plugin for ZIO projects. It provides high-level SBT utilitie Add the following lines to your `plugin.sbt` file: ```scala -addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.1.5") +addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.1.0") ``` Then you can enable it by using the following code in your `build.sbt` file: diff --git a/README.template.md b/README.template.md index 5de363b4..b62b9658 100644 --- a/README.template.md +++ b/README.template.md @@ -1,4 +1,5 @@ # ZIO SBT + {{ main_content }} ## Contributing diff --git a/build.sbt b/build.sbt index 753b8e7a..58649ce8 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,3 @@ -import sbtcrossproject.CrossPlugin.autoImport.crossProject -import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSUseMainModuleInitializer - sbtPlugin := true publishMavenStyle := true @@ -94,7 +91,14 @@ lazy val docs = project publish / skip := true, moduleName := "zio-sbt-docs", scalacOptions -= "-Yno-imports", - scalacOptions -= "-Xfatal-warnings" + scalacOptions -= "-Xfatal-warnings", + badgeInfo := Some( + BadgeInfo( + projectName = "ZIO SBT", + artifact = "zio-sbt-website_2.12", + projectStage = ProjectStage.ProductionReady + ) + ) ) .dependsOn(root) .enablePlugins(ZioEcosystemProjectPlugin, WebsitePlugin) diff --git a/docs/index.md b/docs/index.md index b3d74700..ad6a836e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,10 +5,7 @@ title: "ZIO SBT" _ZIO SBT_ is an sbt plugin for ZIO projects. It provides high-level SBT utilities that simplify the development of ZIO applications. -| Project Stage | CI | Release | Snapshot | Issues | Discord | -|---------------------------------------|-----------------|-----------------------------------------------------------------------|--------------------------------------------------------------------------|------------------------------------------------------------|----------------------------------| -| [![Project stage][Stage]][Stage-Page] | ![CI][Badge-CI] | [![Release Artifacts][Badge-SonatypeReleases]][Link-SonatypeReleases] | [![Snapshot Artifacts][Badge-SonatypeSnapshots]][Link-SonatypeSnapshots] | [![Average time to resolve an issue][badge-iim]][link-iim] | [![badge-discord]][link-discord] | - +@PROJECT_BADGES@ ## Installation diff --git a/zio-sbt-website/src/main/scala/zio/sbt/WebsitePlugin.scala b/zio-sbt-website/src/main/scala/zio/sbt/WebsitePlugin.scala index 6390aad1..7d643160 100644 --- a/zio-sbt-website/src/main/scala/zio/sbt/WebsitePlugin.scala +++ b/zio-sbt-website/src/main/scala/zio/sbt/WebsitePlugin.scala @@ -25,6 +25,14 @@ import mdoc.MdocPlugin.autoImport.* import sbt.Keys.* import sbt.* +import zio.sbt.WebsiteUtils.ProjectStage + +case class BadgeInfo( + projectName: String, + artifact: String, + projectStage: ProjectStage +) + object WebsitePlugin extends sbt.AutoPlugin { object autoImport { @@ -39,6 +47,14 @@ object WebsitePlugin extends sbt.AutoPlugin { val npmToken: SettingKey[String] = settingKey[String]("npm token") val docsDependencies: SettingKey[Seq[ModuleID]] = settingKey[Seq[ModuleID]]("documentation project dependencies") val websiteDir: SettingKey[Path] = settingKey[Path]("website directory") + val badgeInfo: SettingKey[Option[BadgeInfo]] = + settingKey[Option[BadgeInfo]]("information necessary to create badge") + + val BadgeInfo = zio.sbt.BadgeInfo + type BadgeInfo = zio.sbt.BadgeInfo + + val ProjectStage = zio.sbt.WebsiteUtils.ProjectStage + type ProjectStage = zio.sbt.WebsiteUtils.ProjectStage } import autoImport.* @@ -57,13 +73,29 @@ object WebsitePlugin extends sbt.AutoPlugin { publishHashverToNpm := publishHashverToNpmTask.value, generateGithubWorkflow := generateGithubWorkflowTask.value, generateReadme := generateReadmeTask.value, + badgeInfo := None, docsDependencies := Seq.empty, libraryDependencies ++= docsDependencies.value, mdocVariables ++= { Map( "VERSION" -> releaseVersion(sLog.value.warn(_)).getOrElse(version.value), "RELEASE_VERSION" -> releaseVersion(sLog.value.warn(_)).getOrElse("NOT RELEASED YET"), - "SNAPSHOT_VERSION" -> version.value + "SNAPSHOT_VERSION" -> version.value, + "PROJECT_BADGES" -> { + badgeInfo.value match { + case Some(badge) => + WebsiteUtils.generateProjectBadges( + projectStage = badge.projectStage, + groupId = organization.value, + artifact = badge.artifact, + githubUser = "zio", + githubRepo = + scmInfo.value.map(_.browseUrl.getPath.split('/').last).getOrElse("github repo not provided"), + projectName = badge.projectName + ) + case None => "" + } + } ) } ) diff --git a/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala b/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala index f0e0eeed..8e8c787c 100644 --- a/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala +++ b/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala @@ -48,6 +48,66 @@ object WebsiteUtils { result } + def githubBadge(githubUser: String, githubRepo: String, projectName: String): String = { + val githubBadge = s"https://img.shields.io/github/stars/$githubUser/$githubRepo?style=social" + val repoUrl = s"https://github.com/$githubUser/$githubRepo" + s"[![$projectName]($githubBadge)]($repoUrl)" + } + + def discord = + "[![Chat on Discord!](https://img.shields.io/discord/629491597070827530?logo=discord)](https://discord.gg/2ccFBr4)" + + def ciBadge(githubUser: String, githubRepo: String): String = + s"![CI Badge](https://github.com/$githubUser/$githubRepo/workflows/CI/badge.svg)" + + def snapshotBadge(groupId: String, artifact: String): String = { + val badge = s"https://img.shields.io/nexus/s/https/oss.sonatype.org/$groupId/$artifact.svg" + val link = s"https://oss.sonatype.org/content/repositories/snapshots/${groupId.replace('.', '/')}/$artifact/" + s"[![Sonatype Snapshots]($badge)]($link)" + } + + def releaseBadge(groupId: String, artifact: String): String = { + val badge = s"https://img.shields.io/nexus/r/https/oss.sonatype.org/$groupId/$artifact.svg" + val link = s"https://oss.sonatype.org/content/repositories/releases/${groupId.replace('.', '/')}/$artifact/" + s"[![Sonatype Releases]($badge)]($link)" + } + + sealed abstract class ProjectStage(name: String) { + override def toString: String = name.replace(" ", "%20") + } + object ProjectStage { + final case object Development extends ProjectStage(name = "Development") + final case object ProductionReady extends ProjectStage(name = "Production Ready") + final case object Experimental extends ProjectStage(name = "Experimental") + final case object Research extends ProjectStage(name = "Research") + final case object Deprecated extends ProjectStage(name = "Deprecated") + } + + def projectStageBadge(stage: ProjectStage): String = { + val stagePage = "https://github.com/zio/zio/wiki/Project-Stages" + val stageBadge = s"https://img.shields.io/badge/Project%20Stage-$stage-brightgreen.svg" + s"[![$stage]($stageBadge)]($stagePage)" + } + + def generateProjectBadges( + projectStage: ProjectStage, + groupId: String, + artifact: String, + githubUser: String, + githubRepo: String, + projectName: String + ): String = { + val stage = projectStageBadge(projectStage) + val ci = ciBadge(githubUser, githubRepo) + val release = releaseBadge(groupId, artifact) + val snapshot = snapshotBadge(groupId, artifact) + val github = githubBadge(githubUser, githubRepo, projectName) + s"""||Project Stage | CI | Release | Snapshot | Discord | Github | + ||--------------|----|---------|----------|---------|--------| + ||$stage |$ci |$release |$snapshot |$discord |$github | + |""".stripMargin + } + def generateReadme(sourcePath: String): Task[Unit] = for { template <- readFile("README.template.md")