Skip to content

Commit

Permalink
add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygerardmoore committed Sep 23, 2024
1 parent df2c89d commit d13d655
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 5 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
id: precommit
- name: Upload pre-commit changes
if: failure() && steps.precommit.outcome == 'failure'
uses: rhaschke/upload-git-patch-action@main
with:
name: pre-commit
15 changes: 15 additions & 0 deletions .github/workflows/ros2.yml
Original file line number Diff line number Diff line change
@@ -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}}
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit d13d655

Please sign in to comment.