Skip to content

Commit 2b2740b

Browse files
authored
Added CHANGELOG.md to docs website (#358)
1 parent e4bca3c commit 2b2740b

File tree

6 files changed

+145
-2
lines changed

6 files changed

+145
-2
lines changed

.github/workflows/docs.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
with:
3232
fetch-depth: 0
3333

34+
- name: Create stub changelog.md file
35+
run: echo "# Changelog" > docs/pages/kotlinx-rpc/topics/changelog.md
36+
3437
- name: Build docs using Writerside Docker builder
3538
uses: JetBrains/writerside-github-action@v4
3639
with:
@@ -99,6 +102,13 @@ jobs:
99102
- name: Update sitemap.xml
100103
run: chmod +x updateSitemap.sh && ./updateSitemap.sh __docs_publication_dir/sitemap.xml __docs_publication_dir/api
101104

105+
- name: Run Changelog Generator
106+
run: ./gradlew updateDocsChangelog
107+
108+
- name: Move Changelog.md to the publication directory
109+
run:
110+
mv docs/pages/kotlinx-rpc/topics/changelog.md __docs_publication_dir/changelog.md
111+
102112
- name: Setup Pages
103113
uses: actions/configure-pages@v5
104114

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
This release enforces ERROR as a default reporting level for APIs that are forbidden by the strict mode.
66
You can still change the level manually, but in `0.8.0` strict mode will be enforced irreversibly.
77

8-
## What's Changed
9-
108
### Breaking Changes 🔴
119
* Change strict mode to level ERROR by default by @Mr3zee in https://github.com/Kotlin/kotlinx-rpc/pull/338
1210

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import util.configureApiValidation
88
import util.configureNpm
99
import util.configureProjectReport
1010
import util.registerDumpPlatformTableTask
11+
import util.registerChangelogTask
1112
import util.libs
1213
import util.registerVerifyPlatformTableTask
1314
import java.time.Year
@@ -83,6 +84,7 @@ configureApiValidation()
8384

8485
registerDumpPlatformTableTask()
8586
registerVerifyPlatformTableTask()
87+
registerChangelogTask()
8688

8789
val kotlinVersion = rootProject.libs.versions.kotlin.lang.get()
8890
val kotlinCompiler = rootProject.libs.versions.kotlin.compiler.get()

docs/pages/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
api/**
2+
kotlinx-rpc/topics/changelog.md

docs/pages/kotlinx-rpc/rpc.tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
<toc-element topic="0-2-4.topic"/>
5050
<toc-element topic="0-2-1.topic"/>
5151
</toc-element>
52+
<toc-element topic="changelog.md"/>
5253
<toc-element toc-title="API Reference" href="%host%/api/"/>
5354
</instance-profile>
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import org.gradle.api.DefaultTask
8+
import org.gradle.api.GradleException
9+
import org.gradle.api.Project
10+
import org.gradle.api.provider.Property
11+
import org.gradle.api.tasks.InputFile
12+
import org.gradle.api.tasks.OutputFile
13+
import org.gradle.api.tasks.TaskAction
14+
import org.gradle.kotlin.dsl.register
15+
import java.io.File
16+
import kotlin.io.path.createDirectories
17+
import kotlin.io.path.createFile
18+
import kotlin.io.path.exists
19+
import kotlin.io.path.readLines
20+
import kotlin.io.path.writeLines
21+
22+
private val ROOT_CHANGELOG_PATH = File("CHANGELOG.md")
23+
private val DOCS_CHANGELOG_PATH = File("docs/pages/kotlinx-rpc/topics/changelog.md")
24+
25+
private val PULL_REGEX = "https://github.com/Kotlin/kotlinx-rpc/pull/(\\d+)".toRegex()
26+
private val COMPARE_REGEX = "https://github.com/Kotlin/kotlinx-rpc/compare/([+.\\w_-]+)".toRegex()
27+
private val USERNAME_REGEX = "@([\\w_-]+)".toRegex()
28+
private val WHITESPACE = "\\s+".toRegex()
29+
30+
abstract class UpdateDocsChangelog : DefaultTask() {
31+
@get:InputFile
32+
abstract val input: Property<File>
33+
34+
@get:OutputFile
35+
abstract val output: Property<File>
36+
37+
@TaskAction
38+
fun update() {
39+
val inputPath = input.get().toPath()
40+
val outputPath = output.get().toPath()
41+
42+
if (!inputPath.exists()) {
43+
throw GradleException("fatal error: input file $inputPath does not exist")
44+
}
45+
46+
var currentRelease = ""
47+
val fullChangelogLines = mutableListOf<String>()
48+
val lines = inputPath.readLines(Charsets.UTF_8).flatMap { line ->
49+
val updated = line
50+
.replace(PULL_REGEX) {
51+
"[#${it.groupValues[1]}](${it.groupValues[0]})"
52+
}
53+
.replace(COMPARE_REGEX) {
54+
"[${it.groupValues[1]}](${it.groupValues[0]})"
55+
}
56+
.replace(USERNAME_REGEX) {
57+
"[${it.groupValues[0]}](https://github.com/${it.groupValues[1]})"
58+
}.let {
59+
if (it.startsWith("#")) {
60+
"#$it"
61+
} else {
62+
it
63+
}
64+
}
65+
66+
if (updated.startsWith("## ")) {
67+
currentRelease = updated
68+
.drop(3)
69+
.replace(".", "_")
70+
}
71+
72+
when {
73+
updated.startsWith("###") -> {
74+
val name = updated
75+
.dropWhile { it == '#' }
76+
.dropLastWhile { !it.isDigit() && !it.isLetter() }
77+
.trim()
78+
.replace(WHITESPACE, "_")
79+
80+
listOf("$updated {id=${name}_$currentRelease}")
81+
}
82+
83+
updated.startsWith("**Full Changelog**:") -> {
84+
fullChangelogLines.add(updated)
85+
emptyList()
86+
}
87+
88+
else -> listOf(updated)
89+
}
90+
}
91+
92+
val result = mutableListOf<String>()
93+
94+
var i = 0
95+
var fci = 0
96+
while (i < lines.size) {
97+
val line = lines[i]
98+
result.add(line)
99+
100+
if (line.startsWith("## ")) {
101+
result.add(lines[i + 1])
102+
result.add("")
103+
result.add(fullChangelogLines[fci++])
104+
i++
105+
}
106+
107+
i++
108+
}
109+
110+
if (!outputPath.exists()) {
111+
outputPath.parent.createDirectories()
112+
outputPath.createFile()
113+
}
114+
115+
val header = listOf(
116+
"# Changelog",
117+
"",
118+
"This page contains all changes throughout releases of the library.",
119+
"",
120+
)
121+
122+
outputPath.writeLines(header + result)
123+
}
124+
}
125+
126+
fun Project.registerChangelogTask() {
127+
tasks.register<UpdateDocsChangelog>("updateDocsChangelog") {
128+
input.set(ROOT_CHANGELOG_PATH)
129+
output.set(DOCS_CHANGELOG_PATH)
130+
}
131+
}

0 commit comments

Comments
 (0)