-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18678 Use specific check tasks for CI build #9011
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
Conversation
|
Thanks for your pull request! This pull request appears to follow the contribution rules. › This message was automatically generated. |
gavinking
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let's not re-enable checkstyle.
The costs are way not worth the extremely marginal "benefits".
|
Spotless doesn't cover every rule enforced by our code-stye, and this already caused build failures locally (where it was not disabled). @sebersole agreed we should re-enable checkstyle just for the h2 build. |
|
Neither does checkstyle: we have lots of coding conventions which checkstyle has never enforced. If checkstyle didn't measurably slow us down, I wouldn't mind it. But recently I lost almost half a day when the |
|
If you guys can fix it so that it's not pig slow, and so that the Gradle integration is nonbroken, then by all means, please go ahead and turn it back on again. |
|
Checkstyle doesn't run with the The h2 run, which already takes less then half the time then others, will simply take 2 more minutes. |
|
Part of the problem, now, with checkstyle is that it is still doing work that spotless is doing. Cleaning up the checkstyle config will definitely help. I'll change that in a little |
|
I am well-aware that this should never have happened. Nevertheless it happened. Because the Gradle integration is broken. Which is precisely why I went and spent another half-day on replacing it with spotless. |
|
And regardless of whether it is"pig slow" it is formatting we want to enforce. So how else would you suggest we do that? And no, "simply not enforcing" is not an option. |
|
Look I agree it would be nice to enforce the brace on a new line rule. But I would also love to be able to enforce the maximum-120-characters per line rule, or the don't-stack-parens-without-a-space rule, etc, etc. But we don't enforce those rules, nor others, and somehow we manage to live with that. |
One thing we could do is push an IntelliJ config with the project, so that the IDE automatically applies the coding conventions. |
|
Alternatively, it's probably not terribly difficult to write a spotless step that replaces |
|
We have a code formatting step in Search and Validator builds... It actually produces a good result overall (there may be a few places with very long generics where the formatting might be a bit odd). Then in those places where we have code that goes into the documentation guides and we want to have more control, we just wrapped the code blocks with "skip-formatting-here". And these plugins have caching, so they don't need to re-run the formatting of all the files, but only those that changed, so the build time is not visibly impacted. Sooooo .... that might also be an option to consider (add the auto formatting to spotless config and enable this incremental cache so it doesn't run through all files). |
Like mentioned in the CONTRIBUTING? |
Well I mean actually including the IntelliJ config in the project itself so it's loaded automatically when you open the project. |
059cc35 to
5c5afae
Compare
Unfortunately I don't know how to do that. Now we could move the files to import into the project itself which would be a good first step. |
|
@sebersole I commented out all checkstyle rules already enforced by spotless, also I added the |
|
I think also there may be a misundertanding here... compilation does not run checkstyle. You need to run the |
I can set it up if you like. (I used to do it this way on other projects.) The only doubt I have is I need to make sure I can properly sanitize the IntelliJ project metadata of anything specific to my environment. But I believe this to be possible. |
Sure! I think that would be a great thing. To be clear though, we still want checkstyle to run (on the H2 / "default" jobs). Even with spotless and IDE formatting enabled, it is possible for someone to send code that is not formatted. So what we discussed was to do the following on the H2 CI job -
|
Did you need to explicitly disable spotlessApply? I'm surprised that is executed on a "normal CI build". |
Ahh, you did - |
See #9014 which appears to work. |
Does |
I was thinking about this some more. I think we should have a different task set up here. Something like this? // currently spotlessApply happens every time we compile.
// here we move that to the `check` "lifecycle phase"
tasks.check.dependsOn spotlessApply
tasks.register( "ciCheck" ) {
group "verification"
description "Checks for most CI environments"
dependsOn test
}
tasks.register( "ciCheckComplete" ) {
group "verification"
description "More complete checking for the H2 CI environment. The extra work is only needed for one job in the group"
dependsOn ciCheck
dependsOn spotlessCheck
dependsOn checkstyle
dependsOn forbiddenApis
}
|
|
The point of using spotless is so that it runs as soon as possible, and so you never get in a situation where you push code that hasn't had spotless run its cleanups. |
|
Completely excluding checkstyle would be awesome. |
We can quibble about whether spotless should be on compile or check. However, the CI jobs absolutely should be running checkstyle and spotlessCheck and forbiddenApis. No point running those for every database of course, so doing it on the H2 job is perfectly reasonable. |
|
Apart from the issue of brace placement (for which we can surely find another solution), what are the critical things that checkstyle is doing, in your opinion? I mean the things that will cause the sky to fall if we don't have them? |
If we can get those remaining checkstyle rules handled in spotless, I 100% agree that would be better. But if we can't, then the checkstyle checks should still be there. |
I'm sure some of these can be handled in spotless.. |
I already set this up in spotless, and spotless does a much better job of it, automatically adding a newline if necessary, and also stripping off unnecessary newlines.
This one, if it's actually enabled, simply doesn't work. I have had to fix oodles of missing Anyway, the GitHub CodeQL already does a really good job of catching these: https://codeql.github.com/codeql-query-help/java/java-missing-override-annotation/
This is nice to have. But again, CodeQL already does it: https://codeql.github.com/codeql-query-help/java/java-inconsistent-equals-and-hashcode/
I mean this is also quite nice, but there simply has to be a much more performant way to enforce this than running checkstyle! It's completely trivial to detect
The value of this one seems pretty debatable because:
Not counting a handful of
Just for completeness this one is definitely useful. But again it's something that you can actually do with just a regex. Or, in summary:
There has gotta be some |
|
This works, is ridiculously fast, and reports the problem in a much nicer way than checkstyle: task searchInFiles {
doLast {
def tree = fileTree("${project.projectDir}")
tree.include "**/*.java"
tree.each { file ->
file.eachLine { line ->
if (line.startsWith('import jakarta')) {
throw new GradleException( "Illegal import in ${file}: ${line}" )
}
}
}
}
}I'm sure we can easily improve on this. |
|
This seems to work quite nicely, and it really does run very fast: task enforceRules {
doLast {
def illegalImport = /^import (sun|java.awt|org.slf4j).*/
def missingNewline = /^\s*}\s*(else|catch|finally|while).*/
def errors = 0
def tree = fileTree("$rootDir/hibernate-core/src/main/java/")
tree.include "**/*.java"
tree.each { file ->
def lineNum = 0
def shortName = file.path.substring(rootDir.path.length())
file.eachLine { line ->
lineNum++
if (line ==~ illegalImport) {
errors++
logger.error("Illegal import in ${shortName}\n${lineNum}: ${line}")
}
if (line ==~ missingNewline) {
errors++
logger.error("Missing newline in ${shortName}\n${lineNum}: ${line}")
}
}
}
if ( errors>0 ) {
throw new GradleException("Code rules were violated ($errors problems)")
}
}
} |
|
See #9023. |
|
I pulled #9023 locally and played with it. It runs super fast. I think we should definitely move to this. |
|
Great, that's even better! Still, we should make sure we never call |
I think both |
|
Sure, I'll wait for Gavin's PR to be merged then I guess. I'm guessing by this change the intention is to leave |
|
In theory, if CI is enforcing this stuff correctly we should not be seeing what is happening now where we check out, compile and now end up applying someone else's bad formatting fixesg our your working tree.
It should be. It runs before compile so to Gradle it just looks like you changed those files yourself. Combined with better checking on the CI jobs, this should minimize the cases we've seen where a pull from upstream suddenly leads to a bunch of changed files on compile. |
29a8152 to
d5bc0fb
Compare
| spotlessApply { | ||
| enabled = false | ||
| } | ||
| spotlessJavaApply { | ||
| enabled = false | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only disabling spotlessApply is not enough apparently as spotlessJavaApply is run separately (run with --info for details).
|
What do y'all think about making these checks a proper CI action instead (similar to Code QL)? Especially if we can make the execution of tests depend on successfully pass. It would help make it even more obvious that its bad formatting that failed the build visually. Note that |
fd80fdc to
10bbfec
Compare
I like the idea, would make it very easy to understand that the problem is related to code formatting.
I'm fine with this, though note that if we want to include |
|
Since this PR was opened for another purpose and stale I've created a new one: #9188, that introduces a separate task for CI builds |
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-18678