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

DAOS-16923 cq: make clang-format required #15685

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

daltonbohning
Copy link
Contributor

Make clang-format GHA required on PRs.

Skip-build: true

Before requesting gatekeeper:

  • Two review approvals and any prior change requests have been resolved.
  • Testing is complete and all tests passed or there is a reason documented in the PR why it should be force landed and forced-landing tag is set.
  • Features: (or Test-tag*) commit pragma was used or there is a reason documented that there are no appropriate tags for this PR.
  • Commit messages follows the guidelines outlined here.
  • Any tests skipped by the ticket being addressed have been run and passed in the PR.

Gatekeeper:

  • You are the appropriate gatekeeper to be landing the patch.
  • The PR has 2 reviews by people familiar with the code, including appropriate owners.
  • Githooks were used. If not, request that user install them and check copyright dates.
  • Checkpatch issues are resolved. Pay particular attention to ones that will show up on future PRs.
  • All builds have passed. Check non-required builds for any new compiler warnings.
  • Sufficient testing is done. Check feature pragmas and test tags and that tests skipped for the ticket are run and now pass with the changes.
  • If applicable, the PR has addressed any potential version compatibility issues.
  • Check the target branch. If it is master branch, should the PR go to a feature branch? If it is a release branch, does it have merge approval in the JIRA ticket.
  • Extra checks if forced landing is requested
    • Review comments are sufficiently resolved, particularly by prior reviewers that requested changes.
    • No new NLT or valgrind warnings. Check the classic view.
    • Quick-build or Quick-functional is not used.
  • Fix the commit message upon landing. Check the standard here. Edit it to create a single commit. If necessary, ask submitter for a new summary.

Make clang-format GHA required on PRs.

Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
@daltonbohning daltonbohning self-assigned this Jan 6, 2025
@daltonbohning daltonbohning marked this pull request as ready for review January 6, 2025 17:51
@daltonbohning daltonbohning requested a review from a team as a code owner January 6, 2025 17:51
Copy link

github-actions bot commented Jan 6, 2025

Ticket title is 'Make clang-format required on PRs'
Status is 'In Progress'
https://daosio.atlassian.net/browse/DAOS-16923

@daltonbohning
Copy link
Contributor Author

@mchaarawi Per request, it's this simple to make clang-format required. Should we alert devs before merging this?

@daltonbohning
Copy link
Contributor Author

Note that since this is version controlled, inflight PRs will not be affected until this change is merged into their branch

Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
@daltonbohning daltonbohning requested a review from a team as a code owner January 6, 2025 19:04
Since it may conflict with system.

Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
@jolivier23
Copy link
Contributor

I think you're going to get some pushback internally on this one. I'm personally ok with it.

jolivier23
jolivier23 previously approved these changes Jan 7, 2025
@jolivier23
Copy link
Contributor

If it's required, does it mean a PR has to be force landed. You might want to add or point to documentation for the comments to disable it (such as for FOREACH macros) when it does weird things.

@daltonbohning
Copy link
Contributor Author

If it's required, does it mean a PR has to be force landed. You might want to add or point to documentation for the comments to disable it (such as for FOREACH macros) when it does weird things.

If it's required, does it mean a PR has to be force landed

Right. It either needs to pass or needs force landing.

documentation for the comments to disable it (such as for FOREACH macros) when it does weird things

I don't work with C code enough to know - do you have an example of this? Or do you mean disable the hook with DAOS_GITHOOK_SKIP? (which would then require force landing)

Comment on lines 11 to 12
## Install DAOS Git Hooks
Installing is a two-step process:
Copy link
Contributor

Choose a reason for hiding this comment

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

## Install DAOS Git Hooks

Installing is a two-step process:

An empty line after ## ... is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required? this seems to render correctly. I'll update though

change with it.

2. Install all of the required tools
### 2. Install the required tools
Copy link
Contributor

Choose a reason for hiding this comment

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

### 2. Install the tools
Some of them are optional as mentioned below.

utils/githooks/README.md Outdated Show resolved Hide resolved
```
To install system packages with your package manager - for example:
```sh
dnf install git-clang-format
Copy link
Contributor

@grom72 grom72 Jan 22, 2025

Choose a reason for hiding this comment

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

sudo dnf install git-clang-format -y

