Skip to content

Commit 861f268

Browse files
authored
Replace knit with generate_toc.py (#6279)
1 parent 168470f commit 861f268

File tree

11 files changed

+244
-59
lines changed

11 files changed

+244
-59
lines changed

.github/workflows/quality.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ jobs:
287287
path: |
288288
**/build/reports/**/*.*
289289
290-
knit:
291-
name: Knit checks
290+
docs:
291+
name: Doc checks
292292
runs-on: ubuntu-latest
293293
# Allow all jobs on main and develop. Just one per PR.
294294
concurrency:
295-
group: ${{ github.ref == 'refs/heads/main' && format('check-knit-main-{0}', github.sha) || github.ref == 'refs/heads/develop' && format('check-knit-develop-{0}', github.sha) || format('check-knit-{0}', github.ref) }}
295+
group: ${{ github.ref == 'refs/heads/main' && format('check-docs-main-{0}', github.sha) || github.ref == 'refs/heads/develop' && format('check-docs-develop-{0}', github.sha) || format('check-docs-{0}', github.ref) }}
296296
cancel-in-progress: true
297297
steps:
298298
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -309,17 +309,9 @@ jobs:
309309
- name: Clone submodules
310310
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
311311
run: git submodule update --init --recursive
312-
- name: Use JDK 21
313-
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
314-
with:
315-
distribution: 'temurin' # See 'Supported distributions' for available options
316-
java-version: '21'
317-
- name: Configure gradle
318-
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
319-
with:
320-
cache-read-only: ${{ github.ref != 'refs/heads/develop' }}
321-
- name: Run Knit
322-
run: ./gradlew knitCheck $CI_GRADLE_ARG_PROPERTIES
312+
- name: Run docs check
313+
# This is equivalent to `./gradlew checkDocs`, but we avoid having to install java and gradle
314+
run: python3 ./tools/docs/generate_toc.py --verify ./*.md docs/**/*.md
323315

324316
# Note: to auto fix issues you can use the following command:
325317
# shellcheck -f diff <files> | git apply

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* [Code quality](#code-quality)
1717
* [detekt](#detekt)
1818
* [ktlint](#ktlint)
19-
* [knit](#knit)
19+
* [checkDocs](#checkdocs)
2020
* [lint](#lint)
2121
* [Unit tests](#unit-tests)
2222
* [konsist](#konsist)
@@ -123,21 +123,21 @@ Note that you can run
123123

124124
For ktlint to fix some detected errors for you (you still have to check and commit the fix of course)
125125

126-
#### knit
126+
#### checkDocs
127127

128-
[knit](https://github.com/Kotlin/kotlinx-knit) is a tool which checks markdown files on the project. Also it generates/updates the table of content (toc) of the markdown files.
128+
`checkDocs` is a Gradle task which checks markdown files on the project to ensure their table of contents is up to date. It uses `tools/docs/generate_toc.py --verify` under the hood, and has a counterpart `generateDocsToc` task which runs `tools/docs/generate_toc.py` to update the table of contents of markdown files.
129129

130130
So everytime the toc should be updated, just run
131131
<pre>
132-
./gradlew knit
132+
./gradlew generateDocsToc
133133
</pre>
134134

135135
and commit the changes.
136136

137137
The CI will check that markdown files are up to date by running
138138

139139
<pre>
140-
./gradlew knitCheck
140+
./gradlew checkDocs
141141
</pre>
142142

143143
#### lint

app/build.gradle.kts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ plugins {
3333
alias(libs.plugins.kotlin.android)
3434
// When using precompiled plugins, we need to apply the firebase plugin like this
3535
id(libs.plugins.firebaseAppDistribution.get().pluginId)
36-
alias(libs.plugins.knit)
3736
id("kotlin-parcelize")
3837
alias(libs.plugins.licensee)
3938
alias(libs.plugins.kotlin.serialization)
@@ -250,26 +249,6 @@ androidComponents {
250249
configureLicensesTasks(reportingExtension)
251250
}
252251

253-
// Knit
254-
apply {
255-
plugin("kotlinx-knit")
256-
}
257-
258-
knit {
259-
files = fileTree(project.rootDir) {
260-
include(
261-
"**/*.md",
262-
"**/*.kt",
263-
"*/*.kts",
264-
)
265-
exclude(
266-
"**/build/**",
267-
"*/.gradle/**",
268-
"**/CHANGES.md",
269-
)
270-
}
271-
}
272-
273252
setupDependencyInjection()
274253

275254
dependencies {

build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,23 @@ tasks.register("runQualityChecks") {
175175
tasks.findByName("ktlintCheck")?.let { dependsOn(it) }
176176
// tasks.findByName("buildHealth")?.let { dependsOn(it) }
177177
}
178-
dependsOn(":app:knitCheck")
179-
178+
dependsOn("checkDocs")
180179
// Make sure all checks run even if some fail
181180
gradle.startParameter.isContinueOnFailure = true
182181
}
183182

183+
// Register Markdown documentation check task.
184+
tasks.register("checkDocs", Exec::class.java) {
185+
inputs.files("./*.md", "docs/**/*.md")
186+
commandLine("python3", "tools/docs/generate_toc.py", "--verify", *inputs.files.map { it.path }.toTypedArray())
187+
}
188+
189+
// Register Markdown documentation TOC generation task.
190+
tasks.register("generateDocsToc", Exec::class.java) {
191+
inputs.files("./*.md", "docs/**/*.md")
192+
commandLine("python3", "tools/docs/generate_toc.py", *inputs.files.map { it.path }.toTypedArray())
193+
}
194+
184195
// Make sure to delete old screenshots before recording new ones
185196
subprojects {
186197
val snapshotsDir = File("${project.projectDir}/src/test/snapshots")

docs/install_from_github_release.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This document explains how to install Element X Android from a Github Release.
1010
* [I already have the application on my phone](#i-already-have-the-application-on-my-phone)
1111
* [Installing from the App Bundle](#installing-from-the-app-bundle)
1212
* [Requirements](#requirements)
13-
* [Steps](#steps)
14-
* [I already have the application on my phone](#i-already-have-the-application-on-my-phone)
13+
* [Steps](#steps-1)
14+
* [I already have the application on my phone](#i-already-have-the-application-on-my-phone-1)
1515

1616
<!--- END -->
1717

docs/installing_from_ci.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<!--- TOC -->
44

5-
* [Installing from GitHub](#installing-from-github)
6-
* [Create a GitHub token](#create-a-github-token)
7-
* [Provide artifact URL](#provide-artifact-url)
8-
* [Next steps](#next-steps)
9-
* [Future improvement](#future-improvement)
5+
* [Installing from GitHub](#installing-from-github)
6+
* [Create a GitHub token](#create-a-github-token)
7+
* [Provide artifact URL](#provide-artifact-url)
8+
* [Next steps](#next-steps)
9+
* [Future improvement](#future-improvement)
1010

1111
<!--- END -->
1212

docs/integration_tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* [Stop Synapse](#stop-synapse)
99
* [Troubleshoot](#troubleshoot)
1010
* [Android Emulator does cannot reach the homeserver](#android-emulator-does-cannot-reach-the-homeserver)
11-
* [Tests partially run but some fail with "Unable to contact localhost:8080"](#tests-partially-run-but-some-fail-with-"unable-to-contact-localhost8080")
11+
* [Tests partially run but some fail with "Unable to contact localhost:8080"](#tests-partially-run-but-some-fail-with-unable-to-contact-localhost8080)
1212
* [virtualenv command fails](#virtualenv-command-fails)
1313

1414
<!--- END -->

docs/notifications.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ This document aims to describe how Element android displays notifications to the
55
<!--- TOC -->
66

77
* [Prerequisites Knowledge](#prerequisites-knowledge)
8-
* [How does a matrix client get a message from a homeserver?](#how-does-a-matrix-client-get-a-message-from-a-homeserver?)
8+
* [How does a matrix client get a message from a homeserver?](#how-does-a-matrix-client-get-a-message-from-a-homeserver)
99
* [How does a mobile app receives push notification](#how-does-a-mobile-app-receives-push-notification)
1010
* [Push VS Notification](#push-vs-notification)
1111
* [Push in the matrix federated world](#push-in-the-matrix-federated-world)
12-
* [How does the homeserver know when to notify a client?](#how-does-the-homeserver-know-when-to-notify-a-client?)
12+
* [How does the homeserver know when to notify a client?](#how-does-the-homeserver-know-when-to-notify-a-client)
1313
* [Push vs privacy, and mitigation](#push-vs-privacy-and-mitigation)
1414
* [Background processing limitations](#background-processing-limitations)
1515
* [Element Notification implementations](#element-notification-implementations)

docs/pull_request.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
<!--- TOC -->
44

55
* [Introduction](#introduction)
6-
* [Who should read this document?](#who-should-read-this-document?)
6+
* [Who should read this document?](#who-should-read-this-document)
77
* [Submitting PR](#submitting-pr)
8-
* [Who can submit pull requests?](#who-can-submit-pull-requests?)
8+
* [Who can submit pull requests?](#who-can-submit-pull-requests)
99
* [Humans](#humans)
10-
* [Draft PR?](#draft-pr?)
10+
* [Draft PR?](#draft-pr)
1111
* [Base branch](#base-branch)
1212
* [PR Review Assignment](#pr-review-assignment)
1313
* [PR review time](#pr-review-time)
1414
* [Re-request PR review](#re-request-pr-review)
15-
* [When create split PR?](#when-create-split-pr?)
15+
* [When create split PR?](#when-create-split-pr)
1616
* [Avoid fixing other unrelated issue in a big PR](#avoid-fixing-other-unrelated-issue-in-a-big-pr)
1717
* [Bots](#bots)
1818
* [Renovate](#renovate)
1919
* [Gradle wrapper](#gradle-wrapper)
2020
* [Sync analytics plan](#sync-analytics-plan)
2121
* [Reviewing PR](#reviewing-pr)
22-
* [Who can review pull requests?](#who-can-review-pull-requests?)
22+
* [Who can review pull requests?](#who-can-review-pull-requests)
2323
* [What to have in mind when reviewing a PR](#what-to-have-in-mind-when-reviewing-a-pr)
2424
* [Rules](#rules)
2525
* [Check the form](#check-the-form)
@@ -29,7 +29,7 @@
2929
* [Check the commit](#check-the-commit)
3030
* [Check the substance](#check-the-substance)
3131
* [Make a dedicated meeting to review the PR](#make-a-dedicated-meeting-to-review-the-pr)
32-
* [What happen to the issue(s)?](#what-happen-to-the-issues?)
32+
* [What happen to the issue(s)?](#what-happen-to-the-issues)
3333
* [Merge conflict](#merge-conflict)
3434
* [When and who can merge PR](#when-and-who-can-merge-pr)
3535
* [Merge type](#merge-type)

gradle/libs.versions.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ paparazzi = "app.cash.paparazzi:2.0.0-alpha04"
266266
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
267267
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
268268
firebaseAppDistribution = { id = "com.google.firebase.appdistribution", version.ref = "firebaseAppDistribution" }
269-
knit = { id = "org.jetbrains.kotlinx.knit", version = "0.5.1" }
270269
sonarqube = "org.sonarqube:7.2.3.7755"
271270
licensee = "app.cash.licensee:1.14.1"
272271
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

0 commit comments

Comments
 (0)