Skip to content

Commit

Permalink
Add dokka gh-pages docs task
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Jul 14, 2020
1 parent 21100f0 commit 8c18d35
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will upload docs to the gh-pages branch whenever something is pushed to master.

name: Docs
on:
push:
branches:
- master

jobs:
upload_docs:
name: upload docs
runs-on: ubuntu-latest
env:
GRGIT_USER: ${{ secrets.GRGIT_USER }}

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.14
uses: actions/setup-java@v1
with:
java-version: 1.14

- name: Publish docs with Gradle
run: gradle --stacktrace --info gitPublishPush
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea/
build/
out/
dokka/
47 changes: 46 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.jfrog.bintray.gradle.BintrayExtension
import com.jfrog.bintray.gradle.BintrayPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import org.ajoberstar.gradle.git.publish.GitPublishExtension
import org.ajoberstar.gradle.git.publish.tasks.GitPublishPush

buildscript {
repositories {
Expand All @@ -15,14 +18,21 @@ buildscript {

plugins {
id("org.jetbrains.kotlin.jvm") version Versions.kotlin
id("org.jetbrains.dokka") version "1.4.0-M3-dev-61"
id("org.ajoberstar.git-publish") version "2.1.3"
}

repositories {
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev/")
mavenCentral()
jcenter()
mavenLocal()
}

dependencies { api(Dependencies.jdk8) }
dependencies {
api(Dependencies.jdk8)
dokkaPlugins("org.jetbrains.dokka:dokka-base:0.11.0-SNAPSHOT")
}

group = Library.group
version = Library.version
Expand All @@ -39,6 +49,7 @@ subprojects {
jcenter()
maven(url = "https://kotlin.bintray.com/kotlinx")
maven(url = "https://dl.bintray.com/kordlib/Kord")
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev/")
}

dependencies {
Expand Down Expand Up @@ -109,3 +120,37 @@ subprojects {
}
}

tasks {
val dokkaOutputDir = "dokka"

val clean = getByName("clean", Delete::class) {
delete(rootProject.buildDir)
delete(dokkaOutputDir)
}

val dokka by getting(DokkaTask::class) {
dependsOn(clean)
outputDirectory = dokkaOutputDir
outputFormat = "html"
subProjects = listOf("core", "rest", "gateway", "common")
}

val fixIndex by register<DocsTask>("fixIndex") {
dependsOn(dokka)
}

val gitPublishPush by getting(GitPublishPush::class) {
dependsOn(fixIndex)
}
}

configure<GitPublishExtension> {
repoUri.set("https://github.com/kordlib/kord.git")
branch.set("gh-pages")

contents {
from("dokka")
}

commitMessage.set("Update Docs")
}
39 changes: 39 additions & 0 deletions buildSrc/src/main/kotlin/Publishing.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardOpenOption

open class DocsTask : DefaultTask() {

@TaskAction
fun publish() {
val dokkaRoot = Paths.get(project.projectDir.absolutePath, "dokka")

val index = Paths.get(dokkaRoot.toAbsolutePath().toString(), "kord", "index.html")
val newIndex = Paths.get(dokkaRoot.toAbsolutePath().toString(), "index.html")

//We're technically not moving the index.html. Instead, a working copy will be brought over to the root directory.
//This is a bit of a MacGyver move, but it's the easiest solution I could think of.
Files.createFile(newIndex)

var reachedPackages = false
//the default index.html is nested inside a folder, we'll move all links up by one directory to fix this in the
//root index.html copy.
Files.lines(index).map { it.replace("""../""", "") }.forEach {
var line = it
if ( it.contains("packages", true)) {
reachedPackages = true
}

if (reachedPackages){
//once we reach the packages declaration, we'll have to do a similar thing as above
//we'll move all package links down into the kord directory.
line = line.replace("""href="""", """href="kord/""")
}

Files.write(newIndex, (line + "\n").toByteArray(Charsets.UTF_8), StandardOpenOption.APPEND)
}
}

}
15 changes: 15 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.jetbrains.dokka") {
useModule("org.jetbrains.dokka:dokka-gradle-plugin:${requested.version}")
}
}
}
repositories {
mavenLocal()
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev")
gradlePluginPortal()
}
}

rootProject.name = "kord"
include("gateway")
include("common")
Expand Down

0 comments on commit 8c18d35

Please sign in to comment.