Skip to content

Commit

Permalink
Merge pull request #72 from danicheg/microsite
Browse files Browse the repository at this point in the history
Migrate the website to Docusaurus
  • Loading branch information
danicheg authored Jan 7, 2024
2 parents 57ebfa8 + 49f7119 commit 2ac3bc2
Show file tree
Hide file tree
Showing 54 changed files with 14,502 additions and 163,847 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.class
*.log
**/.DS_Store

# sbt specific
.cache
Expand Down Expand Up @@ -32,3 +33,14 @@ project/plugins/project/
.metals
.vscode
metals.sbt

# website
website/translated_docs
website/build/
website/yarn.lock
website/node_modules
website/i18n/*
!website/i18n/en.json
out/
node_modules/
package-lock.json
30 changes: 29 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@ import _root_.ch.epfl.scala.profiling.build.BuildImplementation.BuildDefaults
import scalapb.compiler.Version.scalapbVersion
lazy val profiledb = project
.in(file("profiledb"))
.enablePlugins(BuildInfoPlugin)
// .settings(metalsSettings)
.settings(
// Specify scala version to allow third-party software to use this module
crossScalaVersions := bin212 ++ bin213,
scalaVersion := bin212.head,
libraryDependencies +=
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapbVersion % "protobuf",
Compile / PB.targets := Seq(scalapb.gen() -> (Compile / sourceManaged).value)
Compile / managedSourceDirectories += target.value / "protobuf-generated",
Compile / PB.targets in Compile := Seq(
scalapb.gen() -> (target.value / "protobuf-generated")
),
buildInfoPackage := "scalac.profiling.internal.build",
buildInfoKeys := List[BuildInfoKey](
Keys.organization,
Keys.version,
Keys.scalaVersion,
Keys.crossScalaVersions
)
)

// Do not change the lhs id of this plugin, `BuildPlugin` relies on it
Expand Down Expand Up @@ -189,6 +200,23 @@ lazy val integrations = project
}.evaluated
)

lazy val docs = project
.in(file("docs-gen"))
.dependsOn(profiledb)
.enablePlugins(MdocPlugin, DocusaurusPlugin)
.settings(
name := "scalac-profiling-docs",
moduleName := "scalac-profiling-docs",
libraryDependencies += "io.get-coursier" % "interface" % "1.0.19",
(publish / skip) := true,
scalaVersion := bin212.head,
mdoc := (Compile / run).evaluated,
(Compile / mainClass) := Some("ch.epfl.scala.profiling.Docs"),
(Compile / resources) ++= {
List((ThisBuild / baseDirectory).value / "docs")
}
)

val proxy = project
.in(file(".proxy"))
.aggregate(BetterFiles, Wartremover)
Expand Down
42 changes: 42 additions & 0 deletions docs-gen/src/main/scala/ch/epfl/scala/profiling/Docs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ch.epfl.scala.profiling

import ch.epfl.scala.profiling.docs.Sonatype
import mdoc.MainSettings

import scala.meta.io.AbsolutePath

object Docs {
def main(args: Array[String]): Unit = {
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

def prepareVersions(prefix: String): Seq[String] => String =
_.sortWith {
case (l, r) =>
l.replaceFirst(prefix + ".", "").toInt <=
r.replaceFirst(prefix + ".", "").toInt
}.mkString(", ")

val (scala212Versions, scala213Versions) =
scalac.profiling.internal.build.BuildInfo.crossScalaVersions.partition(_.startsWith("2.12"))

val settings = MainSettings()
.withSiteVariables(
Map(
"VERSION" -> Sonatype.releaseScalacProfiling.version,
"LATEST_VERSION" -> scalac.profiling.internal.build.BuildInfo.version,
"SBT_PLUGIN_VERSION" -> Sonatype.releaseSbtPlugin.version,
"SCALA212_VERSIONS" -> prepareVersions("2.12")(scala212Versions),
"SCALA213_VERSIONS" -> prepareVersions("2.13")(scala213Versions)
)
)
.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"))

val exitCode = _root_.mdoc.Main.process(settings)
if (exitCode != 0) sys.exit(exitCode)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package ch.epfl.scala.profiling.docs

import coursierapi.Repository
import coursierapi.error.CoursierError

import ch.epfl.scala.profiledb.utils.AbsolutePath

import scala.jdk.CollectionConverters._

// Slight modification of `bloop.DependencyResolution`
object DependencyResolution {

/**
* @param organization The module's organization.
* @param module The module's name.
* @param version The module's version.
*/
final case class Artifact(organization: String, module: String, version: String)

/**
* Resolve the specified modules and get all the files. By default, the local Ivy
* repository and Maven Central are included in resolution. This resolution throws
* in case there is an error.
*
* @param artifacts Artifacts to resolve
* @param resolveSources Resolve JAR files containing sources
* @param additionalRepos Additional repositories to include in resolution.
* @return All the resolved files.
*/
def resolve(
artifacts: List[Artifact],
resolveSources: Boolean = false,
additionalRepos: Seq[Repository] = Nil
): Array[AbsolutePath] = {
resolveWithErrors(artifacts, resolveSources, additionalRepos) match {
case Right(paths) => paths
case Left(error) => throw error
}
}

/**
* Resolve the specified module and get all the files. By default, the local ivy
* repository and Maven Central are included in resolution. This resolution is
* pure and returns either some errors or some resolved jars.
*
* @param artifacts Artifacts to resolve
* @return Either a coursier error or all the resolved files.
*/
def resolveWithErrors(
artifacts: List[Artifact],
resolveSources: Boolean = false,
additionalRepositories: Seq[Repository] = Nil
): Either[CoursierError, Array[AbsolutePath]] = {
val dependencies = artifacts.map { artifact =>
import artifact._
val baseDep = coursierapi.Dependency.of(organization, module, version)
if (resolveSources) baseDep.withClassifier("sources")
else baseDep
}
resolveDependenciesWithErrors(dependencies, resolveSources, additionalRepositories)
}

/**
* Resolve the specified dependencies and get all the files. By default, the
* local ivy repository and Maven Central are included in resolution. This
* resolution is pure and returns either some errors or some resolved jars.
*
* @param dependencies Dependencies to resolve.
* @param additionalRepositories Additional repositories to include in resolution.
* @return Either a coursier error or all the resolved files.
*/
def resolveDependenciesWithErrors(
dependencies: Seq[coursierapi.Dependency],
resolveSources: Boolean = false,
additionalRepositories: Seq[Repository] = Nil
): Either[CoursierError, Array[AbsolutePath]] = {
val fetch = coursierapi.Fetch
.create()
.withDependencies(dependencies: _*)
if (resolveSources)
fetch.addArtifactTypes("src", "jar")
fetch.addRepositories(additionalRepositories: _*)

try Right(fetch.fetch().asScala.toArray.map(f => AbsolutePath(f.toPath)))
catch {
case error: CoursierError => Left(error)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package ch.epfl.scala.profiling.docs

import java.text.SimpleDateFormat
import java.util.Date
import org.jsoup.Jsoup

import scala.util.control.NonFatal
import coursierapi.MavenRepository

import scala.jdk.CollectionConverters._

final case class Release(version: String, lastModified: Date)

object Sonatype {
lazy val releaseScalacProfiling = fetchLatest("scalac-profiling_2.12.18")
lazy val releaseSbtPlugin = fetchLatest("sbt-scalac-profiling_2.12_1.0")

/** Returns the latest published snapshot release, or the current release if. */
private def fetchLatest(artifact: String): Release = {
val artifacts = List(
DependencyResolution.Artifact("ch.epfl.scala", artifact, "latest.release")
)
val resolvedJars = DependencyResolution.resolve(
artifacts,
additionalRepos =
List(MavenRepository.of(s"https://oss.sonatype.org/content/repositories/staging"))
)

val latestStableVersion = resolvedJars.find(_.syntax.contains(artifact)) match {
case None => sys.error(s"Missing jar for resolved artifact '$artifact'")
case Some(jar) =>
val firstTry =
jar.underlying
.getFileName()
.toString
.stripSuffix(".jar")
.stripPrefix(artifact + "-")

if (!firstTry.endsWith("_2.12.18") && !firstTry.endsWith("_2.12_1.0"))
firstTry
else jar.getParent.getParent.underlying.getFileName.toString
}

val doc = Jsoup
.connect(
s"https://oss.sonatype.org/content/repositories/releases/ch/epfl/scala/$artifact/"
)
.get

val dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm")
val releases = doc
.select("pre")
.asScala
.flatMap { versionRow =>
val elements = versionRow.getAllElements().asScala.filterNot(_.text().contains("../"))
val nodes = versionRow.textNodes().asScala.filter(_.text().trim.nonEmpty)

elements.zip(nodes).flatMap {
case (element, node) =>
val version = element.text().stripSuffix("/")

if (version.startsWith("maven-metadata")) Nil
else {
node.text().trim().split("\\s+").init.toList match {
case List(date, time) =>
try {
val parsedDate = dateTime.parse(s"$date $time")
List(Release(version, parsedDate))
} catch {
case NonFatal(_) => Nil
}
case _ => Nil
}
}
}
}

releases.filter(_.version == latestStableVersion).maxBy(_.lastModified.getTime)
}
}
16 changes: 0 additions & 16 deletions docs/LICENSE.md

This file was deleted.

5 changes: 0 additions & 5 deletions docs/bin/update.sh

This file was deleted.

Loading

0 comments on commit 2ac3bc2

Please sign in to comment.