Skip to content

Commit 4795978

Browse files
authored
Merge pull request #119 from armanbilge/feature/unidoc-artifact
Create `TypelevelUnidocPlugin`
2 parents 6b942f9 + c83645a commit 4795978

File tree

7 files changed

+112
-23
lines changed

7 files changed

+112
-23
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ jobs:
8686

8787
- name: Make target directories
8888
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/series/0.4')
89-
run: mkdir -p github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target mdocs/target site/target ci-signing/target mergify/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
89+
run: mkdir -p github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target mdocs/target site/target ci-signing/target mergify/target unidoc/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
9090

9191
- name: Compress target directories
9292
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/series/0.4')
93-
run: tar cf targets.tar github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target mdocs/target site/target ci-signing/target mergify/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
93+
run: tar cf targets.tar github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target mdocs/target site/target ci-signing/target mergify/target unidoc/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
9494

9595
- name: Upload target directories
9696
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/series/0.4')

.mergify.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ pull_request_rules:
144144
add:
145145
- sonatype-ci-release
146146
remove: []
147+
- name: Label unidoc PRs
148+
conditions:
149+
- files~=^unidoc/
150+
actions:
151+
label:
152+
add:
153+
- unidoc
154+
remove: []
147155
- name: Label versioning PRs
148156
conditions:
149157
- files~=^versioning/

build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ lazy val root = tlCrossRootProject.aggregate(
3131
core,
3232
ciRelease,
3333
site,
34+
unidoc,
3435
docs
3536
)
3637

@@ -163,11 +164,19 @@ lazy val site = project
163164
)
164165
.dependsOn(kernel, github, githubActions, noPublish)
165166

