<commit_before>import com.vdurmont.semver4j.Semver

plugins {
    id("com.github.breadmoirai.github-release")
}

githubRelease {
    token(project.findProperty("github.token") as? String ?: "")
    owner.set("arturbosch")
    repo.set("detekt")
    overwrite.set(true)
    dryRun.set(false)
    body {
        var changelog = project.file("docs/pages/changelog 1.x.x.md").readText()
        val sectionStart = "#### ${project.version}"
        changelog = changelog.substring(changelog.indexOf(sectionStart) + sectionStart.length)
        changelog = changelog.substring(0, changelog.indexOf("#### 1"))
        changelog.trim()
    }
    val cliBuildDir = project(":detekt-cli").buildDir
    releaseAssets.setFrom(
        files(
            cliBuildDir.resolve("libs/detekt-cli-${project.version}-all.jar"),
            cliBuildDir.resolve("distributions/detekt-cli-${project.version}.zip"),
            cliBuildDir.resolve("run/detekt")
        )
    )
}

val ln: String = System.lineSeparator()

fun updateVersion(increment: (Semver) -> Semver) {
    val versionsFile = file("${rootProject.rootDir}/buildSrc/src/main/kotlin/Versions.kt")
    val newContent = versionsFile.readLines()
        .joinToString(ln) {
            if (it.contains("const val DETEKT: String")) {
                val oldVersion = it.substringAfter("\"").substringBefore("\"")
                val newVersion = Semver(oldVersion).let(increment)
                println("Next release: $newVersion")
                """    const val DETEKT: String = "$newVersion""""
            } else {
                it
            }
        }
    versionsFile.writeText("$newContent$ln")
}

val incrementPatch by tasks.registering { doLast { updateVersion { it.nextPatch() } } }
val incrementMinor by tasks.registering { doLast { updateVersion { it.nextMinor() } } }
val incrementMajor by tasks.registering { doLast { updateVersion { it.nextMajor() } } }
<commit_msg>Build detekt executable before publishing it - #2654 (#2659)<commit_after>import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
import com.vdurmont.semver4j.Semver

plugins {
    id("com.github.breadmoirai.github-release")
}

githubRelease {
    token(project.findProperty("github.token") as? String ?: "")
    owner.set("arturbosch")
    repo.set("detekt")
    overwrite.set(true)
    dryRun.set(false)
    body {
        var changelog = project.file("docs/pages/changelog 1.x.x.md").readText()
        val sectionStart = "#### ${project.version}"
        changelog = changelog.substring(changelog.indexOf(sectionStart) + sectionStart.length)
        changelog = changelog.substring(0, changelog.indexOf("#### 1"))
        changelog.trim()
    }
    val cliBuildDir = project(":detekt-cli").buildDir
    releaseAssets.setFrom(
        files(
            cliBuildDir.resolve("libs/detekt-cli-${project.version}-all.jar"),
            cliBuildDir.resolve("distributions/detekt-cli-${project.version}.zip"),
            cliBuildDir.resolve("run/detekt")
        )
    )
}

tasks.withType<GithubReleaseTask> {
    dependsOn(":detekt-cli:shadowJarExecutable")
}

val ln: String = System.lineSeparator()

fun updateVersion(increment: (Semver) -> Semver) {
    val versionsFile = file("${rootProject.rootDir}/buildSrc/src/main/kotlin/Versions.kt")
    val newContent = versionsFile.readLines()
        .joinToString(ln) {
            if (it.contains("const val DETEKT: String")) {
                val oldVersion = it.substringAfter("\"").substringBefore("\"")
                val newVersion = Semver(oldVersion).let(increment)
                println("Next release: $newVersion")
                """    const val DETEKT: String = "$newVersion""""
            } else {
                it
            }
        }
    versionsFile.writeText("$newContent$ln")
}

val incrementPatch by tasks.registering { doLast { updateVersion { it.nextPatch() } } }
val incrementMinor by tasks.registering { doLast { updateVersion { it.nextMinor() } } }
val incrementMajor by tasks.registering { doLast { updateVersion { it.nextMajor() } } }

{'fraction_non_alphanumeric': 0.13968957871396895, 'fraction_numerical': 0.003941857600394186, 'mean_word_length': 2.9379243452958295, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4431723', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1239, 'n_words': 199}