Skip to content

Commit

Permalink
Dokka (mamoe#1708)
Browse files Browse the repository at this point in the history
* dokka

* test

* Fix classpath

* Fix deploy

* Fix deploy

* Fix deploy

* GitHub workflows
  • Loading branch information
Karlatemp authored Dec 4, 2021
1 parent ad1ee9a commit d10d203
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 84 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ jobs:
./gradlew check --scan
-Dmirai.network.show.all.components=true
-Dkotlinx.coroutines.debug=on
-Dmirai.network.show.packet.details=true
-Dmirai.network.show.packet.details=true
- name: Ensure KDoc valid
run: ./gradlew dokkaHtmlMultiModule
70 changes: 19 additions & 51 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
# This is a basic workflow to help you get started with Actions

name: mirai-doc Publish

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
release:
types:
- created

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
mirai-core-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
push:
tags:
- 'v*' # 正式版本

- name: chmod -R 777 *
run: chmod -R 777 *
- name: Gradle build
run: ./gradlew clean build # if test's failed, don't publish
- name: Dokka
run: ./gradlew :mirai-core-api:dokkaHtml
- name: GitHub Pages Deploy
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.MAMOE_TOKEN }}
publish_dir: ./mirai-core-api/build/dokka
external_repository: project-mirai/mirai-doc
publish_branch: master
user_name: 'mamoebot'
user_email: '[email protected]'
keep_files: true

# This workflow contains a single job called "build"
mirai-console-docs:
jobs:
mirai-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

- name: Checkout submodules
run: git submodule update --init --recursive
Expand All @@ -54,18 +23,17 @@ jobs:

- name: chmod -R 777 *
run: chmod -R 777 *
- name: Gradle build
run: ./gradlew clean build # if test's failed, don't publish

- name: Prepare environment
run: ./gradlew :mirai-dokka:prepare

- name: Dokka
run: ./gradlew :mirai-console:dokkaHtml
- name: GitHub Pages Deploy
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.MAMOE_TOKEN }}
publish_dir: ./mirai-console/build/dokka
external_repository: project-mirai/mirai-doc
publish_branch: master
user_name: 'mamoebot'
user_email: '[email protected]'
keep_files: true
run: ./gradlew dokkaHtmlMultiModule

- name: Update version number
run: ./gradlew :mirai-dokka:update-vers

- name: Deploy
run: ./gradlew :mirai-dokka:deployPages
env:
gh_token: ${{ secrets.MAMOE_TOKEN }}
85 changes: 55 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import java.time.LocalDateTime

buildscript {
repositories {
Expand All @@ -28,12 +31,14 @@ buildscript {
classpath("com.android.tools.build:gradle:${Versions.androidGradlePlugin}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicFU}")
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.binaryValidator}")
classpath("org.jetbrains.dokka:dokka-base:${Versions.dokka}")
}
}

plugins {
kotlin("jvm") // version Versions.kotlinCompiler
kotlin("plugin.serialization") version Versions.kotlinCompiler
id("org.jetbrains.dokka") version Versions.dokka
// id("org.jetbrains.dokka") version Versions.dokka
id("net.mamoe.kotlin-jvm-blocking-bridge") version Versions.blockingBridge
id("com.gradle.plugin-publish") version "0.12.0" apply false
Expand Down Expand Up @@ -114,6 +119,7 @@ subprojects {
if (project.name == "mirai-console") configureDokka()
}
}
rootProject.configureDokka()

tasks.register("cleanExceptIntellij") {
group = "build"
Expand All @@ -140,36 +146,55 @@ fun Project.useIr() {
}

fun Project.configureDokka() {
// apply(plugin = "org.jetbrains.dokka")
// tasks {
// val dokkaHtml by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
// outputDirectory.set(buildDir.resolve("dokka"))
// }
// val dokkaGfm by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
// outputDirectory.set(buildDir.resolve("dokka-gfm"))
// }
// }
// tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
// dokkaSourceSets.configureEach {
// perPackageOption {
// matchingRegex.set("net\\.mamoe\\.mirai\\.*")
// skipDeprecated.set(true)
// }
//
// for (suppressedPackage in arrayOf(
// """net.mamoe.mirai.internal""",
// """net.mamoe.mirai.internal.message""",
// """net.mamoe.mirai.internal.network""",
// """net.mamoe.mirai.console.internal""",
// """net.mamoe.mirai.console.compiler.common"""
// )) {
// perPackageOption {
// matchingRegex.set(suppressedPackage.replace(".", "\\."))
// suppress.set(true)
// }
// }
// }
// }
val isRoot = this@configureDokka == rootProject
if (!isRoot) {
apply(plugin = "org.jetbrains.dokka")
}

tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
this.footerMessage = """Copyright 2019-${
LocalDateTime.now().year
} <a href="https://github.com/mamoe">Mamoe Technologies</a> and contributors.
Source code:
<a href="https://github.com/mamoe/mirai">GitHub</a>
""".trimIndent()

this.customAssets = listOf(
rootProject.projectDir.resolve("mirai-dokka/frontend/ext.js"),
)
}
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
perPackageOption {
matchingRegex.set("net\\.mamoe\\.mirai\\.*")
skipDeprecated.set(true)
}

for (suppressedPackage in arrayOf(
"""net.mamoe.mirai.internal""",
"""net.mamoe.mirai.internal.message""",
"""net.mamoe.mirai.internal.network""",
"""net.mamoe.mirai.console.internal""",
"""net.mamoe.mirai.console.compiler.common"""
)) {
perPackageOption {
matchingRegex.set(suppressedPackage.replace(".", "\\."))
suppress.set(true)
}
}
}
}