167+
lazy val unidoc = project
168+
.in(file("unidoc"))
169+
.enablePlugins(TypelevelUnidocPlugin)
170+
.settings(
171+
name := "sbt-typelevel-docs"
172+
)
173+
166174
lazy val docs = project
167175
.in(file("mdocs"))
168176
.enablePlugins(TypelevelSitePlugin)
169177
.settings(
170178
laikaConfig ~= { _.withRawContent },
179+
tlSiteApiPackage := Some("org.typelevel.sbt"),
171180
tlSiteRelatedProjects := Seq(
172181
"sbt" -> url("https://www.scala-sbt.org/"),
173182
"sbt-crossproject" -> url("https://github.com/portable-scala/sbt-crossproject"),

site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ object TypelevelSitePlugin extends AutoPlugin {
4545
lazy val tlSiteHeliumExtensions =
4646
settingKey[ThemeProvider]("The Typelevel Helium extensions")
4747
lazy val tlSiteApiUrl = settingKey[Option[URL]]("URL to the API docs")
48+
lazy val tlSiteApiModule =
49+
settingKey[Option[ModuleID]]("The module that publishes API docs")
50+
lazy val tlSiteApiPackage = settingKey[Option[String]](
51+
"The top-level package for your API docs (e.g. org.typlevel.sbt)")
4852
lazy val tlSiteRelatedProjects =
4953
settingKey[Seq[(String, URL)]]("A list of related projects (default: cats)")
5054

@@ -73,10 +77,15 @@ object TypelevelSitePlugin extends AutoPlugin {
7377
override def requires =
7478
MdocPlugin && LaikaPlugin && TypelevelGitHubPlugin && GenerativePlugin && NoPublishPlugin
7579

80+
override def globalSettings = Seq(
81+
tlSiteApiModule := None
82+
)
83+
7684
override def buildSettings = Seq(
7785
tlSitePublishBranch := Some("main"),
7886
tlSitePublishTags := tlSitePublishBranch.value.isEmpty,
7987
tlSiteApiUrl := None,
88+
tlSiteApiPackage := None,
8089
tlSiteRelatedProjects := Seq(TypelevelProject.Cats),
8190
tlSiteKeepFiles := true,
8291
homepage := {
@@ -98,17 +107,32 @@ object TypelevelSitePlugin extends AutoPlugin {
98107
Laika / sourceDirectories := Seq(mdocOut.value),
99108
laikaTheme := tlSiteHeliumConfig.value.build.extend(tlSiteHeliumExtensions.value),
100109
mdocVariables ++= Map(
101-
"VERSION" -> GitHelper
102-
.previousReleases(fromHead = true)
103-
.filterNot(_.isPrerelease)
104-
.headOption
105-
.fold(version.value)(_.toString),
110+
"VERSION" -> currentRelease.value.getOrElse(version.value),
106111
"SNAPSHOT_VERSION" -> version.value
107112
),
108113
tlSiteHeliumExtensions := TypelevelHeliumExtensions(
109114
licenses.value.headOption,
110115
tlSiteRelatedProjects.value
111116
),
117+
tlSiteApiUrl := {
118+
val javadocioUrl = for {
119+
moduleId <- (ThisProject / tlSiteApiModule).value
120+
cross <- CrossVersion(
121+
moduleId.crossVersion,
122+
scalaVersion.value,
123+
scalaBinaryVersion.value
124+
)
125+
version <- currentRelease.value
126+
} yield {
127+
val o = moduleId.organization
128+
val n = cross(moduleId.name)
129+
val v = version
130+
val p = tlSiteApiPackage.value.fold("")(_.replace('.', '/') + '/')
131+
url(s"https://www.javadoc.io/doc/$o/$n/$v/$p")
132+
}
133+
134+
tlSiteApiUrl.value.orElse(javadocioUrl)
135+
},
112136
tlSiteHeliumConfig := {
113137
Helium
114138
.defaults
@@ -218,6 +242,14 @@ object TypelevelSitePlugin extends AutoPlugin {
218242
)
219243
)
220244

245+
private lazy val currentRelease = Def.setting {
246+
GitHelper
247+
.previousReleases(fromHead = true)
248+
.filterNot(_.isPrerelease)
249+
.headOption
250+
.map(_.toString)
251+
}
252+
221253
private def previewTask = Def
222254
.taskDyn {
223255
// inlined from https://github.com/planet42/Laika/blob/9022f6f37c9017f7612fa59398f246c8e8c42c3e/sbt/src/main/scala/laika/sbt/Tasks.scala#L192

sonatype/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")
22
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.11")
3+
addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")

sonatype/src/main/scala/org/typelevel/sbt/TypelevelSonatypePlugin.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,23 @@ object TypelevelSonatypePlugin extends AutoPlugin {
6262
"s01.oss.sonatype.org"
6363
}
6464
},
65-
apiURL := {
66-
val javadocio =
67-
if (isSnapshot.value || sbtPlugin.value || !publishArtifact.value)
68-
None // javadoc.io doesn't support snapshots, sbt plugins, or unpublished modules ;)
69-
else
70-
CrossVersion(
71-
crossVersion.value,
72-
scalaVersion.value,
73-
scalaBinaryVersion.value
74-
).map { cross =>
75-
url(
76-
s"https://www.javadoc.io/doc/${organization.value}/${cross(moduleName.value)}/${version.value}/")
77-
}
78-
79-
apiURL.value.orElse(javadocio)
80-
}
65+
apiURL := apiURL.value.orElse(javadocioUrl.value)
8166
)
8267

68+
private[sbt] def javadocioUrl = Def.setting {
69+
if (isSnapshot.value || sbtPlugin.value || !publishArtifact.value)
70+
None // javadoc.io doesn't support snapshots, sbt plugins, or unpublished modules ;)
71+
else
72+
CrossVersion(
73+
crossVersion.value,
74+
scalaVersion.value,
75+
scalaBinaryVersion.value
76+
).map { cross =>
77+
url(
78+
s"https://www.javadoc.io/doc/${organization.value}/${cross(moduleName.value)}/${version.value}/")
79+
}
80+
}
81+
8382
private def sonatypeBundleReleaseIfRelevant: Command =
8483
Command.command("tlSonatypeBundleReleaseIfRelevant") { state =>
8584
if (state.getSetting(isSnapshot).getOrElse(false))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.sbt
18+
19+
import sbt._, Keys._
20+
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
21+
import sbtunidoc.ScalaUnidocPlugin
22+
23+
object TypelevelUnidocPlugin extends AutoPlugin {
24+
25+
override def requires = ScalaUnidocPlugin
26+
27+
override def trigger = noTrigger
28+
29+
import ScalaUnidocPlugin.autoImport._
30+
import TypelevelSonatypePlugin.javadocioUrl
31+
32+
override def projectSettings = Seq(
33+
Compile / packageDoc / mappings := (ScalaUnidoc / packageDoc / mappings).value,
34+
ThisBuild / apiURL := javadocioUrl.value,
35+
mimaPreviousArtifacts := Set.empty,
36+
// tell the site plugin about us, without forcing the dependency!
37+
ThisBuild / SettingKey[Option[ModuleID]]("tlSiteApiModule") := Some(projectID.value)
38+
)
39+
40+
}

0 commit comments

Comments
 (0)