Skip to content

Prepare github actions tasks for deploying multiple documentation versions at once #12784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ jobs:

- name: Generate Website
run: |
./project/scripts/genDocs -doc-snapshot
./project/scripts/genDocs

- name: Deploy Website
uses: peaceiris/actions-gh-pages@v3
Expand Down
68 changes: 45 additions & 23 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,9 @@ object Build {
val generateSelfDocumentation = taskKey[Unit]("Generate example documentation")
// Note: the two tasks below should be one, but a bug in Tasty prevents that
val generateScalaDocumentation = inputKey[Unit]("Generate documentation for dotty lib")
val getJarsForScaladoc = taskKey[Seq[String]]("Get jars for scaladoc")
val getDocRootForScaladoc = taskKey[Path]("Get doc root content file for scaladol")
val copyTheScaladocInputs = inputKey[Unit]("Copy sources to be provided to the scaladoc")
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests")

lazy val `scaladoc-testcases` = project.in(file("scaladoc-testcases")).
Expand Down Expand Up @@ -1320,46 +1323,65 @@ object Build {
"scaladoc", "scaladoc/output/self", VersionUtil.gitHash
)
}.value,

generateScalaDocumentation := Def.inputTaskDyn {
val extraArgs = spaceDelimited("[output]").parsed
val dest = file(extraArgs.headOption.getOrElse("scaladoc/output/scala3")).getAbsoluteFile
val roots = extraArgs.lift(1).map(Seq(_)).getOrElse(getJarsForScaladoc.value)
val docRootFile = extraArgs.lift(2).getOrElse(getDocRootForScaladoc.value)
val majorVersion = (LocalProject("scala3-library-bootstrapped") / scalaBinaryVersion).value
val isDefined = extraArgs.isDefinedAt(2)
if (roots.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
else Def.task {
if (!isDefined) {
IO.write(dest / "versions" / "latest-nightly-base", majorVersion)

// This file is used by GitHub Pages when the page is available in a custom domain
IO.write(dest / "CNAME", "dotty.epfl.ch")
}
}.dependsOn(generateDocumentation(
roots, "Scala 3", dest.getAbsolutePath, "master",
Seq(
"-comment-syntax", "wiki",
"-siteroot", "docs",
s"-source-links:docs=github://lampepfl/dotty/master#docs",
"-doc-root-content", docRootFile.toString,
"-Ydocument-synthetic-types",
"-versions-dictionary-url", "http://127.0.0.1:5500/docs/_site/versions.json"
), usingScript = false
))
}.evaluated,

getJarsForScaladoc := Def.task {
val dottyJars: Seq[java.io.File] = Seq(
(`stdlib-bootstrapped`/Compile/products).value,
(`scala3-interfaces`/Compile/products).value,
(`tasty-core-bootstrapped`/Compile/products).value,
).flatten
dottyJars.map(_.getAbsolutePath)
}.value,

val roots = dottyJars.map(_.getAbsolutePath)

getDocRootForScaladoc := Def.task {
val managedSources =
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "scala-library-src"
val projectRoot = (ThisBuild/baseDirectory).value.toPath
val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
val docRootFile = stdLibRoot.resolve("rootdoc.txt")

val dottyManagesSources =
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "dotty-library-src"

val dottyLibRoot = projectRoot.relativize(dottyManagesSources.toPath.normalize())
stdLibRoot.resolve("rootdoc.txt")
}.value,

if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
else Def.task{
IO.write(dest / "versions" / "latest-nightly-base", majorVersion)
copyTheScaladocInputs := Def.inputTask {
val extraArgs = spaceDelimited("[output]").parsed
val dest = extraArgs.lift(0).getOrElse("output")
val ref = extraArgs.lift(1).getOrElse("0.0.0")
val jars = getJarsForScaladoc.value.foreach { jar =>
val file = new File(jar)
val d = new File(s"$dest/$ref")
sbt.IO.copyDirectory(file, d)
}

// This file is used by GitHub Pages when the page is available in a custom domain
IO.write(dest / "CNAME", "dotty.epfl.ch")
}.dependsOn(generateDocumentation(
roots, "Scala 3", dest.getAbsolutePath, "master",
Seq(
"-comment-syntax", "wiki",
"-siteroot", "docs",
s"-source-links:docs=github://lampepfl/dotty/master#docs",
"-doc-root-content", docRootFile.toString,
"-Ydocument-synthetic-types"
), usingScript = false
))
val path = getDocRootForScaladoc.value
val d = new File(s"$dest/$ref.txt")
sbt.IO.copyFile(path.toFile, d)
}.evaluated,

generateTestcasesDocumentation := Def.taskDyn {
Expand Down
1 change: 1 addition & 0 deletions project/scripts/docs/docs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.X,4de0df4bc4a
18 changes: 18 additions & 0 deletions project/scripts/docs/docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
INPUT=./project/scripts/docs/docs.csv
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }

echo '{"versions":{'

while read label ref
do
# echo "\"$label\": \"https://dotty.epfl.ch/$ref/docs/index.html\",",
echo "\"$label\": \"http://127.0.0.1:5500/docs/_site/$ref/docs/index.html\","
done < $INPUT
IFS=$OLDIFS
# echo '"Nightly": "https://dotty.epfl.ch/docs/index.html",'
echo '"Nightly": "http://127.0.0.1:5500/docs/_site/docs/index.html"'
echo '}}'

52 changes: 46 additions & 6 deletions project/scripts/genDocs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,75 @@ set -e
shopt -s extglob # needed for rm everything but x
echo "Working directory: $PWD"

GENDOC_EXTRA_ARGS=$@
GIT_HEAD=$(git rev-parse HEAD) # save current head for commit message in gh-pages
PREVIOUS_SNAPSHOTS_DIR="$PWD/../prev_snapshots"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)"
SITE_OUT_DIR="$PWD/docs/_site"