if (isRoot) {
tasks.named<org.jetbrains.dokka.gradle.AbstractDokkaTask>("dokkaHtmlMultiModule").configure {
outputDirectory.set(
rootProject.projectDir.resolve("mirai-dokka/pages/snapshot")
)
}
}
}

fun Project.configureMppShadow() {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Versions {

const val kotlinCompiler = "1.5.30"
const val kotlinStdlib = "1.5.30"
const val dokka = "1.4.32"
const val dokka = "1.6.0"

const val coroutines = "1.5.1"
const val atomicFU = "0.16.3"
Expand Down
1 change: 0 additions & 1 deletion mirai-core-api/src/commonMain/kotlin/contact/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import net.mamoe.mirai.utils.NotStableForInheritance
*
* 可通过 [Group.announcements] 获取公告支持. 可在 [Announcements] 查看详细文档.
*
* ##
*/
@NotStableForInheritance
public interface Group : Contact, CoroutineScope, FileSupported, AudioSupported {
Expand Down
1 change: 1 addition & 0 deletions mirai-dokka/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/pages
41 changes: 41 additions & 0 deletions mirai-dokka/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("java")
`maven-publish`
}

dependencies {
implementation(`kotlinx-serialization-core-jvm`)
implementation(`kotlinx-serialization-json-jvm`)
}

fun Project.newExec(name: String, type: String, conf: JavaExec.() -> Unit) {
tasks.create(name, JavaExec::class.java) {
this.classpath = sourceSets["main"].runtimeClasspath
this.mainClass.set("net.mamoe.mirai.dokka.${type}Kt")
this.workingDir(rootProject.projectDir)
this.environment("mirai_ver", rootProject.version.toString())
conf()
}
}

newExec("prepare", "Prepare") {
}

newExec("deployPages", "DeployToGitHub") {
}

newExec("update-vers", "BuildVersionList") {
}


37 changes: 37 additions & 0 deletions mirai-dokka/frontend/ext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// noinspection ES6ConvertVarToLetConst,JSUnresolvedVariable

/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/



(function () {
fetch(window.pathToRoot + "../versions.json").then(function (it) {
return it.json()
}).then(function (rsp) {
console.log(rsp);
var dir = document.getElementById("searchBar").parentElement;
var select = document.createElement("select");
dir.insertBefore(select, dir.firstElementChild);
select.appendChild(document.createElement("option")).textContent = "other version";
var toLatest = select.appendChild(document.createElement("option"));
toLatest.textContent = "latest";
toLatest.value = "";
for (var v of rsp) {
var c = select.appendChild(document.createElement("option"));
c.textContent = v;
c.value = v;
}
select.addEventListener("change", function (event) {
location.href = window.pathToRoot + "../" + c.value
})
}).catch(function (error) {
console.log(error);
})
})()
28 changes: 28 additions & 0 deletions mirai-dokka/src/BuildVersionList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

package net.mamoe.mirai.dokka

import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer


fun main() {
val currentVersion = System.getenv("mirai_ver") ?: error("version not found")

val versions = pages.resolve("versions.json")

json.decodeFromString(ListSerializer(String.serializer()), versions.readText()).toMutableList().let { list ->
if (currentVersion in list) return@let
list.add(currentVersion)
versions.writeText(json.encodeToString(ListSerializer(String.serializer()), list))
}

pages.resolve("snapshot").renameTo(pages.resolve(currentVersion))
}
33 changes: 33 additions & 0 deletions mirai-dokka/src/DeployToGitHub.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

package net.mamoe.mirai.dokka

fun main() {
val token = System.getenv("gh_token") ?: error("Token not found")
val currentVersion = System.getenv("mirai_ver") ?: error("version not found")

repoexec("git", "config", "--local", "http.https://github.com/.extraheader", "")
runCatching {
repoexec("git", "remote", "remove", "token")
}
repoexec(
"git", "remote", "add", "token",
"https://x-access-token:$token@github.com/project-mirai/mirai-doc.git"
)

repoexec("git", "config", "--local", "user.email", "[email protected]")
repoexec("git", "config", "--local", "user.name", "mamoebot")
repoexec("git", "add", "-A")
repoexec(
"git", "commit", "-m", currentVersion,
nooutput = true,
)
repoexec("git", "push", "token", "HEAD:master")
}
17 changes: 17 additions & 0 deletions mirai-dokka/src/Prepare.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

package net.mamoe.mirai.dokka

fun main() {
if (pages.resolve(".git").isDirectory) {
return
}
exec("git", "clone", "https://github.com/project-mirai/mirai-doc.git", pages.absolutePath)
}
Loading

0 comments on commit d10d203

Please sign in to comment.