From ee76a76cef76bf22ae544bc52cdfe5dac8f212fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Herna=CC=81ndez?= Date: Tue, 9 Jan 2024 19:37:54 +0100 Subject: [PATCH] Add new `SUPPORTED_SCALA_VERSIONS` mdoc variable with list of supported versions in markdown format --- .../sbt/github/mdoc/SbtGithubMdocPlugin.scala | 47 +++++++++++-------- .../sbt-test/sbt-github-mdoc/simple/DOCS.md | 4 +- .../sbt-test/sbt-github-mdoc/simple/build.sbt | 7 +-- .../sbt-github-mdoc/simple/docs/DOCS.md | 4 +- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/modules/sbt-github-mdoc/src/main/scala/com/alejandrohdezma/sbt/github/mdoc/SbtGithubMdocPlugin.scala b/modules/sbt-github-mdoc/src/main/scala/com/alejandrohdezma/sbt/github/mdoc/SbtGithubMdocPlugin.scala index f5676cd6..d69ca15d 100644 --- a/modules/sbt-github-mdoc/src/main/scala/com/alejandrohdezma/sbt/github/mdoc/SbtGithubMdocPlugin.scala +++ b/modules/sbt-github-mdoc/src/main/scala/com/alejandrohdezma/sbt/github/mdoc/SbtGithubMdocPlugin.scala @@ -87,31 +87,40 @@ object SbtGithubMdocPlugin extends AutoPlugin { displayName := SbtGithubPlugin.info.value._2, removeVersionTimestampInMdoc := true, mdocVariables ++= Map( - "ORGANIZATION" -> organization.value, - "NAME" -> displayName.value, - "REPO" -> repository.value.map(_.name).getOrElse(""), - "DEFAULT_BRANCH" -> repository.value.map(_.defaultBranch).getOrElse(""), - "LICENSE" -> licenses.value.headOption.map(_._1).getOrElse(""), - "ORG_NAME" -> organizationName.value, - "DESCRIPTION" -> description.value, - "ORG_EMAIL" -> organizationEmail.value.getOrElse(""), - "ORG_URL" -> organizationHomepage.value.map(url => s"$url").getOrElse(""), - "START_YEAR" -> startYear.value.fold("")(year => s"$year"), - "YEAR_RANGE" -> yearRange.value.getOrElse(""), - "VERSION" -> versionForMdoc.value, - "CONTRIBUTORS" -> contributors.value.markdownList, - "CONTRIBUTORS_LIST" -> contributors.value.markdownList, - "CONTRIBUTORS_TABLE" -> contributors.value.markdownTable, - "COLLABORATORS" -> collaborators.value.markdownList, - "COLLABORATORS_LIST" -> collaborators.value.markdownList, - "COLLABORATORS_TABLE" -> collaborators.value.markdownTable, + "ORGANIZATION" -> organization.value, + "NAME" -> displayName.value, + "REPO" -> repository.value.map(_.name).getOrElse(""), + "DEFAULT_BRANCH" -> repository.value.map(_.defaultBranch).getOrElse(""), + "SUPPORTED_SCALA_VERSIONS" -> supportedScalaVersionsForMDoc.value, + "LICENSE" -> licenses.value.headOption.map(_._1).getOrElse(""), + "ORG_NAME" -> organizationName.value, + "DESCRIPTION" -> description.value, + "ORG_EMAIL" -> organizationEmail.value.getOrElse(""), + "ORG_URL" -> organizationHomepage.value.map(url => s"$url").getOrElse(""), + "START_YEAR" -> startYear.value.fold("")(year => s"$year"), + "YEAR_RANGE" -> yearRange.value.getOrElse(""), + "VERSION" -> versionForMdoc.value, + "CONTRIBUTORS" -> contributors.value.markdownList, + "CONTRIBUTORS_LIST" -> contributors.value.markdownList, + "CONTRIBUTORS_TABLE" -> contributors.value.markdownTable, + "COLLABORATORS" -> collaborators.value.markdownList, + "COLLABORATORS_LIST" -> collaborators.value.markdownList, + "COLLABORATORS_TABLE" -> collaborators.value.markdownTable, "COPYRIGHT_OWNER" -> organizationHomepage.value .map(url => s"${organizationName.value} <$url>") .getOrElse(organizationName.value) ) ) - private val versionForMdoc = Def.setting { + private val supportedScalaVersionsForMDoc: Def.Initialize[String] = Def.setting { + crossScalaVersions.value.map(version => s"`$version`") match { + case list :+ last => s"${list.mkString(", ")} and $last" + case head :: Nil => head + case Nil => "" + } + } + + private val versionForMdoc: Def.Initialize[String] = Def.setting { if (removeVersionTimestampInMdoc.value) version.value.replaceAll("\\+.*", "") else version.value } diff --git a/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/DOCS.md b/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/DOCS.md index 4a0dbf25..e6d1489c 100644 --- a/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/DOCS.md +++ b/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/DOCS.md @@ -37,4 +37,6 @@ https://github.com/user1 | :--: | :--: | | user1 | user2 | -The First User \ No newline at end of file +The First User + +`2.12.18`, `2.13.12` and `3.3.0` \ No newline at end of file diff --git a/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/build.sbt b/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/build.sbt index 359c02fb..6c3dabfd 100644 --- a/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/build.sbt +++ b/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/build.sbt @@ -1,9 +1,10 @@ ThisBuild / scmInfo := Some( ScmInfo(url("http://example.com"), "scm:git:https://github.com/alejandrohdezma/sbt-github.git") ) -ThisBuild / organization := "my.org" -ThisBuild / githubEnabled := true -ThisBuild / githubAuthToken := Some(AuthToken("1234")) +ThisBuild / crossScalaVersions := Seq("2.12.18", "2.13.12", "3.3.0") +ThisBuild / organization := "my.org" +ThisBuild / githubEnabled := true +ThisBuild / githubAuthToken := Some(AuthToken("1234")) ThisBuild / githubApiEntryPoint := { val github = baseDirectory.value / "github" diff --git a/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/docs/DOCS.md b/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/docs/DOCS.md index ec0d5c7b..f94526c5 100644 --- a/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/docs/DOCS.md +++ b/modules/sbt-github-mdoc/src/sbt-test/sbt-github-mdoc/simple/docs/DOCS.md @@ -30,4 +30,6 @@ @COLLABORATORS_TABLE@ -@COPYRIGHT_OWNER@ \ No newline at end of file +@COPYRIGHT_OWNER@ + +@SUPPORTED_SCALA_VERSIONS@ \ No newline at end of file