Skip to content

Commit

Permalink
Add pre commit (#75)
Browse files Browse the repository at this point in the history
Changed vscode extentions to precommit

---------

Signed-off-by: Jakub Delicat <[email protected]>
  • Loading branch information
delihus authored Oct 24, 2023
1 parent c92fb13 commit 20fec79
Show file tree
Hide file tree
Showing 47 changed files with 272 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# TODO: specify bump command and remove this description

Bump version workflow is triggered when PR is closed, it bumps version and triggers docker build that will be tagged with version number. To use it you have to specify bump type, available commands: `bump::patch`, `bump::minor` and `bump::major` (simply leave one of them in PR description and remove this description).
Bump version workflow is triggered when PR is closed, it bumps version and triggers docker build that will be tagged with version number. To use it you have to specify bump type, available commands: `bump::patch`, `bump::minor` and `bump::major` (simply leave one of them in PR description and remove this description).
13 changes: 8 additions & 5 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
name: Black python lint

on:
workflow_call:
push:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: --line-length=99
111 changes: 55 additions & 56 deletions .github/workflows/bump_version.yaml
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
---
name: Trigger rosbot-docker to build an image and bump version

on:
workflow_dispatch:
inputs:
name:
description: "Version to bump (major, minor, patch)"
default: "patch"
required: true
pull_request:
branches: humble
types: [closed]
workflow_dispatch:
inputs:
name:
description: Version to bump (major, minor, patch)
default: patch
required: true
pull_request:
branches: humble
types: [closed]

jobs:
get-bump:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Get version bump
runs-on: ubuntu-22.04
outputs:
bump: ${{ env.BUMP }}
steps:
- if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
get-bump:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Get version bump
id: get-version-bump
uses: husarion-ci/[email protected]
- if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
run: echo "BUMP=${{ steps.get-version-bump.outputs.bump }}" >> $GITHUB_ENV
- if: github.event_name == 'workflow_dispatch'
run: echo "BUMP=${{ github.event.inputs.name }}" >> $GITHUB_ENV
runs-on: ubuntu-22.04
outputs:
bump: ${{ env.BUMP }}
steps:
- if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
name: Get version bump
id: get-version-bump
uses: husarion-ci/[email protected]
- if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
run: echo "BUMP=${{ steps.get-version-bump.outputs.bump }}" >> $GITHUB_ENV
- if: github.event_name == 'workflow_dispatch'
run: echo "BUMP=${{ github.event.inputs.name }}" >> $GITHUB_ENV

catkin-release:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Bump version
runs-on: ubuntu-22.04
needs: get-bump
outputs:
new_version: ${{ steps.catkin-release.outputs.new_version }}
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Catkin release
id: catkin-release
uses: husarion-ci/[email protected]
with:
bump: ${{ needs.get-bump.outputs.bump }}
github_token: ${{ secrets.GH_PAT }}
git_user: action-bot
git_email: [email protected]
catkin-release:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Bump version
runs-on: ubuntu-22.04
needs: get-bump
outputs:
new_version: ${{ steps.catkin-release.outputs.new_version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Catkin release
id: catkin-release
uses: husarion-ci/[email protected]
with:
bump: ${{ needs.get-bump.outputs.bump }}
github_token: ${{ secrets.GH_PAT }}
git_user: action-bot
git_email: [email protected]

build-and-push-docker-image:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Create new docker image
runs-on: ubuntu-22.04
needs: catkin-release
steps:
- name: trigger the endpoint
run: >
curl -X POST
-H "Accept: application/vnd.github+json"
-H "Authorization: Bearer ${{ secrets.GH_PAT }}"
https://api.github.com/repos/husarion/rosbot-docker/dispatches
-d '{"event_type":"ros-package-update"}'
build-and-push-docker-image:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Create new docker image
runs-on: ubuntu-22.04
needs: catkin-release
steps:
- name: trigger the endpoint
run: >
curl -X POST
-H "Accept: application/vnd.github+json"
-H "Authorization: Bearer ${{ secrets.GH_PAT }}"
https://api.github.com/repos/husarion/rosbot-docker/dispatches
-d '{"event_type":"ros-package-update"}'
35 changes: 17 additions & 18 deletions .github/workflows/industrial_ci.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---
name: Industrial CI
on:
workflow_call:
push:
workflow_call:
push:

jobs:
industrial_ci:
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [humble]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Clone installation requirements
shell: bash
run : python3 -m pip install -U vcstool &&
vcs import . < ./rosbot/rosbot_hardware.repos &&
vcs import . < ./rosbot/rosbot_simulation.repos
- uses: ros-industrial/industrial_ci@master
env:
ROS_DISTRO: ${{matrix.ROS_DISTRO}}
industrial_ci:
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [humble]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Clone installation requirements
shell: bash
run: python3 -m pip install -U vcstool && vcs import . < ./rosbot/rosbot_hardware.repos && vcs import . < ./rosbot/rosbot_simulation.repos
- uses: ros-industrial/industrial_ci@master
env:
ROS_DISTRO: ${{matrix.ROS_DISTRO}}
19 changes: 10 additions & 9 deletions .github/workflows/spellcheck.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: Spellcheck Action

on:
workflow_call:
push:
workflow_call:
push:

jobs:
build:
name: Spellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: rojopolis/[email protected]
name: Spellcheck
build:
name: Spellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: rojopolis/[email protected]
name: Spellcheck
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.vscode
*.pyc

# ROS 2 build folders
build
install
log
*.pyc

# ROSbots submodules
rosbot_hardware_interfaces/
Expand Down
70 changes: 70 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-xml
- id: check-added-large-files
- id: check-ast
- id: check-json
- id: name-tests-test
files: ^.*\/test\/.*$
args: [--pytest-test-first]

- repo: https://github.com/codespell-project/codespell
rev: v1.16.0
hooks:
- id: codespell
name: codespell
description: Checks for common misspellings in text files.
entry: codespell *
language: python
types: [text]

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.1
hooks:
- id: yamlfmt
files: ^.github|./\.yaml

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

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: ["--ignore=E501"] # ignore too long line, black checks it

- repo: local
hooks:
- id: ament_lint_cmake
name: ament_lint_cmake
description: Check format of CMakeLists.txt files.
entry: ament_lint_cmake
language: system
files: CMakeLists\.txt$

- repo: local
hooks:
- id: ament_copyright
name: ament_copyright
description: Check if copyright notice is available in all files.
stages: [commit]
entry: ament_copyright
language: system

# Docs - RestructuredText hooks
- repo: https://github.com/PyCQA/doc8
rev: v1.1.1
hooks:
- id: doc8
args: ['--max-line-length=100', '--ignore=D001']
exclude: ^.*\/CHANGELOG\.rst/.*$
2 changes: 1 addition & 1 deletion .pyspelling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ matrix:
- .wordlist.txt

pipeline:
- pyspelling.filters.xml
- pyspelling.filters.xml
4 changes: 3 additions & 1 deletion .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ Delicat
Jakub
Bence
Palacios
env
env
pids
pgrep
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,28 @@ ros2 launch rosbot_gazebo simulation.launch.py

## Testing package

### pre-commit
[pre-commit configuration](.pre-commit-config.yaml) prepares plenty of tests helping for developing and contributing. Usage:

```bash
# install pre-commit
pip install pre-commit

# initialize pre-commit workspace
pre-commit install

# manually run tests
pre-commit run -a
```

After initialization [pre-commit configuration](.pre-commit-config.yaml) will applied on every commit.

### Industrial CI
```
colcon test
```

> [!NOTE]
> [!NOTE]
> Command `colcon test` does not build the code. Remember to build your code after changes.
If tests finish with errors print logs:
Expand Down
2 changes: 1 addition & 1 deletion rosbot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ project(rosbot)

find_package(ament_cmake REQUIRED)

ament_package()
ament_package()
2 changes: 1 addition & 1 deletion rosbot/rosbot_hardware.repos
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ repositories:
rosbot_controllers:
type: git
url: https://github.com/husarion/rosbot_controllers
version: main
version: main
2 changes: 1 addition & 1 deletion rosbot/rosbot_simulation.repos
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repositories:
type: git
url: https://github.com/ros-controls/gz_ros2_control.git
# on branch humble hardware isn't activated
# recently on master API breaking change was introduced, it is necessay to use commit before this change
# recently on master API breaking change was introduced, it is necessary to use commit before this change
version: b296ff2f5c3758b637a70bd496fe6ed875ab03ce

husarion/husarion_office_gz:
Expand Down
3 changes: 1 addition & 2 deletions rosbot_bringup/launch/bringup.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def generate_launch_description():
"mecanum",
default_value="False",
description=(
"Whether to use mecanum drive controller "
"(otherwise diff drive controller is used)"
"Whether to use mecanum drive controller (otherwise diff drive controller is used)"
),
)

Expand Down
14 changes: 14 additions & 0 deletions rosbot_bringup/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 Husarion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from glob import glob
from setuptools import find_packages, setup
Expand Down
Loading

0 comments on commit 20fec79

Please sign in to comment.