Skip to content

Add Changelog.md to Docs #358

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

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
with:
fetch-depth: 0

- name: Create stub changelog.md file
run: echo "# Changelog" > docs/pages/kotlinx-rpc/topics/changelog.md

- name: Build docs using Writerside Docker builder
uses: JetBrains/writerside-github-action@v4
with:
Expand Down Expand Up @@ -99,6 +102,13 @@ jobs:
- name: Update sitemap.xml
run: chmod +x updateSitemap.sh && ./updateSitemap.sh __docs_publication_dir/sitemap.xml __docs_publication_dir/api

- name: Run Changelog Generator
run: ./gradlew updateDocsChangelog

- name: Move Changelog.md to the publication directory
run:
mv docs/pages/kotlinx-rpc/topics/changelog.md __docs_publication_dir/changelog.md

- name: Setup Pages
uses: actions/configure-pages@v5

Expand Down
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
This release enforces ERROR as a default reporting level for APIs that are forbidden by the strict mode.
You can still change the level manually, but in `0.8.0` strict mode will be enforced irreversibly.

## What's Changed

### Breaking Changes 🔴
* Change strict mode to level ERROR by default by @Mr3zee in https://github.com/Kotlin/kotlinx-rpc/pull/338

Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import util.configureApiValidation
import util.configureNpm
import util.configureProjectReport
import util.registerDumpPlatformTableTask
import util.registerChangelogTask
import util.libs
import util.registerVerifyPlatformTableTask
import java.time.Year
Expand Down Expand Up @@ -83,6 +84,7 @@ configureApiValidation()

registerDumpPlatformTableTask()
registerVerifyPlatformTableTask()
registerChangelogTask()

val kotlinVersion = rootProject.libs.versions.kotlin.lang.get()
val kotlinCompiler = rootProject.libs.versions.kotlin.compiler.get()
Expand Down
1 change: 1 addition & 0 deletions docs/pages/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
api/**
kotlinx-rpc/topics/changelog.md
1 change: 1 addition & 0 deletions docs/pages/kotlinx-rpc/rpc.tree
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
<toc-element topic="0-2-4.topic"/>
<toc-element topic="0-2-1.topic"/>
</toc-element>
<toc-element topic="changelog.md"/>
<toc-element toc-title="API Reference" href="%host%/api/"/>
</instance-profile>
131 changes: 131 additions & 0 deletions gradle-conventions/common/src/main/kotlin/util/changelog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util

import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.register
import java.io.File
import kotlin.io.path.createDirectories
import kotlin.io.path.createFile
import kotlin.io.path.exists
import kotlin.io.path.readLines
import kotlin.io.path.writeLines

private val ROOT_CHANGELOG_PATH = File("CHANGELOG.md")
private val DOCS_CHANGELOG_PATH = File("docs/pages/kotlinx-rpc/topics/changelog.md")

private val PULL_REGEX = "https://github.com/Kotlin/kotlinx-rpc/pull/(\\d+)".toRegex()
private val COMPARE_REGEX = "https://github.com/Kotlin/kotlinx-rpc/compare/([+.\\w_-]+)".toRegex()
private val USERNAME_REGEX = "@([\\w_-]+)".toRegex()
private val WHITESPACE = "\\s+".toRegex()

abstract class UpdateDocsChangelog : DefaultTask() {
@get:InputFile
abstract val input: Property<File>

@get:OutputFile
abstract val output: Property<File>

@TaskAction
fun update() {
val inputPath = input.get().toPath()
val outputPath = output.get().toPath()

if (!inputPath.exists()) {
throw GradleException("fatal error: input file $inputPath does not exist")
}

var currentRelease = ""
val fullChangelogLines = mutableListOf<String>()
val lines = inputPath.readLines(Charsets.UTF_8).flatMap { line ->
val updated = line
.replace(PULL_REGEX) {
"[#${it.groupValues[1]}](${it.groupValues[0]})"
}
.replace(COMPARE_REGEX) {
"[${it.groupValues[1]}](${it.groupValues[0]})"
}
.replace(USERNAME_REGEX) {
"[${it.groupValues[0]}](https://github.com/${it.groupValues[1]})"
}.let {
if (it.startsWith("#")) {
"#$it"
} else {
it
}
}

if (updated.startsWith("## ")) {
currentRelease = updated
.drop(3)
.replace(".", "_")
}

when {
updated.startsWith("###") -> {
val name = updated
.dropWhile { it == '#' }
.dropLastWhile { !it.isDigit() && !it.isLetter() }
.trim()
.replace(WHITESPACE, "_")

listOf("$updated {id=${name}_$currentRelease}")
}

updated.startsWith("**Full Changelog**:") -> {
fullChangelogLines.add(updated)
emptyList()
}

else -> listOf(updated)
}
}

val result = mutableListOf<String>()

var i = 0
var fci = 0
while (i < lines.size) {
val line = lines[i]
result.add(line)

if (line.startsWith("## ")) {
result.add(lines[i + 1])
result.add("")
result.add(fullChangelogLines[fci++])
i++
}

i++
}

if (!outputPath.exists()) {
outputPath.parent.createDirectories()
outputPath.createFile()
}

val header = listOf(
"# Changelog",
"",
"This page contains all changes throughout releases of the library.",
"",
)

outputPath.writeLines(header + result)
}
}

fun Project.registerChangelogTask() {
tasks.register<UpdateDocsChangelog>("updateDocsChangelog") {
input.set(ROOT_CHANGELOG_PATH)
output.set(DOCS_CHANGELOG_PATH)
}
}
Loading