Skip to content

Commit

Permalink
Add GHA CI workflow (#3)
Browse files Browse the repository at this point in the history
* Add GHA CI workflow

Signed-off-by: Michel Hidalgo <[email protected]>

* Fix dev container image

Signed-off-by: Michel Hidalgo <[email protected]>

* Add missing using directive

Signed-off-by: Michel Hidalgo <[email protected]>

* Add .gitignore file

Signed-off-by: Michel Hidalgo <[email protected]>

---------

Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
mhidalgo-bdai authored Nov 1, 2024
1 parent 8bdc969 commit c25a438
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG ROS_DISTRO=humble
FROM ros:${ROS_DISTRO}-ros-base

ENV ROS_DISTRO=${ROS_DISTRO}

SHELL ["/bin/bash", "-c"]

# setup environment
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN DEBIAN_FRONTEND=noninteractive apt-get update -q && \
apt-get update -q && \
apt-get install -yq --no-install-recommends \
python3-pip \
python-is-python3 \
python3-argcomplete \
python3-colcon-common-extensions \
python3-colcon-mixin \
python3-pytest-cov \
python3-rosdep && \
rm -rf /var/lib/apt/lists/*

# Install dependencies for repository packages
RUN --mount=type=bind,source=.,target=/tmp/context \
apt-get update -q && rosdep update && \
rosdep install -y -i --from-paths /tmp/context && \
rm -rf /var/lib/apt/lists/*

# ROS doesn't recognize the docker shells as terminals so force colored output
ENV RCUTILS_COLORIZED_OUTPUT=1
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "proto2ros dev container",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
}
}
89 changes: 89 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: proto2ros CI

on:
pull_request:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: bdaiinstitute/proto2ros_humble

defaults:
run:
shell: bash

concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || ''}}
cancel-in-progress: true

jobs:
lint:
name: Lint proto2ros packages
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Lint sources
uses: pre-commit/[email protected]
prepare_container:
name: Prepare Humble container for tests
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
outputs:
image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Docker buildx # to workaround: https://github.com/docker/build-push-action/issues/461
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3 # https://github.com/docker/login-action
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
uses: docker/metadata-action@v5 # https://github.com/docker/metadata-action
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
id: meta

- name: Build and push Docker image (may be cached)
uses: docker/build-push-action@v5 # https://github.com/docker/build-push-action
with:
context: .
file: .devcontainer/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build_and_test:
name: Build and test proto2ros packages
runs-on: ubuntu-latest
needs: prepare_container
container:
image: ${{ needs.prepare_container.outputs.image }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and run tests
run: |
source /opt/ros/humble/setup.bash
colcon build --symlink-install
source install/setup.bash
colcon test --event-handlers console_direct+
colcon test-result --all --verbose
25 changes: 25 additions & 0 deletions .github/workflows/maintenance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: proto2ros CI maintenance

on:
schedule:
- cron: "0 0 * * 0" # once a week

env:
ORG_NAME: bdaiinstitute
IMAGE_NAME: proto2ros_humble

jobs:
clean-ghcr:
name: Prune old images from Github Container Registry
runs-on: ubuntu-latest
steps:
- name: Delete old pull request images
uses: snok/container-retention-policy@v2
with:
image-names: ${{ env.IMAGE_NAME }}
skip-tags: main
cut-off: One week ago UTC
org-name: ${{ env.ORG_NAME }}
account-type: org
token: ${{ secrets.GITHUB_TOKEN }}
token-type: github-token
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/.mypy_cache
**/__pycache__
**/*.pyc
1 change: 1 addition & 0 deletions proto2ros/proto2ros/output/templates/conversions.cpp.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ Convert({{ source }}, &{{ destination }});

namespace {{ package_name }}::conversions {

using proto2ros::conversions::Convert;
{%- for namespace in config.cpp_conversion_namespaces %}
using {{ namespace }}::Convert;
{%- endfor %}
Expand Down

0 comments on commit c25a438

Please sign in to comment.