-
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
Changes from all commits
7508264
54a3d05
df325c3
d069b1d
4669354
913e0e2
b2d414b
bcb7a05
b691547
259c54d
d09ae58
17f3c52
b49f7ee
1e8f742
56a8303
5b0c6fd
e70f769
adcac78
92072da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Format | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
pre-commit: | ||
uses: ./.github/workflows/reusable-pre-commit.yml | ||
with: | ||
ros_distro: rolling |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Pre-commit | ||
# The pre-commit configuration is in .pre-commit-config.yaml | ||
# we don't use the pre-commit action because it doesn't support local hooks in its virtual environment | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
ros_distro: | ||
description: 'ROS2 distribution name' | ||
required: true | ||
type: string | ||
os_name: | ||
description: 'On which OS to run the linter' | ||
required: false | ||
default: 'ubuntu-latest' | ||
type: string | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ${{ inputs.os_name }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ros-tooling/setup-ros@0.7.1 | ||
- uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pre-commit | ||
key: pre-commit-3|${{ inputs.ros_distro }}|${{ hashFiles('.pre-commit-config.yaml') }} | ||
- name: Install system hooks and run pre-commit | ||
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 | ||
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Update pre-commit | ||
# Update pre-commit config and create PR if changes are detected | ||
# author: Christoph Fröhlich <christoph.froehlich@ait.ac.at> | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
auto_update_and_create_pr: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install pre-commit | ||
run: | | ||
pip install pre-commit | ||
|
||
- name: Auto-update with pre-commit | ||
run: | | ||
pre-commit autoupdate || true # Ignoring errors | ||
|
||
- name: Check for changes | ||
id: git_status | ||
run: | | ||
git diff --quiet && echo "::set-output name=changed::false" || echo "::set-output name=changed::true" | ||
|
||
- name: There are changes | ||
if: steps.git_status.outputs.changed == 'true' | ||
run: | | ||
echo "Files have changed" | ||
git diff --exit-code || true | ||
|
||
- name: No changes! | ||
if: steps.git_status.outputs.changed == 'false' | ||
run: | | ||
echo "No changes detected" | ||
|
||
- 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 commentThe 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 commentThe 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 commentThe 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 ;) |
||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: auto-update | ||
commit-message: Auto-update with pre-commit | ||
title: Bump version of pre-commit hooks | ||
body: This pull request contains auto-updated files of pre-commit config. | ||
delete-branch: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Auto Update pre-commit | ||
# Update pre-commit config and create PR if changes are detected | ||
# author: Christoph Fröhlich <christoph.froehlich@ait.ac.at> | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 * * 0' # Run every Sunday at midnight | ||
|
||
jobs: | ||
auto_update_and_create_pr: | ||
uses: ./.github/workflows/reusable-update-pre-commit.yml |
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 thepython -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 installpipx (available in apt)
and then dopipx 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?)