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

ci: check code formatting on pull requests #953

Merged
merged 41 commits into from
Aug 16, 2021
Merged

ci: check code formatting on pull requests #953

merged 41 commits into from
Aug 16, 2021

Conversation

lionel-nj
Copy link
Contributor

@lionel-nj lionel-nj commented Aug 12, 2021

relates to #615

Summary:

This PR modifies the formatting workflow so that it is executed in pull request rather than on push on master branch.

The goal here is to avoid cluttering the commit history of the master branch and make sure that code is formatted before it is merged.

Expected behavior:

  • workflow should be executed on pull requests
  • workflow should fail on not properly formatted PRs
  • github-action bot should comment instructions to fix the formatting errors

Capture d’écran, le 2021-08-12 à 17 07 19

Please check the workflow logs to have details about the list of misformatted files (e.g. https://github.com/MobilityData/gtfs-validator/runs/3313714565?check_suite_focus=true)

Please make sure these boxes are checked before submitting your pull request - thanks!

  • [ ] Run the unit tests with gradle test to make sure you didn't break anything
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

Copy link
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lionel-nj See #615 - I believe that this will fail for PRs using branches from forks due to lack of permissions to write to that branch from the fork. IIRC we tried a variation of this config and had that problem. See the history for this file too - https://github.com/MobilityData/gtfs-validator/commits/fb4939e29c584cccb4b46286e9f8fd27194ceed2/.github/workflows/formatting.yml.

If we want this to run on PRs versus the master, I think we'll just to implement it as a check that fails and then prompts the PR submitter to do the format themselves.

@lionel-nj
Copy link
Contributor Author

lionel-nj commented Aug 12, 2021

If we want this to run on PRs versus the master, I think we'll just to implement it as a check that fails and then prompts the PR submitter to do the format themselves.

👍🏾

@barbeau I think that ab7add7 and 9bdf080 fix this.

Capture d’écran, le 2021-08-12 à 12 14 39

The workflow logs prompts the list of files that are not properly formatted - it no longer tries to commit on a branch:

Capture d’écran, le 2021-08-12 à 12 11 43

@lionel-nj lionel-nj requested a review from barbeau August 12, 2021 16:19
Copy link
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lionel-nj Thanks! This works, but I don't think it's very clear to the PR submitter what to do after it fails. First, they have to dig through the logs to find the error that caused the build to fail, and after than there are no instructions for what to do next to fix it.

Things that I think could improve this:

  1. Make the output more visible - Bots like the CLAbot comment on the PR to make it clear when the CLA has been signed and hasn't been signed. Ideally a bot would do the same with this.
  2. Add clear instructions for what to do next - If a bot in 1) above exists, it could comment with the exact command to run to format the files. If it does not, then adding output to the log with the exact command to run to format the files would be helpful. And maybe a link to the contribution documentation, if this is documented more there.

@github-actions
Copy link
Contributor

This contribution does not follow the conventions set by the Google Java style guide. Please download the formatter and run it with -i $(find . -name '*.java') to fix formatting errors.

@github-actions
Copy link
Contributor

This contribution does not follow the conventions set by the Google Java style guide. Please download the formatter and run it with -i $(find . -name '*.java') to fix formatting errors.

@barbeau
Copy link
Member

barbeau commented Aug 12, 2021

Could you include the full java -jar /path/to/google-java-format-1.11.0-all-deps.jar... in the instructions?

@github-actions
Copy link
Contributor

This contribution does not follow the conventions set by the Google Java style guide. Please download the formatter and run it with java -jar /path/to/google-java-format-1.11.0-all-deps.jar -i $(find . -name '*.java') to fix formatting errors.

@lionel-nj lionel-nj requested a review from barbeau August 12, 2021 21:09
Copy link
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @lionel-nj! Some thoughts in-line below.

core/build.gradle Outdated Show resolved Hide resolved
.github/workflows/formatting.yml Outdated Show resolved Hide resolved
@lionel-nj lionel-nj changed the title ci: execute google format on pull requests ci: check code formatting on pull requests Aug 16, 2021
@lionel-nj lionel-nj requested a review from barbeau August 16, 2021 19:31
- remove trailing whitespace

Co-authored-by: Sean Barbeau <[email protected]>
@lionel-nj lionel-nj requested a review from barbeau August 16, 2021 19:45
Copy link
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @lionel-nj! 👍

@lionel-nj
Copy link
Contributor Author

Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants