diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..d8199530 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,72 @@ +name: CI + +on: + # Run if someone manually presses the button in the GitHub Actions UI + workflow_dispatch: + # Run when a PR is opened or updated + pull_request: + # Run when a commit is pushed to main + push: + branches: + - main + +permissions: + # Allow reading the source code + contents: read + # Allow writing built containers to GitHub Package Registry + packages: write + +jobs: + build-ws: + name: Build colcon workspace + runs-on: ubuntu-24.04 + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Log into GitHub Container Registry so we can push an image + - name: Log in to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Build the Dockerfile and push the image to the private GitHub Container Registry on this repo + - name: Build workspace + uses: docker/build-push-action@v4 + with: + context: . + # run_id is unique to a particular run of this workflow so shouldn't clobber + tags: ghcr.io/picknikrobotics/fuse:${{ github.run_id }} + push: true + # This project is small enough that caching to GitHub Actions should be fine (it has a 10GB cache limit) + cache-to: type=gha,mode=max + cache-from: type=gha + + test-ws: + name: Test colcon workspace + needs: + # Ensure the test job runs after the build job finishes instead of attempting to run in parallel + - build-ws + runs-on: ubuntu-24.04 + container: + # Run on the Docker image we tagged and pushed to a private repo in the job above + image: ghcr.io/picknikrobotics/fuse:${{ github.run_id }} + steps: + - name: Unit test workspace + run: | + . /opt/ros/humble/setup.sh + . /colcon_ws/install/local_setup.sh + colcon test --event-handlers console_direct+ --retest-until-pass 3 + working-directory: /colcon_ws + + # `colcon test` does not actually error on failure - run `colcon test-result` to generate a summary and an error code. + - name: Display colcon test results + # Run this step even if a previous step failed + if: always() + run: colcon test-result --verbose + working-directory: /colcon_ws diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..fa52cbc7 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,29 @@ +# see https://github.com/pre-commit/action + +name: pre-commit + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Install clang-format-14 + run: sudo apt-get install clang-format-14 + - uses: pre-commit/action@v3.0.1 + id: precommit + - name: Upload pre-commit changes + if: failure() && steps.precommit.outcome == 'failure' + uses: rhaschke/upload-git-patch-action@main + with: + name: pre-commit diff --git a/.github/workflows/ros2.yml b/.github/workflows/ros2.yml new file mode 100644 index 00000000..02f23108 --- /dev/null +++ b/.github/workflows/ros2.yml @@ -0,0 +1,15 @@ +name: ros2 + +on: [push, pull_request] + +jobs: + industrial_ci: + strategy: + matrix: + env: + - {ROS_DISTRO: rolling, ROS_REPO: main} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: 'ros-industrial/industrial_ci@master' + env: ${{matrix.env}} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebe0a148..1b5c22bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -62,11 +62,6 @@ repos: - "-c" - "markdown-link-check-config.json" - - repo: https://github.com/hadolint/hadolint - rev: v2.12.0 - hooks: - - id: hadolint-docker - - repo: https://github.com/cheshirekow/cmake-format-precommit rev: v0.6.10 hooks: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..17d4305f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Docker setup that's used for CI. + +FROM osrf/ros:rolling-desktop-full + +# Install external packages. +# hadolint ignore=DL3008 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && apt-get upgrade -y && \ + apt-get install -y --no-install-recommends \ + clang-tidy \ + # use cyclonedds instead of fastdds + ros-humble-rmw-cyclonedds-cpp + +# Create the colcon ws. For now, copy the source files into the workspace +# so that we don't have to deal with cloning this repo, which is private. +WORKDIR /colcon_ws/src/fuse +COPY . . +WORKDIR /colcon_ws +# hadolint ignore=SC1091 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && apt-get upgrade -y && \ + . /opt/ros/humble/setup.sh && \ + rosdep install --from-paths src -y --ignore-src && \ + colcon build --mixin compile-commands coverage-gcc coverage-pytest + +# Set up final environment and entrypoint. +ENV RMW_IMPLEMENTATION rmw_cyclonedds_cpp +ENV CYCLONEDDS_URI /root/.ros/cyclonedds.xml +COPY dds/cyclonedds_local.xml $CYCLONEDDS_URI +COPY .clang-tidy /colcon_ws +COPY entrypoint.sh / +ENTRYPOINT [ "/entrypoint.sh" ] +RUN echo "source /entrypoint.sh" >> ~/.bashrc + +ENV SHELL /bin/bash +CMD ["/bin/bash"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..5d7f2847 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +source /opt/ros/humble/setup.bash + +if [ -f /colcon_ws/install/local_setup.bash ] +then + source /colcon_ws/install/local_setup.bash +fi + +exec "$@"