# Load the csv data into memory

INPUT=./project/scripts/docs/docs.csv
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
CSV_FILE=$(<"$INPUT")


### Obtain the previous versions of the website ###
if [ -d "$PREVIOUS_SNAPSHOTS_DIR" ]; then
rm -rf "$PREVIOUS_SNAPSHOTS_DIR"
fi

mkdir -pv "$PREVIOUS_SNAPSHOTS_DIR"
git remote add doc-remote "https://github.com/lampepfl/dotty-website.git"
# git remote add doc-remote "https://github.com/lampepfl/dotty-website.git"
git fetch doc-remote gh-pages
git checkout gh-pages
(cp -vr [03].*/ "$PREVIOUS_SNAPSHOTS_DIR"; true) # Don't fail if no `3.*` found to copy
git checkout "$GIT_HEAD"

### Generate the current snapshot of the website ###
# this command will generate docs in $PWD/docs/_site

### Gather tasty files for new scaladoc different versions

SBT="$SCRIPT_DIR/sbt"

# We iterate over csv to checkout for different versions and generate their jars respectively.

OLDIFS=$IFS
IFS=','

OUTPUT_DIR="output" # output for cumulutative tasty files for previous versions for


# Firstly iterate over each version and generato sources
while read label ref
do
git checkout "$ref"
"$SBT" "scaladoc/copyTheScaladocInputs $OUTPUT_DIR $ref"
done <<< $CSV_FILE

git checkout "$GIT_HEAD"

# Let's start with generating latest docs for nightly
"$SBT" "scaladoc/generateScalaDocumentation docs/_site"

# make sure that the previous command actually succeeded
# make sure that sbt command actually succeeded
if [ ! -d "$SITE_OUT_DIR" ]; then
echo "Output directory did not exist: $SITE_OUT_DIR" 1>&2
exit 1
fi

# Iterate once again and generate scaladoc for additional older versions
while read label ref
do
# Generate the website
# this command will generate docs in $PWD/docs/_site/$ref
"$SBT" "scaladoc/generateScalaDocumentation docs/_site/$ref $OUTPUT_DIR $ref"
done <<< $CSV_FILE

IFS=$OLDIFS

# Generate json file

touch "docs/_site/versions.json"
sh ./project/scripts/docs/docs.sh > "docs/_site/versions.json"

### Move previous versions' snapshots to _site ###
mv -v "$PREVIOUS_SNAPSHOTS_DIR"/* "$SITE_OUT_DIR"
rm -rf "$PREVIOUS_SNAPSHOTS_DIR"