-
Notifications
You must be signed in to change notification settings - Fork 10
chore(CI): adds googlejavaformat action to CI. #24
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
Codecov Report
@@ Coverage Diff @@
## main #24 +/- ##
============================================
+ Coverage 69.44% 69.49% +0.04%
Complexity 160 160
============================================
Files 11 11
Lines 707 708 +1
Branches 73 73
============================================
+ Hits 491 492 +1
Misses 174 174
Partials 42 42
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@aaron-steinfeld @buchi-busireddy could you please loop in and tell what are the rules we expect to meet? also the version for the formatting rules? |
We generally use https://plugins.jetbrains.com/plugin/8527-google-java-format - so it looks like that currently means 1.9 (I think their versioning is not of the rules themselves which don't appear to be versioned https://google.github.io/styleguide/javaguide.html , but the tool's implementation?) |
push: | ||
branches: | ||
- master | ||
paths-ignore: |
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.
Do we need ignore paths? This check takes ~15s, and the problem with limiting actions based on changed paths is that we can't do the same with the protected branch required checks. So if this action sometimes doesn't run, we can't require it.
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.
I don't think it is about the time it takes, it is mostly about this linter only makes sense if java code has been changed, hence the ignore.
|
||
jobs: | ||
formatting: | ||
runs-on: ubuntu-latest |
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 pin the env (we've been using ubuntu-20.04
elsewhere)
id("org.hypertrace.jacoco-report-plugin") version "0.1.0" | ||
id("org.hypertrace.integration-test-plugin") version "0.1.0" | ||
id("com.bmuschko.docker-remote-api") version "6.4.0" | ||
`java-library` |
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.
Is this to verify the check is working? The indentation should be 2 https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation
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.
We need to fix all files before merge so next person opening a PR in here does not have to deal with the lint mess.
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.
Agreed - but aren't these formatting changes going in the wrong direction? They're changing the formatting of files that were previously correctly formatted and after this change are incorrect. As an example, take Datastore.java - https://github.com/hypertrace/document-store/pull/24/files#diff-fcb7b4dcc9273e596438f61590e9eb81e373bec38fa40adec47e2068853fcd3a
The changes switch the block indent from 2 -> 4 (should be 2 https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation ) and separates the lang imports from third party (should be in single block https://google.github.io/styleguide/javaguide.html#s3.3.3-import-ordering-and-spacing )
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.
Yeah, let me rephrase. This was an attempt to fix all problems but I was fooled by the intellij plugin I think.
Is there a way to auto format the code using some command line option? I recently added https://github.com/diffplug/spotless in one of the repositories, which provides a command line option to auto format the entire code and it has various formatting options, google formatting being one of them https://github.com/diffplug/spotless/tree/main/plugin-gradle#google-java-format We can add git hooks and auto apply/check the formatting as I think @pavolloffay also uses the same plugin in Java Agent https://github.com/hypertrace/javaagent/blob/a339bd5747af6cef4fbc666e641278b61cfbc273/gradle/spotless.gradle |
@skjindal93, are you talking about something like this: https://github.com/thegreystone/action-jmc-spotless ? Not sure if this helps. If not we can still write shellscript and use it with dockerfile and create our own action similar to above. I believe it will be series of bash commands so we can have basic dockerfile with gradle as in above action and then add bash script as We will also need to figure out how GH actions can make a commit if it's going to make changes. Not sure about that. Will be happy to work with you if this is significant and can help us in future as well. we can take a stab. |
If we just add spotless plugin in the list of applied plugins, spotless exposes a gradle command, which can be used as a separate Github Action as |
I think the gradle plugin to autofix the code is better so we don't add another tool to fix the files. Maybe @pavolloffay can port his work into this repo? |
Agree it would be nice to embed this into the existing |
Check is good. I think it is too much overhead to only check diffs or diff files. This is linting and checking all files might be just fine. I am also against doing the fix on PR, this should be just a yes/no check and not do anything else. Autofixing on CI is cumbersome experience as 1. actions run in paralell and 2. we need push access 3. users have to download new commits before adding further changes. |
Yes the HT javaagent uses the spotless gradle plugin and it works perfectly ❤️ . |
This one is still an open issue diffplug/spotless#623, unless we write a fancy bash script to do that |
This PR adds a google java format check on CI.