Skip to content

Commit

Permalink
Merge pull request #756 from scalacenter/topic/fixes-docs-1.1.1
Browse files Browse the repository at this point in the history
Show release table and fix versions in docs [DOCS]
  • Loading branch information
jvican authored Dec 11, 2018
2 parents 7aee7d0 + f6ab6e4 commit ab2752a
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/build-tools/sbt/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Install bloop in `project/plugins.sbt`:

```scala
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.1.0")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "@VERSION@")
```

And start up or reload your sbt shell to add the plugin to your working build.
Expand Down
2 changes: 1 addition & 1 deletion docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Center](https://scala.epfl.ch) and [JetBrains](https://www.jetbrains.com/). Bloo
server to implement the protocol and provide build supports to clients such as
[Metals](https://scalameta.org/metals/) and [IntelliJ](https://www.jetbrains.com/idea/)

At the moment, Bloop v1.1.0 partially implements version 2.0.0-M2 and Bloop v1.0.0 implements
At the moment, Bloop @VERSION@ partially implements version 2.0.0-M2 and Bloop v1.0.0 implements
version 1.0.0. If you want to implement a compatible build client, check out [the protocol
specification](https://github.com/scalacenter/bsp/blob/master/docs/bsp.md). As a client, the
protocol gives you fine-grained build and action information and it's more suitable for rich clients
Expand Down
4 changes: 4 additions & 0 deletions docs/release-table.md
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.
```
26 changes: 22 additions & 4 deletions docs/src/main/scala/bloop/Docs.scala
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)
}
}
}
32 changes: 32 additions & 0 deletions docs/src/main/scala/bloop/docs/ReleasesModifier.scala
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
}
}
49 changes: 49 additions & 0 deletions docs/src/main/scala/bloop/docs/Sonatype.scala
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)
}
}
2 changes: 1 addition & 1 deletion docs/tools/nix/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Then, verify your installation by running the command-line application:

```
$ bloop about
bloop v1.1.0
bloop v@VERSION@
Running on Scala v2.12.7 and Zinc v1.1.0
Maintained by the Scala Center (Martin Duhem, Jorge Vicente Cantero)
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/universal/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Then, verify your installation by running the command-line application:

```
$ bloop about
bloop v1.1.0
bloop v@VERSION@
Running on Scala v2.12.7 and Zinc v1.1.0
Maintained by the Scala Center (Martin Duhem, Jorge Vicente Cantero)
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ You've just learned the most basic bloop commands. Learn more commands with `blo

```bash
→ bloop --help
bloop 1.1.0
bloop @VERSION@
Usage: bloop [options] [command] [command-options]


Expand Down
6 changes: 2 additions & 4 deletions website/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@
"title": "Integrate with the Build Server",
"sidebar_label": "Integration Guide"
},
"project-goals": {
"title": "Project Goals",
"sidebar_label": "Project Goals"
"release-table": {
"title": "release-table"
},
"target/scala-2.12/classes/LICENSE": {
"title": "target/scala-2.12/classes/LICENSE"
Expand Down Expand Up @@ -118,7 +117,6 @@
},
"pages-strings": {
"Installation Guide|setup page - header": "Installation Guide",
"The installation guide walks you through all the steps to to install and get any of the supported build tools working with Bloop.|setup page - description": "The installation guide walks you through all the steps to to install and get any of the supported build tools working with Bloop.",
"Pick your preferred method|setup page - step 1": "Pick your preferred method",
"Installation|setup page - step 2": "Installation",
"Usage|setup page - step 3": "Usage",
Expand Down
17 changes: 10 additions & 7 deletions website/pages/en/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ const PrismScala = require("prismjs/components/prism-scala");
const siteConfig = require(process.cwd() + "/siteConfig.js");
const toolsMD = siteConfig.toolsMD;
const buildToolsMD = siteConfig.buildToolsMD;
const releaseTableMD = siteConfig.releaseTableMD;

const SetupHeader = () => {
return (
<div className="page-header text-center">
<div className="page-header text-center installation-header">
<h1>
<translate desc="setup page - header">Installation Guide</translate>
</h1>
<p>
<translate desc="setup page - description">
The installation guide walks you through all the steps to
to install and get any of the supported build tools working with Bloop.
</translate>
</p>
<p>
The installation guide walks you through all the steps to to install and get any
of the supported build tools working with Bloop.
</p>

<div style={{"display": "flex", "justifyContent": "center", "marginBottom": "1em"}}>
<MarkdownBlock key={"release-table"}>{releaseTableMD}</MarkdownBlock>
</div>
</div>
);
};
Expand Down
8 changes: 4 additions & 4 deletions website/siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ buildToolsMD.forEach(buildTool => {
buildTool.export = loadMD(`${buildTool.path}/export.md`);
});

const releaseTableMD = loadMD("../out/release-table.md")

// List of projects/orgs using your project for the users page.
const users = [
{
Expand Down Expand Up @@ -82,6 +84,7 @@ const siteConfig = {
toolsMD,
buildTools,
buildToolsMD,
releaseTableMD,

// If you have users set above, you add it here:
users,
Expand Down Expand Up @@ -170,10 +173,7 @@ const siteConfig = {
editUrl: `${repoUrl}/edit/master/docs/`,
algolia: {
apiKey: 'cf5bcb37b134346182da2be3f5e0a76b',
indexName: 'bloop_scala',
algoliaOptions: {
facetFilters: [ "version:VERSION" ]
}
indexName: 'bloop_scala'
},
};

Expand Down
6 changes: 5 additions & 1 deletion website/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
margin: 0px auto;
max-width: 60%;
}

.installation-header table {
display: initial !important;
}
}

@media only screen and (max-width: 1023px) {
Expand All @@ -17,4 +21,4 @@
}

@media only screen and (min-width: 1500px) {
}
}
4 changes: 4 additions & 0 deletions website/static/css/setup.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
border-bottom: 1px solid #eee;
}

.installation-header table {
display: none;
}

.tools-button {
display: inline-block;
margin-right: 5px;
Expand Down
2 changes: 1 addition & 1 deletion website/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
universal: curl (Default)
- name: Package Managers
items:
homebrew: Homebrew (Mac OS)
homebrew: Homebrew (macOS)
scoop: Scoop (Windows)
nix: Nix

0 comments on commit ab2752a

Please sign in to comment.