Skip to content

Commit 2a621da

Browse files
committed
Prepare github actions tasks for deploying multiple documentation versions at once
1 parent fe2fcc4 commit 2a621da

File tree

5 files changed

+111
-30
lines changed

5 files changed

+111
-30
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ jobs:
492492

493493
- name: Generate Website
494494
run: |
495-
./project/scripts/genDocs -doc-snapshot
495+
./project/scripts/genDocs
496496
497497
- name: Deploy Website
498498
uses: peaceiris/actions-gh-pages@v3

project/Build.scala

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,9 @@ object Build {
12191219
val generateSelfDocumentation = taskKey[Unit]("Generate example documentation")
12201220
// Note: the two tasks below should be one, but a bug in Tasty prevents that
12211221
val generateScalaDocumentation = inputKey[Unit]("Generate documentation for dotty lib")
1222+
val getJarsForScaladoc = taskKey[Seq[String]]("Get jars for scaladoc")
1223+
val getDocRootForScaladoc = taskKey[Path]("Get doc root content file for scaladol")
1224+
val copyTheScaladocInputs = inputKey[Unit]("Copy sources to be provided to the scaladoc")
12221225
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests")
12231226

12241227
lazy val `scaladoc-testcases` = project.in(file("scaladoc-testcases")).
@@ -1320,46 +1323,65 @@ object Build {
13201323
"scaladoc", "scaladoc/output/self", VersionUtil.gitHash
13211324
)
13221325
}.value,
1326+
13231327
generateScalaDocumentation := Def.inputTaskDyn {
13241328
val extraArgs = spaceDelimited("[output]").parsed
13251329
val dest = file(extraArgs.headOption.getOrElse("scaladoc/output/scala3")).getAbsoluteFile
1330+
val roots = extraArgs.lift(1).map(Seq(_)).getOrElse(getJarsForScaladoc.value)
1331+
val docRootFile = extraArgs.lift(2).getOrElse(getDocRootForScaladoc.value)
13261332
val majorVersion = (LocalProject("scala3-library-bootstrapped") / scalaBinaryVersion).value
1333+
val isDefined = extraArgs.isDefinedAt(2)
1334+
if (roots.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
1335+
else Def.task {
1336+
if (!isDefined) {
1337+
IO.write(dest / "versions" / "latest-nightly-base", majorVersion)
1338+
1339+
// This file is used by GitHub Pages when the page is available in a custom domain
1340+
IO.write(dest / "CNAME", "dotty.epfl.ch")
1341+
}
1342+
}.dependsOn(generateDocumentation(
1343+
roots, "Scala 3", dest.getAbsolutePath, "master",
1344+
Seq(
1345+
"-comment-syntax", "wiki",
1346+
"-siteroot", "docs",
1347+
s"-source-links:docs=github://lampepfl/dotty/master#docs",
1348+
"-doc-root-content", docRootFile.toString,
1349+
"-Ydocument-synthetic-types",
1350+
"-versions-dictionary-url", "http://127.0.0.1:5500/docs/_site/versions.json"
1351+
), usingScript = false
1352+
))
1353+
}.evaluated,
13271354

1355+
getJarsForScaladoc := Def.task {
13281356
val dottyJars: Seq[java.io.File] = Seq(
13291357
(`stdlib-bootstrapped`/Compile/products).value,
13301358
(`scala3-interfaces`/Compile/products).value,
13311359
(`tasty-core-bootstrapped`/Compile/products).value,
13321360
).flatten
1361+
dottyJars.map(_.getAbsolutePath)
1362+
}.value,
13331363

1334-
val roots = dottyJars.map(_.getAbsolutePath)
1335-
1364+
getDocRootForScaladoc := Def.task {
13361365
val managedSources =
13371366
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "scala-library-src"
13381367
val projectRoot = (ThisBuild/baseDirectory).value.toPath
13391368
val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
1340-
val docRootFile = stdLibRoot.resolve("rootdoc.txt")
1341-
1342-
val dottyManagesSources =
1343-
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "dotty-library-src"
1344-
1345-
val dottyLibRoot = projectRoot.relativize(dottyManagesSources.toPath.normalize())
1369+
stdLibRoot.resolve("rootdoc.txt")
1370+
}.value,
13461371

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

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

13651387
generateTestcasesDocumentation := Def.taskDyn {

project/scripts/docs/docs.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0.X,4de0df4bc4a

project/scripts/docs/docs.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
INPUT=./project/scripts/docs/docs.csv
3+
OLDIFS=$IFS
4+
IFS=','
5+
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
6+
7+
echo '{"versions":{'
8+
9+
while read label ref
10+
do
11+
# echo "\"$label\": \"https://dotty.epfl.ch/$ref/docs/index.html\",",
12+
echo "\"$label\": \"http://127.0.0.1:5500/docs/_site/$ref/docs/index.html\","
13+
done < $INPUT
14+
IFS=$OLDIFS
15+
# echo '"Nightly": "https://dotty.epfl.ch/docs/index.html",'
16+
echo '"Nightly": "http://127.0.0.1:5500/docs/_site/docs/index.html"'
17+
echo '}}'
18+

project/scripts/genDocs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,75 @@ set -e
44
shopt -s extglob # needed for rm everything but x
55
echo "Working directory: $PWD"
66

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

12+
# Load the csv data into memory
13+
14+
INPUT=./project/scripts/docs/docs.csv
15+
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
16+
CSV_FILE=$(<"$INPUT")
17+
18+
1319
### Obtain the previous versions of the website ###
1420
if [ -d "$PREVIOUS_SNAPSHOTS_DIR" ]; then
1521
rm -rf "$PREVIOUS_SNAPSHOTS_DIR"
1622
fi
1723

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

25-
### Generate the current snapshot of the website ###
26-
# this command will generate docs in $PWD/docs/_site
30+
31+
### Gather tasty files for new scaladoc different versions
32+
2733
SBT="$SCRIPT_DIR/sbt"
34+
35+
# We iterate over csv to checkout for different versions and generate their jars respectively.
36+
37+
OLDIFS=$IFS
38+
IFS=','
39+
40+
OUTPUT_DIR="output" # output for cumulutative tasty files for previous versions for
41+
42+
43+
# Firstly iterate over each version and generato sources
44+
while read label ref
45+
do
46+
git checkout "$ref"
47+
"$SBT" "scaladoc/copyTheScaladocInputs $OUTPUT_DIR $ref"
48+
done <<< $CSV_FILE
49+
50+
git checkout "$GIT_HEAD"
51+
52+
# Let's start with generating latest docs for nightly
2853
"$SBT" "scaladoc/generateScalaDocumentation docs/_site"
2954

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

61+
# Iterate once again and generate scaladoc for additional older versions
62+
while read label ref
63+
do
64+
# Generate the website
65+
# this command will generate docs in $PWD/docs/_site/$ref
66+
"$SBT" "scaladoc/generateScalaDocumentation docs/_site/$ref $OUTPUT_DIR $ref"
67+
done <<< $CSV_FILE
68+
69+
IFS=$OLDIFS
70+
71+
# Generate json file
72+
73+
touch "docs/_site/versions.json"
74+
sh ./project/scripts/docs/docs.sh > "docs/_site/versions.json"
75+
3676
### Move previous versions' snapshots to _site ###
3777
mv -v "$PREVIOUS_SNAPSHOTS_DIR"/* "$SITE_OUT_DIR"
3878
rm -rf "$PREVIOUS_SNAPSHOTS_DIR"

0 commit comments

Comments
 (0)