-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #756 from scalacenter/topic/fixes-docs-1.1.1
Show release table and fix versions in docs [DOCS]
- Loading branch information
Showing
15 changed files
with
138 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
```scala mdoc:releases | ||
I am going to be replaced by releases. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
package bloop | ||
|
||
import bloop.docs.{ReleasesModifier, Sonatype} | ||
import mdoc.MainSettings | ||
|
||
import scala.meta.io.AbsolutePath | ||
|
||
object Docs { | ||
def main(args: Array[String]): Unit = { | ||
val settings = mdoc.MainSettings() | ||
.withSiteVariables(Map("VERSION" -> bloop.internal.build.BuildInfo.version)) | ||
val cwd0 = AbsolutePath.workingDirectory | ||
// Depending on who runs it (sbt vs bloop), the current working directory is different | ||
val cwd = if (!cwd0.resolve("docs").isDirectory) cwd0.toNIO.getParent else cwd0.toNIO | ||
|
||
val settings = MainSettings() | ||
.withSiteVariables( | ||
Map( | ||
"VERSION" -> Sonatype.release.version, | ||
"LATEST_VERSION" -> bloop.internal.build.BuildInfo.version | ||
) | ||
) | ||
.withArgs(args.toList) | ||
// it should work with mdoc when run inside bloop but it doesn't, let's wait until it's fixed | ||
.withIn(cwd.resolve("docs")) | ||
.withOut(cwd.resolve("out")) | ||
.withStringModifiers(List(new ReleasesModifier)) | ||
|
||
val exitCode = mdoc.Main.process(settings) | ||
val exitCode = _root_.mdoc.Main.process(settings) | ||
if (exitCode != 0) sys.exit(exitCode) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bloop.docs | ||
|
||
import mdoc.Reporter | ||
import mdoc.StringModifier | ||
|
||
import scala.meta.inputs.Input | ||
|
||
class ReleasesModifier extends StringModifier { | ||
override val name: String = "releases" | ||
override def process(info: String, code: Input, reporter: Reporter): String = { | ||
val xml = <table> | ||
<thead> | ||
<th>Version</th> | ||
<th>Published</th> | ||
<th>Resolver</th> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>{Sonatype.release.version}</td> | ||
<td>{Sonatype.release.date}</td> | ||
<td><code>-r sonatype:releases</code></td> | ||
</tr> | ||
<tr> | ||
<td>{Sonatype.current.version}</td> | ||
<td>{Sonatype.current.date}</td> | ||
<td><code>-r bintray:scalacenter/releases</code></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
xml.toString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package bloop.docs | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
|
||
import bloop.internal.build.BuildInfo | ||
import org.jsoup.Jsoup | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.util.control.NonFatal | ||
|
||
case class Release(version: String, lastModified: Date) { | ||
def date: String = { | ||
val pattern = new SimpleDateFormat("dd MMM yyyy HH:mm") | ||
pattern.format(lastModified) | ||
} | ||
} | ||
|
||
object Sonatype { | ||
lazy val release = Sonatype.fetchLatest("releases") | ||
|
||
// Copy-pasted from https://github.com/scalameta/metals/blob/994e5e6746ad327ce727d688ad9831e0fbb69b3f/metals-docs/src/main/scala/docs/Snapshot.scala | ||
lazy val current: Release = Release(BuildInfo.version, new Date()) | ||
|
||
/** Returns the latest published snapshot release, or the current release if. */ | ||
private def fetchLatest(repo: String): Release = { | ||
// maven-metadata.xml is consistently outdated so we scrape the "Last modified" column | ||
// of the HTML page that lists all snapshot releases instead. | ||
val doc = Jsoup | ||
.connect( | ||
s"https://oss.sonatype.org/content/repositories/$repo/ch/epfl/scala/bloop-frontend_2.12/" | ||
) | ||
.get | ||
val dateTime = new SimpleDateFormat("EEE MMM d H:m:s z yyyy") | ||
val versions: Seq[Release] = doc.select("tr").asScala.flatMap { tr => | ||
val lastModified = | ||
tr.select("td:nth-child(2)").text() | ||
val version = | ||
tr.select("td:nth-child(1)").text().stripSuffix("/") | ||
if (lastModified.nonEmpty && !version.contains("maven-metadata")) { | ||
val date = dateTime.parse(lastModified) | ||
List(Release(version, date)) | ||
} else { | ||
List() | ||
} | ||
} | ||
versions.maxBy(_.lastModified.getTime) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters