Skip to content

Commit

Permalink
Tweak doc version URLs (#3939)
Browse files Browse the repository at this point in the history
Duplicate `latest` as `0.12.x`, and fix the `.x` URLs and display names
for old versions
  • Loading branch information
lihaoyi authored Nov 11, 2024
1 parent 891119f commit 15627f0
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions docs/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ object `package` extends RootModule {
sanitizeAntoraYml(
dest,
"main-branch",
build.millVersion().split('.').dropRight(1).mkString(".") + ".x",
"main-branch",
build.millLastTag()
)
PathRef(dest)
Expand All @@ -172,17 +172,15 @@ object `package` extends RootModule {
def sanitizeAntoraYml(
dest: os.Path,
version: String,
millVersion: String,
displayVersion: String,
millLastTag: String
): Unit = {
val isPreRelease = (millVersion != millLastTag) || Seq("-M", "-RC").exists(millVersion.contains)
val isPreRelease = version == "main-branch" || Seq("-M", "-RC").exists(version.contains)
val preReleaseSuffix = if (isPreRelease) "\nprerelease: true" else ""
val lines = os.read(dest / "antora.yml").linesIterator.map {
case s"version:$_" =>
if (isPreRelease)
s"version: '${version}'\ndisplay-version: 'main-branch'\nprerelease: true"
else
s"version: '${version}'\ndisplay-version: '${millVersion}'"
case s" mill-version:$_" => s" mill-version: '$millVersion'"
s"version: '$version'\ndisplay-version: '$displayVersion'$preReleaseSuffix"
case s" mill-version:$_" => s" mill-version: '$millLastTag'"
case s" mill-last-tag:$_" => s" mill-last-tag: '$millLastTag'"
case l => l
}
Expand Down Expand Up @@ -246,16 +244,23 @@ object `package` extends RootModule {
}

def oldDocSources: T[Seq[PathRef]] = Task {
for (oldVersion <- build.Settings.docTags) yield {
val latest = build.Settings.docTags.last == oldVersion
val checkout = T.dest / oldVersion
val versionLabels =
build.Settings.docTags.map{v =>
val xVersion = v.split('.').dropRight(1).mkString(".") + ".x"
(v, xVersion, xVersion)
} ++
// Set the latest stable branch as the "master" docs that people default to
Seq((build.Settings.docTags.last, "master", s"latest-${build.Settings.docTags.last}"))

for ((millLastTag, version, displayVersion) <- versionLabels) yield {
val checkout = T.dest / displayVersion
os.proc("git", "clone", T.workspace / ".git", checkout).call(stdout = os.Inherit)
os.proc("git", "checkout", oldVersion).call(cwd = checkout, stdout = os.Inherit)
os.proc("git", "checkout", millLastTag).call(cwd = checkout, stdout = os.Inherit)
val outputFolder = checkout / "out" / "docs" / "source.dest"
os.proc("./mill", "-i", "docs.source").call(cwd = checkout, stdout = os.Inherit)
expandDiagramsInDirectoryAdocFile(outputFolder, mill.main.VisualizeModule.classpath().map(_.path))
// Set the latest stable branch as the "master" docs that people default to
sanitizeAntoraYml(outputFolder, if (latest) "master" else oldVersion, oldVersion, oldVersion)

sanitizeAntoraYml(outputFolder, version, displayVersion, millLastTag)
PathRef(outputFolder)
}
}
Expand Down

0 comments on commit 15627f0

Please sign in to comment.