Skip to content

Commit

Permalink
Add GitHub actions CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Aug 22, 2023
1 parent 2aa762d commit 1f3b2e7
Show file tree
Hide file tree
Showing 15 changed files with 1,767 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/check_style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

# Given a set of commits current script checks the style based on clang_format
# on the list of changed files that exist in the commits.
#
# Script should be called from a travis.yml file.

# Functions
######################

# This is run by travis automatically from the root of the project

set +e
set +x

DIRS_IN="modules"
DIRS_OUT="demos docs modules/mp2p_icp/3rdparty"
LANGS=cpp
FORMAT_CODE_BIN="scripts/clang_git_format/format_code.py"

function lint() {

# Get list of changed files for lint to run on. Grep only .h, .cpp files and
# mind the DIRS_IN, DIRS_OUT vars

# Following command fails if you "git commit --amend" - Works correctly on
# standard commits
echo "commit_range: $TRAVIS_COMMIT_RANGE"
changed_files=$(git diff --name-only $TRAVIS_COMMIT_RANGE)
printf "Summary of changed files:\n\n${changed_files}\n\n"

# include
regexp_in=
for i in $DIRS_IN; do
if [ -n "${regexp_in}" ]; then
regexp_in="${regexp_in}\|${i}"
else
regexp_in="${i}"
fi
done

# exclude
regexp_out=
for i in $DIRS_OUT; do
if [ -n "${regexp_out}" ]; then
regexp_out="${regexp_out}\|${i}"
else
regexp_out="${i}"
fi
done

echo "regexp_in: ${regexp_in}"
echo "regexp_out: ${regexp_out}"

valid_files=$(echo ${changed_files} \
| xargs -d' ' -n 1 \
| grep -i -e "${regexp_in}" \
| grep -v "${regexp_out}" \
| grep -ie ".*\.h$\|.*\.cpp")


printf "Valid files for lint:\n\t${valid_files}\n"
if [ -n "${valid_files}" ]; then
${FORMAT_CODE_BIN} -g . --lint_files ${valid_files}
else
true
fi
exit $?

}

function lint_all() {

${FORMAT_CODE_BIN} -g . --lang ${LANGS} \
-o ${DIRS_OUT} -i ${DIRS_IN} \
-l

exit $?
}

lint_all
3 changes: 3 additions & 0 deletions .github/python_clang_format_reqs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Requisites for the clang-format linter script
argparse
colorlog
73 changes: 73 additions & 0 deletions .github/workflows/build-ros.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Based on GTSAM file (by @ProfFan)
name: CI ROS

on: [push, pull_request]

jobs:
test_docker: # On Linux, iterates on all ROS 1 and ROS 2 distributions.
runs-on: ubuntu-latest
env:
DEBIAN_FRONTEND: noninteractive
strategy:
matrix:
# Github Actions requires a single row to be added to the build matrix.
# See https://help.github.com/en/articles/workflow-syntax-for-github-actions.
ros_distribution:
- noetic
- humble
- iron
- rolling

# Define the Docker image(s) associated with each ROS distribution.
# The include syntax allows additional variables to be defined, like
# docker_image in this case. See documentation:
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-configurations-in-a-matrix-build
#
# Platforms are defined in REP 3 and REP 2000:
# https://ros.org/reps/rep-0003.html
# https://ros.org/reps/rep-2000.html
include:
# Noetic Ninjemys (May 2020 - May 2025)
- docker_image: ubuntu:focal
ros_distribution: noetic
ros_version: 1

# Humble Hawksbill (May 2022 - May 2027)
- docker_image: ubuntu:jammy
ros_distribution: humble
ros_version: 2

# Iron Irwini (May 2023 - November 2024)
- docker_image: ubuntu:jammy
ros_distribution: iron
ros_version: 2

# Rolling Ridley (No End-Of-Life)
- docker_image: ubuntu:jammy
ros_distribution: rolling
ros_version: 2

container:
image: ${{ matrix.docker_image }}

steps:
- name: Checkout
run: |
apt-get -y update
apt-get -y install git
git clone https://github.com/$GITHUB_REPOSITORY.git --recursive "$GITHUB_WORKSPACE"
- name: setup ROS environment
uses: ros-tooling/setup-ros@v0.7
with:
required-ros-distributions: ${{ matrix.ros_distribution }}

- name: Install rosdep dependencies
run: |
rosdep update
rosdep install --from-paths . --ignore-src -r -y
- name: Build with colcon
run: |
source /opt/ros/*/setup.bash
colcon build --symlink-install
40 changes: 40 additions & 0 deletions .github/workflows/check-clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI Check clang-format

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
# Github Actions requires a single row to be added to the build matrix.
# See https://help.github.com/en/articles/workflow-syntax-for-github-actions.
name: [
clang-format-check
]

include:
- name: clang-format-check
os: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master

- name: Git submodule
run: |
git submodule sync
git submodule update --init --recursive
- name: Install Dependencies
run: |
sudo apt install clang-format-11 -yq
pip3 install --user -r .github/python_clang_format_reqs.txt
- name: Check code style
run: |
echo "TASK=lint_all" >> $GITHUB_ENV
bash .github/check_style.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI Check clang-format](https://github.com/MOLAorg/mola/actions/workflows/check-clang-format.yml/badge.svg)](https://github.com/MOLAorg/mola/actions/workflows/check-clang-format.yml)
[![CI ROS](https://github.com/MOLAorg/mola/actions/workflows/build-ros.yml/badge.svg)](https://github.com/MOLAorg/mola/actions/workflows/build-ros.yml)
[![CircleCI](https://img.shields.io/circleci/build/gh/MOLAorg/mola/master.svg)](https://circleci.com/gh/MOLAorg/mola) [![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://docs.mola-slam.org/latest/)


Expand Down
40 changes: 40 additions & 0 deletions scripts/clang_git_format/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

build/
Loading

0 comments on commit 1f3b2e7

Please sign in to comment.