Skip to content

Commit

Permalink
Generate Project Badges (#12)
Browse files Browse the repository at this point in the history
* generate project badges.

* fix and fmt.

* use proper artifact name.
  • Loading branch information
khajavi authored Dec 7, 2022
1 parent 91016bf commit bb3f21b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 13 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@

# 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

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:
Expand Down
1 change: 1 addition & 0 deletions README.template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ZIO SBT

{{ main_content }}

## Contributing
Expand Down
12 changes: 8 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSUseMainModuleInitializer

sbtPlugin := true
publishMavenStyle := true

Expand Down Expand Up @@ -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)
5 changes: 1 addition & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 33 additions & 1 deletion zio-sbt-website/src/main/scala/zio/sbt/WebsitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.*
Expand All @@ -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 => ""
}
}
)
}
)
Expand Down
60 changes: 60 additions & 0 deletions zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bb3f21b

Please sign in to comment.