|
14 | 14 | required: false
|
15 | 15 | default: 'ubuntu-latest'
|
16 | 16 | type: string
|
| 17 | + container: |
| 18 | + description: '(optional) Docker container to run the job in, e.g. ubuntu:noble' |
| 19 | + required: false |
| 20 | + default: '' |
| 21 | + type: string |
17 | 22 |
|
18 | 23 | jobs:
|
19 | 24 | pre-commit:
|
20 | 25 | runs-on: ${{ inputs.os_name }}
|
| 26 | + container: ${{ inputs.container }} |
| 27 | + env: |
| 28 | + # this will be src/{repo-owner}/{repo-name} |
| 29 | + path: src/${{ github.repository }} |
21 | 30 | steps:
|
22 |
| - - uses: actions/checkout@v4 |
23 |
| - - uses: ros-tooling/[email protected] |
24 |
| - - uses: actions/cache@v4 |
25 |
| - with: |
26 |
| - path: ~/.cache/pre-commit |
27 |
| - key: pre-commit-3|${{ inputs.ros_distro }}|${{ hashFiles('.pre-commit-config.yaml') }} |
28 |
| - - name: Install system hooks and run pre-commit |
29 |
| - run: | |
30 |
| - 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 |
31 |
| - source /opt/ros/${{ inputs.ros_distro }}/setup.bash |
32 |
| - python -m pip install pre-commit |
33 |
| - pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual |
| 31 | + - name: "Determine prerequisites" |
| 32 | + id: prereq |
| 33 | + run: | |
| 34 | + command -v sudo >/dev/null 2>&1 || (apt update && apt install -y sudo) |
| 35 | + DEBIAN_FRONTEND=noninteractive sudo apt update && sudo apt upgrade -y |
| 36 | + echo "need_node=$(command -v node >/dev/null 2>&1 && echo 0 || echo 1)" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + # needed for github actions, and only if a bare ubuntu image is used |
| 39 | + - uses: actions/setup-node@v4 |
| 40 | + if: ${{ steps.prereq.outputs.need_node == '1' && !env.ACT }} |
| 41 | + - name: Install node |
| 42 | + # Consider switching to https://github.com/actions/setup-node when it works |
| 43 | + # https://github.com/nektos/act/issues/973 |
| 44 | + if: ${{ steps.prereq.outputs.need_node == '1' && env.ACT }} |
| 45 | + run: | |
| 46 | + sudo apt install -y curl |
| 47 | + curl -sS https://webi.sh/node | sh |
| 48 | + echo ~/.local/opt/node/bin >> $GITHUB_PATH |
| 49 | +
|
| 50 | + # needed only if a non-ros image is used |
| 51 | + - uses: ros-tooling/[email protected] |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + path: ${{ env.path }} |
| 56 | + - uses: actions/cache@v4 |
| 57 | + with: |
| 58 | + path: ~/.cache/pre-commit |
| 59 | + key: pre-commit-3|${{ inputs.ros_distro }}|${{ hashFiles('.pre-commit-config.yaml') }} |
| 60 | + - name: Install pre-commit and system hooks |
| 61 | + shell: bash |
| 62 | + run: | |
| 63 | + 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 |
| 64 | + python3 -m venv .venv |
| 65 | + source .venv/bin/activate |
| 66 | + python3 -m pip install pre-commit |
| 67 | + - name: Run pre-commit |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + source .venv/bin/activate |
| 71 | + source /opt/ros/${{ inputs.ros_distro }}/setup.bash |
| 72 | + cd ${{ env.path }} |
| 73 | + pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual |
0 commit comments