Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of gh-pages branch #815

Closed
wants to merge 10 commits into from
Closed
77 changes: 57 additions & 20 deletions .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
# This workflow will build and deploy docs to GitHub Pages whenever something is pushed to the default branch
name: Build docs

name: Docs

on: push # but only to default branch, see if below
on:
push:
release:
types:
- published
workflow_dispatch:
DRSchlaubi marked this conversation as resolved.
Show resolved Hide resolved

# Gives the workflow permissions to clone the repo and create a page deployment
permissions:
contents: write
id-token: write
pages: write

jobs:
docs:
name: Build and deploy docs
runs-on: ubuntu-latest
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
concurrency: # Allow one concurrent deployment
# Allow one concurrent deployment
concurrency:
group: pages
cancel-in-progress: true

# This workflow updates the versioned docs on dokka.kord.dev using the following strategy
# 1) pull cache to docs-cache
# 2) Call dokkaHtmlMultiModule for current version
# - if this is a release build move current docs into docs-cache/$version
# - otherwise move it into docs-cache/current
# 3) Build GitHub Pages artifact
# - Move all folders not named "current" into docs/<folder>
# - Move current into docs/
Comment on lines +22 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't get where this is done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the produceDocs tasks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it custom? cause if so, you didn't commit it

# 4) Trigger a deployment to GitHub Actions
jobs:
build-job:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
env:
GITHUB_TAG_NAME: ${{ github.event.release.tag_name }}
GITHUB_BRANCH_NAME: ${{ github.ref }}
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout cache
with:
ref: 'docs-cache'
path: 'docs-cache'
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
Expand All @@ -28,12 +52,25 @@ jobs:
- name: Build docs with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: --stacktrace --info dokkaHtmlMultiModule
- name: Deploy docs to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
arguments: :produceDocs
DRSchlaubi marked this conversation as resolved.
Show resolved Hide resolved
- name: Commit files
working-directory: docs-cache
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "Add changes"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: docs-cache
directory: docs-cache
- name: Setup Pages
uses: actions/configure-pages@v2
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
folder: build/dokka/htmlMultiModule
branch: gh-pages
git-config-name: GitHub Actions
git-config-email: [email protected]
commit-message: Update docs
path: docs
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
.idea/
out/

# Versioned docs structure
docs/
old-docs/

**/build/*
!**/build/generated/
# re-exclude BuildConfigGenerated.kt
Expand Down
43 changes: 43 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,46 @@ repositories {

group = Library.group
version = Library.version

dependencies {
dokkaHtmlMultiModulePlugin(libs.dokka.versioning.plugin)
}

tasks {
val oldDocsRoot = "docs-cache"
dokkaHtmlMultiModule {
applyVersioningPlugin()
}

val saveDocs = task<Copy>("saveVersionedDocs") {
fromDokkaMutliModule()
if (Library.isSnapshot) {
into("$oldDocsRoot/current")
} else {
into("$oldDocsRoot/${Library.version}")
}
}

task<Copy>("produceDocs") {
dependsOn(saveDocs)
// copy old versions
from(oldDocsRoot) {
exclude("current")
}
// copy up to date version
fromDokkaMutliModule {
if (Library.isRelease) {
into(Library.version)
}
}
into("docs")
}
}

// For some reason from(dokkaHtmlMultiModule) produces some really weird output
inline fun Copy.fromDokkaMutliModule(crossinline configure: CopySpec.() -> Unit = {}) {
from("$buildDir/dokka/htmlMultiModule") {
configure()
}
dependsOn(tasks.dokkaHtmlMultiModule)
}
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ repositories {

dependencies {
implementation(libs.bundles.pluginsForBuildSrc)
implementation(libs.dokka.versioning.plugin)
}
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import kotlinx.atomicfu.plugin.gradle.AtomicFUPluginExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
Expand Down Expand Up @@ -41,7 +42,9 @@ fun KotlinSourceSet.applyKordOptIns() {
fun Project.configureAtomicFU() {
// https://github.com/Kotlin/kotlinx-atomicfu/issues/210
configure<AtomicFUPluginExtension> {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependenciesVersion = libs.findVersion("kotlinx-atomicfu").get().requiredVersion
}
}

internal val Project.libs: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
23 changes: 19 additions & 4 deletions buildSrc/src/main/kotlin/Documentation.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import org.gradle.api.Project
import org.gradle.kotlin.dsl.assign
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.dokka.versioning.VersioningConfiguration
import org.jetbrains.dokka.versioning.VersioningPlugin
import java.io.FileFilter
import java.net.URL

fun AbstractDokkaLeafTask.applyKordDokkaOptions() {

moduleName = "kord-${project.name}"

failOnWarning = true

dokkaSourceSets.configureEach {

jdkVersion = Jvm.target

suppressGeneratedFiles = false

sourceLink {
localDirectory = project.projectDir
remoteUrl = URL("https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.9.x")}/${project.name}")
remoteUrl =
URL("https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.9.x")}/${project.name}")
remoteLineSuffix = "#L"
}

Expand All @@ -34,4 +37,16 @@ fun AbstractDokkaLeafTask.applyKordDokkaOptions() {
suppress = true
}
}
applyVersioningPlugin()
}

fun AbstractDokkaTask.applyVersioningPlugin() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go into the root build.gradle.kts, see the example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to apply this configuration for the root project and the sub projects so putting it just in the root project makes no sense

pluginConfiguration<VersioningPlugin, VersioningConfiguration> {
olderVersions = project.rootProject
.file("docs-cache").listFiles(FileFilter { it.isDirectory })?.toList() ?: emptyList()
renderVersionsNavigationOnAllPages = true
}
}

val Project.dokkaVersioningPlugin
get() = project.libs.findLibrary("dokka-versioning-plugin").get()
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repositories {

dependencies {
ksp(project(":ksp-processors"))
"dokkaHtmlPartialPlugin"(dokkaVersioningPlugin)
}

apiValidation {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.dokka.gradle.DokkaTask
DRSchlaubi marked this conversation as resolved.
Show resolved Hide resolved
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest

plugins {
Expand All @@ -16,6 +17,7 @@ repositories {

dependencies {
kspCommonMainMetadata(project(":ksp-processors"))
"dokkaHtmlPartialPlugin"(dokkaVersioningPlugin)
}

apiValidation {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
kotlinx-nodejs = { module = "org.jetbrains.kotlin-wrappers:kotlin-node", version.ref = "kotlinx-nodejs" }
dokka-versioning-plugin = { module = "org.jetbrains.dokka:versioning-plugin", version.ref = "dokka" }

# other
kotlin-logging = { module = "io.github.microutils:kotlin-logging", version.ref = "kotlin-logging" }
Expand Down