Skip to content

Commit

Permalink
Create reusable-pre-commit.yml and add workflow for it (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Exner (fexner) <exner@fzi.de>
  • Loading branch information
christophfroehlich and fmauch authored Feb 21, 2024
1 parent 3dfe127 commit ec7c2ac
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 15 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci-pre-commit.yml
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
33 changes: 33 additions & 0 deletions .github/workflows/reusable-pre-commit.yml
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
2 changes: 0 additions & 2 deletions .github/workflows/reusable-ros-tooling-source-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
env:
# this will be src/{repo-owner}/{repo-name}
path: src/${{ github.repository }}
strategy:
fail-fast: false
steps:
- uses: ros-tooling/setup-ros@0.7.1
with:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/reusable-update-pre-commit.yml
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
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
12 changes: 12 additions & 0 deletions .github/workflows/update-pre-commit.yml
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
30 changes: 18 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -36,7 +36,7 @@ repos:

# Python hooks
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand All @@ -49,40 +49,38 @@ repos:
args: ["--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D404"]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.2.0
hooks:
- id: black
args: ["--line-length=99"]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
args: ["--extend-ignore=E501"]

# CPP hooks
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.6
rev: v17.0.6
hooks:
- id: clang-format
args: ['-fallback-style=none', '-i']

- repo: local
hooks:
- id: ament_cppcheck
name: ament_cppcheck
description: Static code analysis of C/C++ files.
stages: [commit]
entry: ament_cppcheck
entry: env AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1 ament_cppcheck
language: system
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$

# Maybe use https://github.com/cpplint/cpplint instead
- repo: local
hooks:
- id: ament_cpplint
name: ament_cpplint
description: Static code analysis of C/C++ files.
stages: [commit]
entry: ament_cpplint
language: system
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
Expand All @@ -94,7 +92,6 @@ repos:
- id: ament_lint_cmake
name: ament_lint_cmake
description: Check format of CMakeLists.txt files.
stages: [commit]
entry: ament_lint_cmake
language: system
files: CMakeLists\.txt$
Expand All @@ -105,7 +102,6 @@ repos:
- id: ament_copyright
name: ament_copyright
description: Check if copyright notice is available in all files.
stages: [commit]
entry: ament_copyright
language: system

Expand All @@ -128,8 +124,18 @@ repos:
# Spellcheck in comments and docs
# skipping of *.svg files is not working...
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.6
hooks:
- id: codespell
args: ['--write-changes']
exclude: CHANGELOG\.rst|\.(svg|pyc)$

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-github-workflows
args: ["--verbose"]
- id: check-github-actions
args: ["--verbose"]
- id: check-dependabot
args: ["--verbose"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This repository holds reusable workflows for CI of the ros2_control framework.

It also build the full ros2_control stack once per day.
It also builds the full ros2_control stack once per day.

[![Rolling Stack Build](https://github.com/ros-controls/ros2_control_ci/actions/workflows/rolling-binary-build.yml/badge.svg)](https://github.com/ros-controls/ros2_control_ci/actions/workflows/rolling-binary-build.yml)
[![Iron Stack Build](https://github.com/ros-controls/ros2_control_ci/actions/workflows/iron-binary-build.yml/badge.svg)](https://github.com/ros-controls/ros2_control_ci/actions/workflows/iron-binary-build.yml)
Expand Down

0 comments on commit ec7c2ac

Please sign in to comment.