Skip to content

Commit

Permalink
fix: only print issue postscript if there's an issue to report.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Oct 24, 2024
1 parent c5f4add commit b408f37
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ abstract class ReportingHandler @Inject constructor(objects: ObjectFactory) {

internal val postscript: Property<String> = objects.property<String>().convention("")

/**
* A postscript to include in issue reports. Only included when there are issues to report, otherwise ignored.
*/
fun postscript(postscript: String) {
this.postscript.set(postscript)
this.postscript.disallowChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ internal class ProjectHealthConsoleReportBuilder(

appendModuleAdvice()

if (postscript.isNotEmpty()) {
// Only print the postscript if there is anything at all to report.
if (isNotEmpty() && postscript.isNotEmpty()) {
appendLine()
appendLine()
appendLine(postscript)
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/autonomousapps/subplugin/RootPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ internal class RootPlugin(private val project: Project) {
shouldFail.set(generateBuildHealthTask.flatMap { it.outputFail })
consoleReport.set(generateBuildHealthTask.flatMap { it.consoleOutput })
printBuildHealth.set(printBuildHealth())
postscript.set(dagpExtension.reportingHandler.postscript)
}

// Add a dependency from the root project all projects (including itself).
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/com/autonomousapps/tasks/BuildHealthTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ abstract class BuildHealthTask : DefaultTask() {
@get:Input
abstract val printBuildHealth: Property<Boolean>

@get:Input
abstract val postscript: Property<String>

@TaskAction fun action() {
val shouldFail = shouldFail.get().asFile.readText().toBoolean()
val consoleReportFile = consoleReport.get().asFile
Expand All @@ -40,7 +43,15 @@ abstract class BuildHealthTask : DefaultTask() {
val output = buildString {
if (printBuildHealth.get()) {
append(consoleReportFile.readText())
} else {
// If we're not printing the build health report, we should still print the postscript.
val ps = postscript.get()
if (ps.isNotEmpty()) {
appendLine(ps)
appendLine()
}
}

// Trailing space so terminal UIs linkify it
append("There were dependency violations. See report at ${consoleReportPath.toUri()} ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ abstract class GenerateBuildHealthTask : DefaultTask() {
// console report
val report = ProjectHealthConsoleReportBuilder(
projectAdvice = projectAdvice,
postscript = postscript.get(),
// For buildHealth, we want to include the postscript only once.
postscript = "",
dslKind = dslKind.get(),
dependencyMap = dependencyMap.get().toLambda()
).text
Expand Down Expand Up @@ -135,9 +136,15 @@ abstract class GenerateBuildHealthTask : DefaultTask() {
output.bufferWriteJson(buildHealth)
outputFail.writeText(shouldFail.toString())

// This file must always exist, even if empty
if (!didWrite) {
// This file must always exist, even if empty
consoleOutput.writeText("")
} else {
// Append postscript if it exists
val ps = postscript.get()
if (ps.isNotEmpty()) {
consoleOutput.appendText("\n\n$ps")
}
}
}

Expand Down

0 comments on commit b408f37

Please sign in to comment.