-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (70 loc) · 2.75 KB
/
reusable-pre-commit.yml
File metadata and controls
75 lines (70 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Reusable pre-commit
# The pre-commit configuration is in .pre-commit-config.yaml
# OG author: Christoph Fröhlich <christoph.froehlich@ait.ac.at>[ROS2 Control CI]
# UoE editor: Alejandro Bordallo <alex.bordallo@ed.ac.uk>
on:
workflow_call:
inputs:
ros_distro:
description: 'ROS2 distribution name'
required: true
type: string
jobs:
pre-commit:
runs-on: ubuntu-latest
container: ros:${{ inputs.ros_distro }}
env:
# this will be src/{repo-owner}/{repo-name}
path: src/${{ github.repository }}
steps:
- name: "Determine prerequisites"
id: prereq
run: |
command -v sudo >/dev/null 2>&1 || (apt update && apt install -y sudo)
sudo apt update
echo "need_node=$(command -v node >/dev/null 2>&1 && echo 0 || echo 1)" >> $GITHUB_OUTPUT
echo "need_ros2=$(if [ -d "/opt/ros/${{ inputs.ros_distro }}" ]; then echo 0; else echo 1; fi)" \
>> $GITHUB_OUTPUT
# needed for github actions, and only if a bare ubuntu image is used
- uses: actions/setup-node@v4
if: ${{ steps.prereq.outputs.need_node == '1' && !env.ACT }}
- name: Install node
# Consider switching to https://github.com/actions/setup-node when it works
# https://github.com/nektos/act/issues/973
if: ${{ steps.prereq.outputs.need_node == '1' && env.ACT }}
run: |
sudo apt install -y curl
curl -sS https://webi.sh/node | sh
echo ~/.local/opt/node/bin >> $GITHUB_PATH
# needed only if a non-ros image is used
- uses: ros-tooling/setup-ros@0.7.10
if: ${{ steps.prereq.outputs.need_ros2 == '1' }}
with:
use-ros2-testing: true
- uses: actions/checkout@v4
with:
fetch-depth: 0
path: ${{ env.path }}
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ inputs.ros_distro }}|${{ hashFiles( format('{0}/.pre-commit-config.yaml', env.path) ) }}
- name: Install pre-commit and system hooks
shell: bash
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 \
python3-venv
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pre-commit
- name: Run pre-commit
shell: bash
run: |
source .venv/bin/activate
source /opt/ros/${{ inputs.ros_distro }}/setup.bash
cd ${{ env.path }}
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual