-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create reusable-pre-commit.yml
and add workflow for it
#10
Conversation
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 would have my two cents on this, I'll try to write them down until tonight.
5b0df92
to
f874fe7
Compare
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.
Alright, my two cents: In my opinion it is better to run clang-format through pre-commit and then run pre-commit in CI.
This has the advantage, that the configured clang-format version
a) only has to be configured in once place (the pre-commit-config)
b) is the same for users if they setup pre-commit independent of their installed version, since it installed via python in the pre-commit config (see this example)
This is of course only my opinion, apart from that the workflow seems fine, so I'm still approving.
I'm not sure if I understand you.. We have this in the pre-commit config files, I think in every repo of ros-controls ros2_control_ci/.pre-commit-config.yaml Lines 63 to 67 in aa86661
So the problem is here that it is installed with apt? I just copied that from ros2_controllers but maybe this is not necessary if it is installed via python later on? |
We may not have this change consistently everywhere but yes, there is precommit native support now for.clang and we should use that everywhere. When we first set things up it either didn't exist yet or we missed it and went with the local clang instance which is problematic. |
I think I missed that this actually runs pre-commit. So basically, it boils down to: yes, there is not necessarily a problem, but it might be confusing that clang-format is installed in the workflow in version 14. Same goes for cppcheck. It isn't used in the pre-commit config (at least in the linked ros2_controllers workflow), but there we use If a specific repo needs a specific apt package for their pre-commit configuration it can be installed in the specific workflow where this reusable workflow is included as a step. Also, it might make sense to rename this workflow to
Yes, that's also the progression I've seen and done in other repositories. This might be a good point to clean things up (which in this case boils down to remove some unused leftovers). |
To summarize: I remove the apt install section totally, because pre-commit hooks install their correct dependencies already? |
reusable-pre-commit.yml
|
f709690
to
4669354
Compare
Not necessarily. If they are predefined python hooks: Yes. If they are a custom command, no. Hence the failures in #10 (comment). However, since the missing packages are a consequence of the The solution would be to add
where Again, in my opinion it seems semantically correct to keep this together with the pre-commit-config file (meaning in each repo) but for maintenance reasons it might make sense to add those two steps to the |
As you have more experience, does it make sense to use pre-commit hooks like https://github.com/cmake-lint/cmake-lint/ or https://github.com/cpplint/cpplint instead? If we can do that for all linters, it would be much faster instead of running ros-tooling/setup-ros? Edit: It's too complicated to get all the settings from the ament-linters into the default hooks. This is not maintainable. |
Yes, that would have been my guess, as well. |
Any guesses why pre-commit doesn't find the executables now? Do I have to source the ROS installation? This doesn't fix it unfortunately
python version 3.10 seems to be ok. Does this action run in an virtual environment? my friend Copilot tells me:
maybe this is just not possible, we have to add the commit-stage again and run the four linters manually. maybe this is the reason why it was set-up like this. edit: running pre-commit in the same step manually works fine. |
reusable-pre-commit.yml
reusable-pre-commit.yml
and add workflow for 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.
Maybe we went down a rabbit hole withe the "ament linters through pre-commit" approach, sorry for triggering this...
run: | | ||
sudo apt-get install -qq ros-${{ inputs.ros_distro }}-ament-cppcheck ros-${{ inputs.ros_distro }}-ament-cpplint ros-${{ inputs.ros_distro }}-ament-lint-cmake ros-${{ inputs.ros_distro }}-ament-copyright | ||
source /opt/ros/${{ inputs.ros_distro }}/setup.bash | ||
python -m pip install 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.
This will probably get problematic on 24.04, since python 3.11 doesn't allow to install pip packages without a venv by default (see e.g. https://stackoverflow.com/questions/75602063/pip-install-r-requirements-txt-is-failing-this-environment-is-externally-mana). We can keep that in mind for later, though...
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.
For me it seemed that every step has its own vritual environment? this is why https://github.com/pre-commit/action/blob/main/action.yml#L13 didn't show any of the ROS packages before?
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, the hooks use their own venv (if they are python hooks). However, pre-commit
itself is installed without a venv here. I am simply referring to the python -m pip install pre-commit
command. This will not work on 24.04 (without any modifications to the systemat least). One way to resolve this (Doing this on my 23.10 machine for instance) would be to install pipx (available in apt)
and then do pipx install pre-commit && pipx ensurepath
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.
then we will have more problems, for example also with the sphinx build I guess
https://github.com/ros-controls/control.ros.org/blob/51ff1372c4014845b4b3b7f9fd86644d05fa1db3/.github/workflows/sphinx-make-page.yml#L22-L32
let's keep it like this for now and remember it until rolling is targeting on 24.04 (which might be together with Jazzy release?)
|
||
- name: Create Pull Request | ||
if: steps.git_status.outputs.changed == 'true' | ||
uses: peter-evans/create-pull-request@v6 |
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.
Would we want to specify the author here, as well? Otherwise, the default author Defaults to the user who triggered the workflow run which might be misleading in some situations.
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.
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'd test this first without specifying it, because in the demos of the action the PR is also from the github action bot without having specified it.. let's see ;)
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.
That seems nice now. Thank you @christophfroehlich!
Summary from the discussions below:
repo: local
hooks, because it is run in a virtual environment and I didn't manage to get the ament_linters installed in it. I now manually run pre-commit from the same step as installing the linters, this works fine.stage: [commit]
config.pre-commit autoupdate
to bump the versions of the hooks. Additionally, I added a scheduled workflow for doing this once a week.