-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update developer docs build config (#3493)
* update developer docs build config - specify requirements.txt - update site: add dark/light mode toggle - use `com.pswidersk.python-plugin` (it's more compatible with Configuration Cache) - define tasks for installing & building mkdocs - log link to site using IntelliJ built-in server * remove config-cache props * refine mkdocs tasks, update task inputs, always log link (either using IJ or a plain file link) * update task in GitHub Action * add note to site_dir * bump mkdocs-material version (prevents warning about `A plugin has set File.page to an instance of Page and it got overwritten`) * update mkdocs site structure: - generate the site into `$dokkaVersion/` subdir - on non-SNAPSHOT versions generate a redirecting index.html * update GHA with new MkDocs task name * filter index.html in buildMkDocsSite task inputs * fix Dokka version in logged link * de-duplicate Gradle Configuration utils
- Loading branch information
Showing
24 changed files
with
243 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
build-logic/src/main/kotlin/dokkabuild/internal/gradleUtils.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,179 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import com.pswidersk.gradle.python.VenvTask | ||
import org.apache.tools.ant.filters.ReplaceTokens | ||
import org.gradle.api.tasks.PathSensitivity.RELATIVE | ||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs | ||
|
||
plugins { | ||
id("ru.vyarus.mkdocs") version "2.4.0" | ||
id("com.pswidersk.python-plugin") version "2.4.0" | ||
} | ||
|
||
if (project.version.toString().endsWith("-SNAPSHOT")) { | ||
// Do not generate the root index.html file with the redirect | ||
// to a snapshot version, otherwise GitHub Pages-based documentation | ||
// will always lead to the non-yet-released documentation. | ||
// For more details, see https://github.com/Kotlin/dokka/issues/2869. | ||
// For configuration details, see https://xvik.github.io/gradle-mkdocs-plugin/3.0.0/examples/#simple-multi-version. | ||
mkdocs.publish.rootRedirect = false | ||
val dokkaVersion = provider { project.version.toString() } | ||
val isDokkaSnapshotVersion = dokkaVersion.map { it.endsWith("-SNAPSHOT") } | ||
|
||
/** Directory containing generated docs. */ | ||
val currentMkDocsDir: Provider<Directory> = layout.buildDirectory.dir("mkdocs-current") | ||
|
||
/** | ||
* Directory containing a fully built MkDocs site, ready for upload to GitHub Pages. | ||
* | ||
* The [currentMkDocsDir] must be placed in a [dokkaVersion] subdirectory. | ||
* | ||
* ```. | ||
* └── build/ | ||
* └── mkdocs/ | ||
* └── 1.2.3-SNAPSHOT/ | ||
* └── <content> | ||
* ``` | ||
* | ||
* If [dokkaVersion] is a release version (non-SNAPSHOT) then the dir must contain an index.html | ||
* that redirects to the current version. | ||
* | ||
* ``` | ||
* └── build/ | ||
* ├── mkdocs/ | ||
* │ └── 1.2.3/ | ||
* │ └── <content> | ||
* └── index.html (redirects to `1.2.3/index.html`) | ||
* ``` | ||
*/ | ||
val mkDocsSiteDir: Provider<Directory> = layout.buildDirectory.dir("mkdocs") | ||
|
||
val mkDocsSetup: TaskProvider<VenvTask> by tasks.registering(VenvTask::class) { | ||
description = "Install required Python libraries" | ||
group = project.name | ||
venvExec = "pip" | ||
args = parseSpaceSeparatedArgs("install -r requirements.txt") | ||
|
||
inputs.file("requirements.txt") | ||
.withPropertyName("requirements.txt") | ||
.withPathSensitivity(RELATIVE) | ||
.normalizeLineEndings() | ||
} | ||
|
||
val pipPrintRequirements by tasks.registering(VenvTask::class) { | ||
description = "Log the current requirements (useful util for manually updating dependencies & requirements.txt)" | ||
group = project.name | ||
venvExec = "pip" | ||
args = parseSpaceSeparatedArgs("freeze") | ||
} | ||
|
||
val mkDocsBuild: TaskProvider<VenvTask> by tasks.registering(VenvTask::class) { | ||
description = "Compile Dokka Developer Documentation site using MkDocs" | ||
group = project.name | ||
|
||
dependsOn(mkDocsSetup) | ||
finalizedBy(logMkDocsLink) | ||
|
||
venvExec = "mkdocs" | ||
args = parseSpaceSeparatedArgs("build") | ||
|
||
inputs.dir("docs") | ||
.withPropertyName("docs") | ||
.withPathSensitivity(RELATIVE) | ||
.normalizeLineEndings() | ||
|
||
inputs.file("mkdocs.yml") | ||
.withPropertyName("mkdocs.yml") | ||
.withPathSensitivity(RELATIVE) | ||
.normalizeLineEndings() | ||
|
||
// output directory is also specified in mkdocs.yml as `site_dir` | ||
outputs.dir(currentMkDocsDir) | ||
.withPropertyName("mkDocsOutputDir") | ||
|
||
outputs.cacheIf("always cache - task has defined output directory") { true } | ||
} | ||
|
||
val generateMkDocsSiteIndexHtml by tasks.registering(Sync::class) { | ||
description = "Generate the root index.html" | ||
group = project.name | ||
|
||
val dokkaVersion = dokkaVersion | ||
inputs.property("dokkaVersion", dokkaVersion) | ||
|
||
val indexHtml = layout.projectDirectory.file("index.html") | ||
inputs.file(indexHtml) | ||
.withPropertyName("indexHtml") | ||
.withPathSensitivity(RELATIVE) | ||
.normalizeLineEndings() | ||
|
||
from(indexHtml) | ||
|
||
filter<ReplaceTokens>("tokens" to mapOf("dokkaVersion" to dokkaVersion.get())) | ||
|
||
into(temporaryDir) | ||
} | ||
|
||
|
||
val buildMkDocsSite by tasks.registering(Sync::class) { | ||
description = "Generate a complete MkDocs site, with versioned subdirectories" | ||
group = project.name | ||
|
||
val dokkaVersion = dokkaVersion | ||
inputs.property("dokkaVersion", dokkaVersion) | ||
|
||
// only generate a root index.html on non-snapshot versions | ||
if (!isDokkaSnapshotVersion.get()) { | ||
from(generateMkDocsSiteIndexHtml) | ||
} | ||
from(mkDocsBuild) { | ||
eachFile { | ||
relativePath = relativePath.prepend(dokkaVersion.get()) | ||
} | ||
} | ||
|
||
includeEmptyDirs = false | ||
|
||
into(mkDocsSiteDir) | ||
} | ||
|
||
val logMkDocsLink: TaskProvider<Task> by tasks.registering { | ||
description = "Prints a link to the generated docs" | ||
group = project.name | ||
|
||
dependsOn(buildMkDocsSite) | ||
doNotTrackState("this task performs no work and should always log the link") | ||
|
||
// redefine currentMkDocsDir for config-cache compliance | ||
val mkDocsDir = buildMkDocsSite.map { it.destinationDir } | ||
|
||
val ideaActive = System.getProperty("idea.active").toBoolean() | ||
|
||
val dokkaProjectDir = project.rootDir.parentFile | ||
|
||
val dokkaVersion = dokkaVersion | ||
val isDokkaSnapshotVersion = isDokkaSnapshotVersion | ||
|
||
doLast { | ||
val indexHtml = if (isDokkaSnapshotVersion.get()) { | ||
mkDocsDir.get().resolve("${dokkaVersion.get()}/index.html") | ||
} else { | ||
mkDocsDir.get().resolve("index.html") | ||
} | ||
|
||
val link: String = | ||
if (ideaActive) { | ||
// The built-in IntelliJ server requires a specific path to index.html: | ||
// a _relative_ path starting with the project's directory (dokka) | ||
val relativeOutputPath = indexHtml.relativeTo(dokkaProjectDir).invariantSeparatorsPath | ||
"http://localhost:63342/$relativeOutputPath" | ||
} else { | ||
indexHtml.toURI().toString() | ||
} | ||
|
||
logger.quiet( | ||
""" | ||
| | ||
|*************************************************************************************************** | ||
| | ||
| Dokka Developer Docs: $link | ||
| | ||
|*************************************************************************************************** | ||
| | ||
""".trimMargin() | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | ||
<head> | ||
<meta http-equiv="refresh" content="0; url='./@dokkaVersion@/'"/> | ||
<title>Dokka Developer Docs</title> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Babel==2.14.0 | ||
certifi==2024.2.2 | ||
charset-normalizer==3.3.2 | ||
click==8.1.7 | ||
colorama==0.4.6 | ||
ghp-import==2.1.0 | ||
idna==3.6 | ||
Jinja2==3.1.3 | ||
Markdown==3.5.2 | ||
MarkupSafe==2.1.5 | ||
mergedeep==1.3.4 | ||
mkdocs==1.5.3 | ||
mkdocs-material==9.5.10 | ||
mkdocs-material-extensions==1.3.1 | ||
packaging==23.2 | ||
paginate==0.5.6 | ||
pathspec==0.12.1 | ||
platformdirs==4.2.0 | ||
Pygments==2.17.2 | ||
pymdown-extensions==10.7 | ||
python-dateutil==2.8.2 | ||
PyYAML==6.0.1 | ||
pyyaml_env_tag==0.1 | ||
regex==2023.12.25 | ||
requests==2.31.0 | ||
six==1.16.0 | ||
urllib3==2.2.0 | ||
watchdog==4.0.0 |