```sh
dnf install git-clang-format
```
### Installed tools
Copy link
Contributor

Choose a reason for hiding this comment

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

#### Recommended tools
Is it a subsection of Install the~~ required~~ tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not, but makes sense. Thanks

It is important to check the output on commit for any errors that may indicate
any one of the required tools is missing.

1. copyright - Custom tool that automatically updates copyrights in modified files.
Copy link
Contributor

Choose a reason for hiding this comment

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

The script's name is update-copyright.
and
why some of names are within '`'?
All names refer to *.sh scripts in utils\githooks\pre-commit.d.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed '`' and made names match script names

@@ -13,11 +14,11 @@ if [ -e .git/MERGE_HEAD ]; then
fi

if ! command -v git-clang-format > /dev/null 2>&1; then
echo "git-clang-format not installed. Skipping"
echo "git-clang-format not installed. See ./utils/githooks/README.md for instructions"
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

exit 1
Shall we also make git-clang-format not optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No objection from me. But TBH I don't write enough C code to know whether that will bother people

Copy link
Contributor

Choose a reason for hiding this comment

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

If we enable this in CI we should also enable it in githooks.
Otherwise build fails and user will have to make another commit to fix that issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do agree with you. But in the past people have not liked when a githook prevents them from committing. Hopefully with updated documentation and it being required in the GHA, people will accept it 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

If we get acceptance here we can also modify all other pre-commit scripts later to force everybody with pre-validation for every changes that are later verified by CI ;).

Copy link
Contributor

Choose a reason for hiding this comment

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

in the past people have not liked when a githook prevents them from committing

Funny thing clang changes over time and differs from distro to distro. So, you may even have clang-format pre-hook enabled and still be stopped by a check on GitHub. Just because of the different versions I believe.

Here --no-verify toggle becomes very useful. Just turn it off when it is in your way. ;-)

exit 0
fi
if ! command -v clang-format > /dev/null 2>&1; then
echo "clang-format not installed. Skipping"
echo "clang-format not installed. See ./utils/githooks/README.md for instructions"
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

exit 1
Shall we also make git-clang-format not optional?

exit 0
fi
if ! command -v clang-format > /dev/null 2>&1; then
echo "clang-format not installed. Skipping"
echo "clang-format not installed. See ./utils/githooks/README.md for instructions"
Copy link
Contributor

Choose a reason for hiding this comment

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

./utils/githooks/README.md#2-install-the-required-tools
Let's try to use link to particular section - helps a lot.


It is important to check the output on commit for any errors that may indicate
any one of the required tools is missing.
### Optional tools
Copy link
Contributor

Choose a reason for hiding this comment

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

#### Optional tools
Is it a subsection of Install the~~ required~~ tools?

@kccain
Copy link
Contributor

kccain commented Jan 22, 2025

If it's required, does it mean a PR has to be force landed. You might want to add or point to documentation for the comments to disable it (such as for FOREACH macros) when it does weird things.

If it's required, does it mean a PR has to be force landed

Right. It either needs to pass or needs force landing.

documentation for the comments to disable it (such as for FOREACH macros) when it does weird things

I don't work with C code enough to know - do you have an example of this? Or do you mean disable the hook with DAOS_GITHOOK_SKIP? (which would then require force landing)

clang-format has made unwanted (human-unreadable) changes to RPC definition macros. Pretty bad. And in those cases we've had to repair this after the fact in subsequent commits by using C comments containing "clang-format off" and "clang-format on" to mark the region of the source code that clang-format should not modify. Example region with the control comments:

/* clang-format off */
...
/* clang-format on */

Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
Skip-build: true

Signed-off-by: Dalton Bohning <[email protected]>
exit 0
echo "git-clang-format not installed."
echo "See ./utils/githooks/README.md#2-install-the-required-tools for instructions."
exit 1
fi
if ! command -v clang-format > /dev/null 2>&1; then
Copy link
Contributor

Choose a reason for hiding this comment

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

if ! command -v clang-format > /dev/null 2>&1; then
I think we can remove this check as:

  • there is a strict dependency between git-clang-format pkg and clang-tools-extra (clang-format) pkg. Every time
  • the presence of clang-format is checked by extra.py script few lines later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I admit I don't know much about this tool

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

Successfully merging this pull request may close these issues.

5 participants