mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2026-11-03 01:53:54 +00:00
build: add Kotlin Toolchain migration with Gradle fallback
This commit is contained in:
1 parent
0b9fb30862
commit
4d0f039787
58 files changed
+3115
-47
No files matched your search
@@ -0,0 +1,17 @@
|
||||
# KSLog GitHub release Toolchain plugin
|
||||
|
||||
Kotlin Toolchain 0.13.0 has no built-in GitHub release task. This local plugin
|
||||
keeps the existing explicit release capability as a narrow wrapper around the
|
||||
standard `gh release create` CLI.
|
||||
|
||||
It extracts the matching version section from `CHANGELOG.md`, preserves the
|
||||
legacy tag/title/target conventions, accepts the existing
|
||||
`GITHUB_RELEASE_TOKEN` variable plus standard `GH_TOKEN`/`GITHUB_TOKEN`, and
|
||||
supports a non-network `KSLOG_GITHUB_RELEASE_DRY_RUN=true` validation mode. It
|
||||
runs the committed release/version consistency preflight before rendering or
|
||||
creating a release. No CI workflow invokes it.
|
||||
|
||||
`gh release create` does not modify local git state, but GitHub may create the
|
||||
remote tag at `--target` when the requested tag does not already exist. A real
|
||||
invocation therefore mutates both the remote release and potentially the remote
|
||||
tag; dry-run mode performs neither action.
|
||||
@@ -0,0 +1,15 @@
|
||||
product: jvm/amper-plugin
|
||||
|
||||
description: Explicit GitHub release command backed by the standard GitHub CLI.
|
||||
|
||||
pluginInfo:
|
||||
id: github-release
|
||||
settingsClass: dev.inmo.kslog.build.release.GitHubReleaseSettings
|
||||
|
||||
settings:
|
||||
jvm:
|
||||
jdk:
|
||||
version: 17
|
||||
release: 17
|
||||
kotlin:
|
||||
version: 2.4.20
|
||||
@@ -0,0 +1,9 @@
|
||||
tasks:
|
||||
release:
|
||||
action: !dev.inmo.kslog.build.release.githubRelease
|
||||
projectRootDir: ${project.rootDir}
|
||||
settings: ${pluginSettings}
|
||||
|
||||
commands:
|
||||
- name: githubRelease
|
||||
performedBy: release
|
||||
@@ -0,0 +1,86 @@
|
||||
package dev.inmo.kslog.build.release
|
||||
|
||||
import org.jetbrains.amper.plugins.ExecutionAvoidance
|
||||
import org.jetbrains.amper.plugins.TaskAction
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.pathString
|
||||
import kotlin.io.path.writeText
|
||||
|
||||
@TaskAction(ExecutionAvoidance.Disabled)
|
||||
fun githubRelease(
|
||||
projectRootDir: String,
|
||||
settings: GitHubReleaseSettings,
|
||||
) {
|
||||
val root = Path.of(projectRootDir).toAbsolutePath().normalize()
|
||||
val changelog = root.resolve(settings.changelogFile).normalize()
|
||||
require(changelog.startsWith(root) && changelog.isRegularFile()) {
|
||||
"Changelog must be an existing file inside the module: $changelog"
|
||||
}
|
||||
|
||||
val releasePreflight = root.resolve("verification/check_release_consistency.py")
|
||||
require(releasePreflight.isRegularFile()) { "Missing release consistency preflight: $releasePreflight" }
|
||||
runCommand(root, listOf("python3", releasePreflight.pathString))
|
||||
|
||||
val parser = root.resolve("changelog_parser.sh")
|
||||
require(parser.isRegularFile()) { "Missing changelog parser: $parser" }
|
||||
val notes = runCommand(root, listOf("bash", parser.pathString, settings.version, changelog.pathString))
|
||||
.trim()
|
||||
require(notes.isNotEmpty()) { "No CHANGELOG.md section found for ${settings.version}" }
|
||||
|
||||
val tag = "${settings.tagPrefix}${settings.version}"
|
||||
val targetCommitish = settings.targetCommitish.ifBlank { settings.version }
|
||||
val repository = "${settings.owner}/${settings.repository}"
|
||||
if (System.getenv("KSLOG_GITHUB_RELEASE_DRY_RUN").toBoolean()) {
|
||||
println("Dry run: GitHub release $repository tag=$tag target=$targetCommitish title=${settings.version}")
|
||||
println(notes)
|
||||
return
|
||||
}
|
||||
|
||||
val token = System.getenv("GITHUB_RELEASE_TOKEN")
|
||||
?: System.getenv("GH_TOKEN")
|
||||
?: System.getenv("GITHUB_TOKEN")
|
||||
?: error("Set GITHUB_RELEASE_TOKEN, GH_TOKEN, or GITHUB_TOKEN before creating a release")
|
||||
|
||||
val notesFile = Files.createTempFile("kslog-release-notes-", ".md")
|
||||
try {
|
||||
notesFile.writeText(notes)
|
||||
val process = ProcessBuilder(
|
||||
"gh",
|
||||
"release",
|
||||
"create",
|
||||
tag,
|
||||
"--repo",
|
||||
repository,
|
||||
"--title",
|
||||
settings.version,
|
||||
"--target",
|
||||
targetCommitish,
|
||||
"--notes-file",
|
||||
notesFile.pathString,
|
||||
)
|
||||
.directory(root.toFile())
|
||||
.redirectErrorStream(true)
|
||||
process.environment()["GH_TOKEN"] = token
|
||||
val started = process.start()
|
||||
val output = started.inputStream.bufferedReader().use { it.readText() }
|
||||
val exitCode = started.waitFor()
|
||||
check(exitCode == 0) { "gh release create failed with exit code $exitCode:\n$output" }
|
||||
print(output)
|
||||
} finally {
|
||||
notesFile.deleteIfExists()
|
||||
}
|
||||
}
|
||||
|
||||
private fun runCommand(workingDirectory: Path, command: List<String>): String {
|
||||
val process = ProcessBuilder(command)
|
||||
.directory(workingDirectory.toFile())
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
val output = process.inputStream.bufferedReader().use { it.readText() }
|
||||
val exitCode = process.waitFor()
|
||||
check(exitCode == 0) { "Command failed with exit code $exitCode: ${command.first()}\n$output" }
|
||||
return output
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.inmo.kslog.build.release
|
||||
|
||||
import org.jetbrains.amper.plugins.Configurable
|
||||
|
||||
@Configurable
|
||||
interface GitHubReleaseSettings {
|
||||
val owner: String
|
||||
val repository: String
|
||||
val version: String
|
||||
val tagPrefix: String get() = "v"
|
||||
val targetCommitish: String get() = ""
|
||||
val changelogFile: String get() = "CHANGELOG.md"
|
||||
}
|
||||
Reference in new issue
Block a user