openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
60 stars 37 forks source link

Gradle exception should come after rewrite output on GitHub actions #230

Closed koppor closed 10 months ago

koppor commented 1 year ago

The RuntimeException is put inbetween the output in GitHub actions making it unreadable.

Maybe a flush helps?

Running on GitHub CI

image

These recipes would make changes to src/main/java/org/jabref/cli/JournalListMvGenerator.java:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':rewriteDryRun'.
> java.lang.RuntimeException: Applying recipes would make changes. See logs for more details.

* Try:
    org.jabref.config.rewrite.cleanup
> Run with --stacktrace option to get the stack trace.
        org.openrewrite.staticanalysis.EqualsAvoidsNull
> Run with --info or --debug option to get more log output.
Report available:
> Run with --scan to get full insights.
    /home/runner/work/jabref/jabref/build/reports/rewrite/rewrite.patch
> Get more help at https://help.gradle.org./
Run 'gradle rewriteRun' to apply the recipes.

BUILD FAILED in 1m 34s
> Task :rewriteDryRun FAILED

Running on command line

$ ./gradlew -s rewriteDryRun
These recipes would make changes to src\main\java\org\jabref\cli\JournalListMvGenerator.java:
    org.jabref.config.rewrite.cleanup
        org.openrewrite.staticanalysis.EqualsAvoidsNull
Report available:
    C:\git-repositories\jabref\build\reports\rewrite\rewrite.patch
Run 'gradle rewriteRun' to apply the recipes.

> Task :rewriteDryRun FAILED

FAILURE: Build failed with an exception.

What version of OpenRewrite are you using?

(Not quite sure, it is hard to determine - see https://github.com/openrewrite/rewrite-gradle-plugin/issues/199)

I am using

How are you running OpenRewrite?

./gradlew rewriteDryRun

Commit at JabRef/jabref@a11cb9d (#10347)

timtebeek commented 1 year ago

Hi @koppor ; fun to see how you've integrated OpenRewrite into your build pipelines there. From what I gather you do a dry run, and fail on dry run results, correct?

There's a few different messages showing up in your screenshot:

First there's the ones in yellow: https://github.com/openrewrite/rewrite-gradle-plugin/blob/903faa813c8061f2ac97f72b430f22ccf0e42122/plugin/src/main/java/org/openrewrite/gradle/isolated/DefaultProjectParser.java#L356-L357

Then there's the exception thrown here https://github.com/openrewrite/rewrite-gradle-plugin/blob/903faa813c8061f2ac97f72b430f22ccf0e42122/plugin/src/main/java/org/openrewrite/gradle/isolated/DefaultProjectParser.java#L385 And info logged through org.gradle.api.logging in https://github.com/openrewrite/rewrite-gradle-plugin/blob/903faa813c8061f2ac97f72b430f22ccf0e42122/plugin/src/main/java/org/openrewrite/gradle/RewriteDryRunTask.java#L49

The yellow ones seem to intermix with some Gradle logs regarding the use of --stacktrace.

timtebeek commented 1 year ago

Not quite sure what would be needed to not have those messages intermixed; perhaps consistently using logger.warn or logger.info could help, but even then I'm unsure if we have any influence over the Gradle internal messages appearing there.

koppor commented 11 months ago

From what I gather you do a dry run, and fail on dry run results, correct?

Yes, correct!

Not quite sure what would be needed

Me neither ^^. Maybe it is possible to tell the logging framework to flush after each line?

shanman190 commented 11 months ago

So personally this smells of stdout VS stderr synchronization. I know Gradle internally already does synchronized writes to the console, so there isn't any way for it to get jumbled from Gradle land. I believe both error and warn are routed to the stderr stream while everything else is routed to stdout. Based on a couple of other searches, I'm guessing that GitHub doesn't guarantee order between the streams when it comes to actions and rapid writes.

timtebeek commented 10 months ago

Thanks for that context @shanman190 ! Looks like there's not much we can do on this front then, or at least out of scope for this project. Hope you agree with me closing this one then @koppor , in an effort to clear our backlog from items that are not directly actionable.

That said, if you see this locally and feel that it is related to OpenRewrite's use of the Gradle and logging APIs, then perhaps we can have another look. Closing until then, but the commments below remain open for additional input.