Skip to content
Draft
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
104 changes: 104 additions & 0 deletions .github/workflows/docs-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Docs checks

# Builds the docs website and the Dokka API reference, and puts the API reference at `/api` of the website. A pull
# request runs this workflow, and the Deploy docs website workflow calls it. No job requests a write permission, so a
# pull request from a fork can run it.
#
# Don't make this check required. A pull request that the `paths` filter skips never gets the check.
on:
pull_request:
paths:
- 'docs/**'
- '!docs/spec.md'
- '**/src/**/*.kt'
- '**/*.gradle.kts'
- 'gradle/**'
- 'gradle.properties'
- '.github/workflows/docs-checks.yml'
workflow_call:
inputs:
version:
description: >-
The release that the website documents. The job builds the tag `v<version>`. Empty builds the commit of the
caller, with the version in gradle/libs.versions.toml.
type: string
default: ''

# A newer run of the same pull request cancels the older run. `github` is the context of the caller.
concurrency:
group: docs-checks-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

env:
# The runner has 16 GB, and the Kotlin daemon is a second JVM next to Gradle's.
GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx4g -Dkotlin.daemon.jvmargs=-Xmx4g

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
# The website and the Gradle builds read DEVKIT_PUBLISH_VERSION. An empty value is not the same as no value for
# the Gradle builds, so the variable is set only for a release.
- name: Check the website version
if: inputs.version != ''
env:
WEBSITE_VERSION: ${{ inputs.version }}
run: |
if [[ ! "$WEBSITE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-dev-[0-9]+)?$ ]]; then
echo "::error::The version must be a release, for example 0.0.4-dev-408. Got '$WEBSITE_VERSION'."
exit 1
fi
echo "DEVKIT_PUBLISH_VERSION=$WEBSITE_VERSION" >> "$GITHUB_ENV"

- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ inputs.version != '' && format('v{0}', inputs.version) || '' }}

- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: docs/package-lock.json

- name: Install docs dependencies
working-directory: docs
run: npm ci

- name: Check the website sources
working-directory: docs
run: npm run typecheck

# Docusaurus fails on a broken link or anchor, so this is the docs check as well.
- name: Build the docs website
working-directory: docs
run: npm run build

- name: Set up JDK
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v5

# Dokka fails on a warning, for example a KDoc link that doesn't resolve.
- name: Build the API reference
run: ./gradlew :dokkaGenerate

- name: Add the API reference to the website
run: |
mkdir -p docs/build/api
cp -r build/dokka/html/. docs/build/api/

- name: Upload the website
uses: actions/upload-pages-artifact@v5
with:
path: docs/build
retention-days: 7
39 changes: 39 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy docs website

# Only a manual run deploys the website. A run on a branch other than main builds the website and doesn't deploy it.
on:
workflow_dispatch:
inputs:
version:
description: 'The DevKit release to document, for example 0.0.4-dev-408. The run builds the tag v<version>.'
required: true
type: string

# Runs don't overlap and aren't cancelled, so a deploy to GitHub Pages never stops half way.
concurrency:
group: docs-deploy
cancel-in-progress: false

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/docs-checks.yml
with:
version: ${{ inputs.version }}

deploy:
if: github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
pages: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
build/
out/
local.properties
node_modules/
.docusaurus/
31 changes: 28 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ Three separate Gradle builds, none a subproject of another. Edits in either
included build take effect with no publishing step. Consumers outside this repo need a publish.

`build-logic` is a fourth build that isn't published. All three builds include it for its convention plugins:
`devkit.publishing` (coordinates, POM, signing, repositories) and `devkit.plugin-publishing` (the same, and the Gradle
Plugin Portal). It runs only on the Gradle that builds this repo, so the `tapmoc` and `gradle-public-api` rules below
don't apply to it.
`devkit.publishing` (coordinates, POM, signing, repositories), `devkit.plugin-publishing` (the same, and the Gradle
Plugin Portal), and `devkit.dokka` (the API reference). It runs only on the Gradle that builds this repo, so the
`tapmoc` and `gradle-public-api` rules below don't apply to it.

The root settings script includes `plugins` twice. The include in `pluginManagement` gives only the plugins of that
build. The second include lets the root project resolve the modules of `plugins`, for the aggregated Dokka publication.
Don't remove either include.

## Repo constraints

Expand Down Expand Up @@ -85,6 +89,19 @@ project with `artifacts/<project>.txt` of its build. When a publication changes,
for build in . version-resolution; do ./gradlew --project-dir $build dumpArtifacts; done
```

The docs website is a Docusaurus project in `docs/`, with its pages in `docs/pages/`. `docs/spec.md` isn't a page of the
website. The API reference is one Dokka publication of all three builds, and the docs workflows copy it to `/api` of the
website:

```bash
(cd docs && npm ci && npm start) # serves the website; its API Reference link goes to the deployed website
(cd docs && npm run build) # fails on a broken link or anchor
./gradlew :dokkaGenerate # writes the API reference to build/dokka/html
```

Only a manual run of the `Deploy docs website` workflow deploys the website. The run builds the tag `v<version>` of its
`version` input, so a docs change is live only after a release that has it.

## Conventions

- **Formatting is ktfmt, `Kotlinlang` style.** Spotless is declared in the **root** build script only and covers all
Expand Down Expand Up @@ -135,6 +152,14 @@ for build in . version-resolution; do ./gradlew --project-dir $build dumpArtifac
convention plugin uses the project name and that description for the POM. Don't declare
`com.vanniktech.maven.publish` or `com.gradle.plugin-publish` in a module. The convention plugins apply them, at the
catalog versions `publish` and `plugin-publish`.
- **A module with API for DevKit users applies `devkit.dokka`, and the root build script has a `dokka(...)` dependency
on it.** Dokka fails on a warning, for example a KDoc link that doesn't resolve. In the root build and
`version-resolution`, the javadoc jar of a publication has the Dokka output, so a warning also fails a publish.
`DEVKIT_PUBLISH_VERSION` also sets the version that the website and the API reference show. With the variable set, the
source links of the API reference go to the tag `v<version>`.
- **A `DevKitTarget` module with `devkit.dokka` also needs the `documentedCompilation` block** that
`compiler-plugin-runtime/build.gradle.kts` has. Without the block, Dokka documents the source sets of every version and
can't resolve the compiler classes in the shared source sets.

## Recipe: support a new Kotlin version

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A DevKit for Kotlin compiler plugin development

Use the [compiler-plugin-template](https://github.com/Kotlin/compiler-plugin-template/tree/devkit)'s `devkit` branch.

Alternatively, for a pre-existing project, use the [Migration guide](./docs/migration/)
Alternatively, for a pre-existing project, use the [Migration guide](./docs/pages/migration/0-migration-guide.md)

### Compatibility

Expand Down
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins { `kotlin-dsl` }

dependencies {
implementation(libs.dokka)
implementation(libs.maven.publish)
implementation(libs.plugin.publish)
}
8 changes: 8 additions & 0 deletions build-logic/src/main/kotlin/RepositoryRoot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.io.File
import org.gradle.api.Project

// `plugins` and `version-resolution` are builds in subdirectories, so `rootDir` isn't always the
// root of the repository.
val Project.repositoryRoot: File
get() =
generateSequence(rootDir) { it.parentFile }.first { it.resolve("build-logic").isDirectory }
20 changes: 20 additions & 0 deletions build-logic/src/main/kotlin/devkit.dokka.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins { id("org.jetbrains.dokka") }

// A release build links to the sources of its tag, so the line numbers match. AGENTS.md describes
// `DEVKIT_PUBLISH_VERSION`.
val sourceRef =
providers.environmentVariable("DEVKIT_PUBLISH_VERSION").map { "v$it" }.getOrElse("main")

dokka {
dokkaSourceSets.configureEach {
sourceLink {
localDirectory = repositoryRoot
remoteUrl("https://github.com/Kotlin/compiler-plugin-dev-kit/blob/$sourceRef")
remoteLineSuffix = "#L"
}
}
dokkaPublications.configureEach {
suppressObviousFunctions = true
failOnWarning = true
}
}
5 changes: 0 additions & 5 deletions build-logic/src/main/kotlin/devkit.publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ providers.gradleProperty("libs.sign.key.private").orNull?.let { key ->
}
}

// `plugins` and `version-resolution` are builds in subdirectories, so `rootDir` isn't always the
// root of the repository.
val repositoryRoot =
generateSequence(rootDir) { it.parentFile }.first { it.resolve("build-logic").isDirectory }

publishing {
repositories {
maven {
Expand Down
25 changes: 25 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.tapmoc) apply false
alias(libs.plugins.spotless)
id("devkit.dokka")
}

spotless {
Expand All @@ -24,3 +25,27 @@ spotless {
ktfmt(libs.versions.ktfmt.get()).kotlinlangStyle()
}
}

val devKitGroup = libs.versions.devkit.group.get()
val devKitVersion = libs.versions.devkit.version.get()

dependencies {
dokka(project(":compiler-plugin-runtime"))
dokka(project(":compiler-plugin-test"))
dokka(project(":compiler-plugin-test-generator"))
dokka(project(":gradle-plugin-runtime"))
// These modules are in included builds, so the dependencies use their coordinates.
dokka("$devKitGroup:plugins:$devKitVersion")
dokka("$devKitGroup:settings:$devKitVersion")
dokka("$devKitGroup:version-resolution:$devKitVersion")
}

dokka {
moduleName = "Kotlin Compiler Plugin DevKit"
moduleVersion = devKitVersion
pluginsConfiguration.html {
customAssets.from("docs/static/img/logo-icon.svg")
footerMessage = "© JetBrains s.r.o. and contributors"
homepageLink = "https://kotlin.github.io/compiler-plugin-dev-kit/"
}
}
12 changes: 12 additions & 0 deletions compiler-plugin-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
kotlin("multiplatform")
pluginDevKit("compiler-library")
id("devkit.publishing")
id("devkit.dokka")
alias(libs.plugins.tapmoc)
}

Expand Down Expand Up @@ -49,3 +50,14 @@ kotlin.sourceSets {
named("pre250Dev5651Main") { dependsOn(getByName("post23DevMain")) }
named("post250Dev5651Main") { dependsOn(getByName("post23DevMain")) }
}

// Dokka documents the API that the newest CLI version sees. The shared source sets get the compile
// classpath of that version, because their own metadata classpath has no compiler.
val documentedCompilation = provider {
pluginDevKit.testAgainst.filter { !it.forIde }.maxBy { it.version }.mainCompilation
}

dokka.dokkaSourceSets.configureEach {
suppress = documentedCompilation.map { c -> c.allKotlinSourceSets.none { it.name == name } }
classpath.from(documentedCompilation.map { it.compileDependencyFiles })
}
1 change: 1 addition & 0 deletions compiler-plugin-test-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion
plugins {
kotlin("jvm")
id("devkit.publishing")
id("devkit.dokka")
alias(libs.plugins.tapmoc)
}

Expand Down
12 changes: 12 additions & 0 deletions compiler-plugin-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
kotlin("multiplatform")
pluginDevKit("compiler-library")
id("devkit.publishing")
id("devkit.dokka")
alias(libs.plugins.tapmoc)
}

Expand Down Expand Up @@ -91,3 +92,14 @@ kotlin.sourceSets {
}
}
}

// Dokka documents the API that the newest CLI version sees. The shared source sets get the compile
// classpath of that version, because their own metadata classpath has no compiler.
val documentedCompilation = provider {
pluginDevKit.testAgainst.filter { !it.forIde }.maxBy { it.version }.mainCompilation
}

dokka.dokkaSourceSets.configureEach {
suppress = documentedCompilation.map { c -> c.allKotlinSourceSets.none { it.name == name } }
classpath.from(documentedCompilation.map { it.compileDependencyFiles })
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public expect fun TestInfrastructureException(

/**
* Checks that the source elements of FIR declarations in the analyzed FIR files are distinct. See
* [checkDistinctSourceElements] for more information.
* `checkDistinctSourceElements` for more information.
*
* The handler checks FIR files *after* analysis, which means that FIR elements have already been
* transformed. The tree might be different compared to its raw state, so the checker might not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public abstract class TestDumpRoot<out Self : TestDumpRoot<Self>>(public val uni
*
* For example, consider an OS classifier with Linux and Ubuntu(compatibleWith = Linux), and
* only `Ubuntu` is fixed:
* - tests with [Ubuntu] classifier must use dump files with [Ubuntu]
* - tests with [Linux] classifier must use dump files with no OS classifier
* - tests with `Ubuntu` classifier must use dump files with `Ubuntu`
* - tests with `Linux` classifier must use dump files with no OS classifier
*/
public open fun fixedClassifiers(
directives: RegisteredDirectives
Expand Down
Loading