Skip to content

Commit bbdbdf2

Browse files
authored
Merge pull request #10522 from romanowski/scala3doc/community-build
Scala3doc/community build
2 parents 5fd25e4 + 042d58d commit bbdbdf2

File tree

13 files changed

+281
-30
lines changed

13 files changed

+281
-30
lines changed

.github/workflows/scala3doc.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,36 @@ jobs:
6262
echo uplading docs to https://scala3doc.virtuslab.com/$DOC_DEST
6363
az storage container create --name $DOC_DEST --account-name scala3docstorage --public-access container
6464
az storage blob sync -s scala3doc/output -c $DOC_DEST --account-name scala3docstorage
65+
66+
community-docs:
67+
env:
68+
AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }}
69+
runs-on: ubuntu-latest
70+
if: "github.event_name == 'pull_request' || contains(github.event.ref, 'scala3doc') || contains(github.event.ref, 'master')"
71+
72+
steps:
73+
- name: Git Checkout
74+
uses: actions/checkout@v2
75+
76+
- name: Set up JDK 8
77+
uses: actions/setup-java@v1
78+
with:
79+
java-version: 8
80+
81+
- name: Init submodules
82+
run: git submodule update --init --recursive --jobs 7
83+
84+
- name: Generate docs
85+
run: ./project/scripts/sbt "community-build/run doc all docsOutput"
86+
87+
- name: Upload documentation to server
88+
uses: azure/CLI@v1
89+
if: env.AZURE_STORAGE_SAS_TOKEN
90+
env:
91+
PR_NUMBER: ${{ github.event.pull_request.number }}
92+
with:
93+
inlineScript: |
94+
DOC_DEST=pr-${PR_NUMBER:-${GITHUB_REF##*/}}-docs
95+
echo uplading docs to https://scala3doc.virtuslab.com/$DOC_DEST
96+
az storage container create --name $DOC_DEST --account-name scala3docstorage --public-access container
97+
az storage blob sync -s community-build/docsOutput -c $DOC_DEST --account-name scala3docstorage
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.communitybuild
2+
3+
import scala.quoted.Type
4+
5+
class FieldsDsl[V](v: V):
6+
inline def of[T]: Seq[T] = FieldsImpl.fieldsOfType[V, T](v)
7+
8+
extension [V](on: V):
9+
def fields = FieldsDsl(on)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dotty.communitybuild
2+
3+
import scala.quoted._
4+
5+
object FieldsImpl:
6+
inline def fieldsOfType[V, T](inline v: V): Seq[T] =
7+
${ fieldsImpl[V, T]('v) }
8+
9+
def fieldsImpl[V: Type, T: Type](from: Expr[V])(using Quotes): Expr[Seq[T]] =
10+
import quotes.reflect._
11+
val retType = TypeTree.of[T].tpe
12+
def isProjectField(s: Symbol) =
13+
s.isValDef && s.tree.asInstanceOf[ValDef].tpt.tpe <:< retType
14+
val projectsTree = Term.of(from)
15+
val symbols = TypeTree.of[V].symbol.members.filter(isProjectField)
16+
val selects = symbols.map(Select(projectsTree, _).asExprOf[T])
17+
'{ println(${Expr(retType.show)}); ${Varargs(selects)} }
Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,91 @@
11
package dotty.communitybuild
22

3-
object Main {
4-
/** Builds stdlib.
5-
*
6-
* Output is available in build/pack/lib directory in stdlib project.
7-
*
8-
* In the future, we allow building different projects based on arguments,
9-
* but for now stdlib is the only usecase.
10-
*/
3+
import java.nio.file.Paths
4+
import java.nio.file.Path
5+
import java.nio.file.Files
6+
import scala.sys.process._
7+
8+
9+
object Main:
10+
11+
private def generateDocs(project: CommunityProject): Seq[Path] =
12+
val name = project.project
13+
try
14+
project.doc()
15+
val pathsOut = s"find community-projects/$name/ -name 'scala3doc.version'".!!
16+
pathsOut.linesIterator.map(Paths.get(_).getParent).toList
17+
catch
18+
case e: Exception =>
19+
e.printStackTrace()
20+
Nil
21+
22+
/** Allows running various commands on community build projects. */
1123
def main(args: Array[String]): Unit =
12-
projects.stdLib213.publish()
13-
}
24+
args.toList match
25+
case "publish" :: name :: Nil =>
26+
case "doc" :: "all" :: destStr :: Nil =>
27+
val dest = Paths.get(destStr)
28+
Seq("rm", "-rf", "destStr").!
29+
Files.createDirectory(dest)
30+
val (toRun, ignored) =
31+
allProjects.partition(_.docCommand != null)
32+
33+
val paths = toRun.map { project =>
34+
val name = project.project
35+
val projectDest = dest.resolve(name)
36+
val projectRoot = Paths.get(s"community-projects/$name")
37+
println(s"generating docs for $name into $projectDest")
38+
val generatedDocs = generateDocs(project)
39+
if !Files.exists(projectDest) && generatedDocs.nonEmpty then
40+
Files.createDirectory(projectDest)
41+
42+
val docsFiles = generatedDocs.map { docsPath =>
43+
val destFileName =
44+
docsPath.subpath(2, docsPath.getNameCount).toString.replace('/', '_')
45+
46+
Seq("cp", "-r", docsPath.toString, projectDest.resolve(destFileName).toString).!
47+
destFileName
48+
}
49+
name -> docsFiles
50+
}
51+
52+
val (failed, withDocs) = paths.partition{ case (_, paths) => paths.isEmpty }
53+
54+
val indexFile = withDocs.map { case (name, paths) =>
55+
paths.map(p => s"""<a href="$name/$p/index.html">$p</a></br>\n""")
56+
.mkString(s"<h1>$name</h1>","\n", "\n")
57+
}.mkString("<html><body>\n", "\n", "\n</html></body>")
58+
59+
Files.write(dest.resolve("index.html"), indexFile.getBytes)
60+
61+
if ignored.nonEmpty then
62+
println(s"Ignored project without doc command: ${ignored.map(_.project)}")
63+
64+
if failed.nonEmpty then
65+
println(s"Documentation not found for ${failed.map(_._1).mkString(", ")}")
66+
sys.exit(1)
67+
68+
case "doc" :: names if names.nonEmpty =>
69+
val missing = names.filterNot(projectMap.contains)
70+
if missing.nonEmpty then
71+
println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}")
72+
sys.exit(1)
73+
74+
val failed = names.filter{ p =>
75+
val docsRoots = generateDocs(projectMap(p))
76+
if docsRoots.nonEmpty then println(s"Docs for $p generated in $docsRoots")
77+
docsRoots.isEmpty
78+
}
79+
if failed.nonEmpty then
80+
println(s"Documentation not found for ${failed.mkString(", ")}")
81+
sys.exit(1)
82+
83+
case args =>
84+
println("USAGE: <COMMAND> <PROJECT NAME>")
85+
println("COMMAND is one of: publish doc")
86+
println("Available projects are:")
87+
allProjects.foreach { k =>
88+
println(s"\t$k")
89+
}
90+
sys.exit(1)
91+

0 commit comments

Comments
 (0)