-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Enforce pre-commit in ArduPilot #24683
base: master
Are you sure you want to change the base?
Conversation
Need to install pre-commit as part of the normal set of python packages. |
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 should fix the files instead of excluding them.
Looks like we might be able to force an upgrade of |
9f2f02a
to
48cc7b1
Compare
173500a
to
7a89854
Compare
Rebased and fixed the regression. Dropped changes of installing pre-commit automatically.
|
Here's a demo for the CI script with a good PR:
Now, if we accidentally make a cpp file executable, you get this in the CI logs:
|
* Needed by ArduPilot/ardupilot#24683 Signed-off-by: Ryan Friedman <[email protected]>
* Needed by ArduPilot/ardupilot#24683 Signed-off-by: Ryan Friedman <[email protected]>
c027dd7
to
d3b4d7d
Compare
@khancyr Can you create a new tag/release for the dev dockerfiles? |
my bad, I haven't seen it wasn't in the release. I have force push a rebuild with the latest version |
982299b
to
2fa7168
Compare
Is there an option to disable this pre-vcommit though? I really wouldn't want to be forced to obey specific rules when I'm just doing test development in my own fork. That would really slow down development. |
Yep! That said, do you have examples of this slowing down development and specifics on which hooks or workflows have affected you? We only run a bare minimum set of hooks right now. You can also disable specific hooks like so: https://stackoverflow.com/questions/7230820/skip-git-commit-hooks |
Tools/scripts/build_ci.sh
Outdated
@@ -424,6 +424,13 @@ for t in $CI_BUILD_TARGET; do | |||
continue | |||
fi | |||
|
|||
if [ "$t" == "pre-commit-cleanliness" ]; then | |||
echo "Checking pre-commit code cleanliness" | |||
pre-commit install |
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.
@Ryanf55 that means that after a first run precommit will be enable on git commit. Probably not the best move. Just doing the pre-commit run is enough and don't mess the git config for now (I still want pre-commit)
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.
Are you saying that local developers run build_ci with specific arguments to hit this code block?
Without the above line, the job would fail in CI because pre-commit wasn't enabled for the repo.
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.
@Ryanf55 I think Pierre is saying we shouldn't be making this permanent change to their setup in here.
We can do it as part of the machine setup in the github workflows instead, yes?
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.
yes, but I thought it would be ok because this is a CI script. I'm happy to move it if you think we need to worry about devs running this check and then being surprised pre-commit is now enabled.
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.
Yes, please move 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.
Done! Let's see how it goes...
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.
@Ryanf55 normally there is not issue to use pre-commit run --all-files
on CI, install isn't need for CI
@Ryanf55 This is tagged MergeOnCiPass, and it's passing, but it has a merge conflict |
I never got an answer on Pierre's comment. I don't have a path forward on this without feedback on the raised concern. |
@khancyr ping! |
Signed-off-by: Ryan Friedman <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
* These are not scripts and should not be executable Signed-off-by: Ryan Friedman <[email protected]>
* It should be moved to the workflow Signed-off-by: Ryan Friedman <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
2fa7168
to
7fb8fc7
Compare
- name: install pre-commit | ||
shell: bash | ||
run: | | ||
pre-commit install |
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.
why need this ? we don't run git command on CI, so the install isn't need normally, or I miss something ?
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.
are you sure that shouldn't be pip install pre-commit
instead ?
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.
OK i have checked and we got pre-commit into the docker image already so we are fine. the pre-commit install is just to install the git hook so that isn't need on CI
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.
You are conflating installation of the pre-commit tool in the environment and installation of the git hooks into the repo.
https://pre-commit.com/#3-install-the-git-hook-scripts
We need both at some point before calling pre-commit run
in ArduPilot.
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.
Nope you don't need to install the git hook to use precommit.
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.
something is wrong with this commit as it moves the submodules ! ce6e3fb (the xmllint one's )
Related issues
Fixes #24555.
Depends on #24727.
Purpose
Pre-commit provides basic guardrails for the repos, but it's not enforced. This PR adds it as a CI job.
How to test
Future ideas
We could autofix and re-commit the changes in CI to save developer time, but one could see it as risky.
Actions from Tridge's testing: