Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format with ktfmt #572

Merged
merged 5 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 16 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ indent_size = 2
indent_size = 2

[{*.kt,*.kts}]
ktlint_function_signature_body_expression_wrapping = multiline
ktlint_ignore_back_ticked_identifier = true
ij_kotlin_allow_trailing_comma = true
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_signature_body_expression_wrapping = multiline
ktlint_ignore_back_ticked_identifier = true
ktlint_standard_annotation = disabled
ktlint_standard_chain-method-continuation = disabled
ktlint_standard_class-signature = disabled
ktlint_standard_condition-wrapping = disabled
ktlint_standard_function-expression-body = disabled
ktlint_standard_function-literal = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_import-ordering = disabled
ktlint_standard_indent = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_string-template-indent = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_try-catch-finally-spacing = disabled

[gradlew.bat]
end_of_line = crlf
Expand Down
5 changes: 3 additions & 2 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 51 additions & 46 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ dependencies {
}

tasks {
val mergeSarifReports by registering(MergeSarifTask::class) {
source(configurations.outgoingSarif)
include { it.file.extension == "sarif" }
}

register("check") { dependsOn(mergeSarifReports) }
// val mergeSarifReports by
// registering(MergeSarifTask::class) {
// source(configurations.outgoingSarif)
// include { it.file.extension == "sarif" }
// }
//
// register("check") { dependsOn(mergeSarifReports) }

register("tagRelease") {
dependsOn("check")
Expand All @@ -36,9 +37,9 @@ tasks {
group = "release"

doFirst {
val rawReleaseVersion = ((project.property("jewel.release.version") as String?)
?.takeIf { it.isNotBlank() }
?: throw GradleException("Please provide a jewel.release.version in gradle.properties"))
val rawReleaseVersion =
((project.property("jewel.release.version") as String?)?.takeIf { it.isNotBlank() }
?: throw GradleException("Please provide a jewel.release.version in gradle.properties"))

val releaseName = "v$rawReleaseVersion"

Expand All @@ -47,9 +48,10 @@ tasks {
// Check we're on the main branch
logger.info("Checking current branch is main...")
exec {
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
standardOutput = stdOut
}
.assertNormalExitValue()

val currentBranch = stdOut.use { it.toString() }.trim()
if (currentBranch != "main") {
Expand All @@ -60,9 +62,10 @@ tasks {
logger.info("Checking current branch is main...")
stdOut.reset()
exec {
commandLine = listOf("git", "tag")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "tag")
standardOutput = stdOut
}
.assertNormalExitValue()

if (stdOut.toString().trim().lines().any { it == releaseName }) {
throw GradleException("The tag $releaseName already exists!")
Expand All @@ -72,9 +75,10 @@ tasks {
logger.info("Checking all changes have been committed...")
stdOut.reset()
exec {
commandLine = listOf("git", "status", "--porcelain")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "status", "--porcelain")
standardOutput = stdOut
}
.assertNormalExitValue()

if (stdOut.toString().isNotBlank()) {
throw GradleException("Please commit all changes before tagging a release")
Expand All @@ -84,24 +88,28 @@ tasks {
logger.info("Getting HEAD hash...")
stdOut.reset()
exec {
commandLine = listOf("git", "rev-parse", "HEAD")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "rev-parse", "HEAD")
standardOutput = stdOut
}
.assertNormalExitValue()

val currentHead = stdOut.use { it.toString() }.trim()

// Enumerate the release branches
logger.info("Enumerating release branches...")
stdOut.reset()
exec {
commandLine = listOf("git", "branch")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "branch")
standardOutput = stdOut
}
.assertNormalExitValue()

val releaseBranches = stdOut.use { it.toString() }
.lines()
.filter { it.trim().startsWith("releases/") }
.map { it.trim().removePrefix("releases/") }
val releaseBranches =
stdOut
.use { it.toString() }
.lines()
.filter { it.trim().startsWith("releases/") }
.map { it.trim().removePrefix("releases/") }

if (releaseBranches.isEmpty()) {
throw GradleException("No local release branches found, make sure they exist locally")
Expand All @@ -114,9 +122,10 @@ tasks {
for (branch in releaseBranches) {
stdOut.reset()
exec {
commandLine = listOf("git", "merge-base", "main", "releases/$branch")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "merge-base", "main", "releases/$branch")
standardOutput = stdOut
}
.assertNormalExitValue()

val mergeBase = stdOut.use { it.toString() }.trim()
if (mergeBase != currentHead) {
Expand All @@ -126,9 +135,7 @@ tasks {

// Tag main branch
logger.lifecycle("Tagging head of main branch as $releaseName...")
exec {
commandLine = listOf("git", "tag", releaseName)
}.assertNormalExitValue()
exec { commandLine = listOf("git", "tag", releaseName) }.assertNormalExitValue()

// Tag release branches
for (branch in releaseBranches) {
Expand All @@ -138,30 +145,28 @@ tasks {

logger.info("Getting branch head commit...")
exec {
commandLine = listOf("git", "rev-parse", "releases/$branch")
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "rev-parse", "releases/$branch")
standardOutput = stdOut
}
.assertNormalExitValue()

val branchHead = stdOut.use { it.toString() }.trim()
logger.info("HEAD of releases/$branch is $branchHead")

logger.info("Tagging commit ${branchHead.take(7)} as $branchTagName")
stdOut.reset()
exec {
commandLine = listOf("git", "tag", branchTagName, branchHead)
standardOutput = stdOut
}.assertNormalExitValue()
commandLine = listOf("git", "tag", branchTagName, branchHead)
standardOutput = stdOut
}
.assertNormalExitValue()
}

logger.info("All done!")
}
}

register<Delete>("cleanTestPublishArtifacts") {
delete(rootProject.layout.buildDirectory.dir("maven-test"))
}
register<Delete>("cleanTestPublishArtifacts") { delete(rootProject.layout.buildDirectory.dir("maven-test")) }

register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}
register<Delete>("clean") { delete(rootProject.layout.buildDirectory) }
}
16 changes: 5 additions & 11 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ plugins {
}

val properties = Properties()

project.file("../gradle.properties").inputStream().use { properties.load(it) }

val jdkLevel = properties.getProperty("jdk.level") as String

kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(jdkLevel)
}

sourceSets {
all {
languageSettings {
optIn("kotlinx.serialization.ExperimentalSerializationApi")
}
}
}
jvmToolchain { languageVersion = JavaLanguageVersion.of(jdkLevel) }

sourceSets { all { languageSettings { optIn("kotlinx.serialization.ExperimentalSerializationApi") } } }
}

dependencies {
Expand Down
6 changes: 1 addition & 5 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ dependencyResolutionManagement {
mavenCentral()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
}
43 changes: 22 additions & 21 deletions buildSrc/src/main/kotlin/MergeSarifTask.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import io.github.detekt.sarif4k.Run
import io.github.detekt.sarif4k.SarifSchema210
import io.github.detekt.sarif4k.Tool
import io.github.detekt.sarif4k.ToolComponent
import io.github.detekt.sarif4k.Version
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
Expand All @@ -21,38 +24,36 @@ open class MergeSarifTask : SourceTask() {

@get:OutputFile
val mergedSarifPath: RegularFileProperty =
project.objects
.fileProperty()
.convention(project.layout.buildDirectory.file("reports/static-analysis.sarif"))
project.objects.fileProperty().convention(project.layout.buildDirectory.file("reports/static-analysis.sarif"))

@TaskAction
fun merge() {
val json = Json { prettyPrint = true }

logger.lifecycle("Merging ${source.files.size} SARIF file(s)...")
logger.lifecycle(
source.files.joinToString("\n") { " * ~${it.path.removePrefix(project.rootDir.path)}" }
)
logger.lifecycle(source.files.joinToString("\n") { " * ~${it.path.removePrefix(project.rootDir.path)}" })

val merged =
SarifSchema210(
schema = SARIF_SCHEMA,
version = Version.The210,
runs = source.files
.asSequence()
.filter { it.extension == "sarif" }
.map { file ->
file.inputStream().use { json.decodeFromStream<SarifSchema210>(it) }
}
.flatMap { report -> report.runs }
.groupBy { run -> run.tool.driver.guid ?: run.tool.driver.name }
.values
.asSequence()
.filter { it.isNotEmpty() }
.map { run ->
run.first().copy(results = run.flatMap { it.results ?: emptyList() })
}
.toList()
runs =
source.files
.asSequence()
.filter { it.extension == "sarif" }
.map { file -> file.inputStream().use { json.decodeFromStream<SarifSchema210>(it) } }
.flatMap { report -> report.runs }
.groupBy { run -> run.tool.driver.guid ?: run.tool.driver.name }
.values
.asSequence()
.filter { it.isNotEmpty() }
.map { runs ->
Run(
results = runs.flatMap { it.results.orEmpty() },
tool = Tool(driver = ToolComponent(name = "Jewel static analysis")),
)
}
.toList(),
)

logger.lifecycle("Merged SARIF file contains ${merged.runs.size} run(s)")
Expand Down
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/PublishConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ internal fun PublishingExtension.configureJewelRepositories(project: Project) {
}
}

maven(project.rootProject.layout.buildDirectory.dir("maven-test")) {
name = "LocalTest"
}
maven(project.rootProject.layout.buildDirectory.dir("maven-test")) { name = "LocalTest" }
}
}

Expand Down
Loading
Loading