Skip to content

Commit

Permalink
ci: use caching from docker to run test in CI (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
domire8 authored Apr 2, 2024
1 parent 7855e68 commit 5747b2d
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 200 deletions.
5 changes: 0 additions & 5 deletions .github/actions/build-test-protocol/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/build-test-protocol/action.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/actions/build-test-protocol/entrypoint.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/build-test-python/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/build-test-python/action.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/actions/build-test-python/entrypoint.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/build-test/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions .github/actions/build-test/action.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/actions/build-test/entrypoint.sh

This file was deleted.

75 changes: 20 additions & 55 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Build and Test

# Run workflow on pushes to main and develop branches, on any pull request, or by manual dispatch
on:
push:
branches:
Expand All @@ -9,15 +8,14 @@ on:
pull_request:
workflow_dispatch:

# Define the build test jobs for each configuration
jobs:

check-contribution:
name: Check if changelog and version have been updated
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check contributions
if: ${{ github.event.pull_request.base.sha }}
Expand All @@ -39,7 +37,6 @@ jobs:
fi
shell: bash

# check if jobs can be skipped
check-skippable-changes:
name: Check skippable changes
runs-on: ubuntu-latest
Expand All @@ -54,62 +51,30 @@ jobs:
paths_ignore: '["**.md", ".**/**", "**.gitignore"]'
skip_after_successful_duplicate: 'true'

build-test-debug:
build-test:
needs: check-skippable-changes
if: ${{ needs.check-skippable-changes.outputs.skip != 'true' }}
runs-on: ubuntu-latest
name: Debug configuration test
name: Run tests
steps:
# First check out the repository
- name: Checkout
uses: actions/checkout@v3
# Load the repository build-test action
- name: Build and Test
uses: ./.github/actions/build-test
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Cache for Docker
uses: actions/cache@v3
with:
configuration: Debug

build-test-release:
needs: check-skippable-changes
if: ${{ needs.check-skippable-changes.outputs.skip != 'true' }}
runs-on: ubuntu-latest
name: Release configuration test
steps:
# First check out the repository
- name: Checkout
uses: actions/checkout@v3
# Load the repository build-test action
path: build-cache
key: ${{ runner.os }}-build-cache-${{ hashFiles('./') }}
- name: Inject build-cache into docker
uses: reproducible-containers/buildkit-cache-dance@v2.1.2
with:
cache-source: build-cache
cache-target: /build
- name: Build and Test
uses: ./.github/actions/build-test
uses: docker/build-push-action@v5
with:
configuration: Release

build-test-python:
needs:
- check-skippable-changes
- build-test-release
if: ${{ needs.check-skippable-changes.outputs.skip != 'true' }}
runs-on: ubuntu-latest
name: Python bindings test
steps:
# First check out the repository
- name: Checkout
uses: actions/checkout@v3
# Load the repository build-test-python action
- name: Build and Test Python
uses: ./.github/actions/build-test-python

build-test-protocol:
needs:
- check-skippable-changes
- build-test-release
if: ${{ needs.check-skippable-changes.outputs.skip != 'true' }}
runs-on: ubuntu-latest
name: Protocol library test
steps:
# First check out the repository
- name: Checkout
uses: actions/checkout@v3
# Load the repository build-test-python action
- name: Build and Test Protocol
uses: ./.github/actions/build-test-protocol
context: .
target: python-test
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Release Versions:

## Upcoming changes (in development)

- ci: use caching from docker to run tests in CI (#429)
- feat: add IO states to state representation (proto) (#172)
- feat: add IO states to state representation (cpp) (#158)
- build: add missing licenses (#170)
Expand Down
65 changes: 30 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ xargs -a /tmp/new-packages.txt dpkg-query -L \
# this root can then be copied to / to install everything globally or use LD_LIBRARY_PATH to use it locally
HEREDOC

FROM base as dep-base
FROM base as base-dependencies
ARG TARGETPLATFORM
ARG CACHEID
COPY dependencies/base_dependencies.cmake CMakeLists.txt
RUN --mount=type=cache,target=./build,id=cmake-osqp-${TARGETPLATFORM}-${CACHEID},uid=1000 \
RUN --mount=type=cache,target=/build,id=cmake-base-deps-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build && cmake --install build --prefix /tmp/deps

FROM base as dep-pinocchio
FROM base as pinocchio-dependencies
COPY --from=apt-dependencies /tmp/apt /
COPY --from=dep-base /tmp/deps /usr
COPY --from=base-dependencies /tmp/deps /usr
ARG TARGETPLATFORM
ARG CACHEID
ARG PINOCCHIO_TAG=v2.9.0
Expand All @@ -94,13 +94,13 @@ ARG HPP_FCL_TAG=v1.8.1
# * `pinocchio` doesn't provide an include directory we can easily plug into `target_include_directories` and thus needs to be installed first
# * `pinocchio` uses hacks relying on undocumented CMake quirks which break if you use `FetchContent`
# FIXME: it needs `CMAKE_INSTALL_PREFIX` and `--prefix` because it doesn't install to the right place otherwise
RUN --mount=type=cache,target=./hpp-fcl,id=cmake-hpp-fcl-src-${HPP_FCL_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
--mount=type=cache,target=./build,id=cmake-hpp-fcl-${HPP_FCL_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
RUN --mount=type=cache,target=/hpp-fcl,id=cmake-hpp-fcl-src-${HPP_FCL_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
--mount=type=cache,target=/build,id=cmake-hpp-fcl-${HPP_FCL_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
if [ ! -f hpp-fcl/CMakeLists.txt ]; then rm -rf hpp-fcl/* && git clone --depth 1 -b ${HPP_FCL_TAG} --recursive https://github.com/humanoid-path-planner/hpp-fcl; fi \
&& cmake -B build -S hpp-fcl -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON_INTERFACE=OFF -DCMAKE_INSTALL_PREFIX=/tmp/deps \
&& cmake --build build --target all install
RUN --mount=type=cache,target=./pinocchio,id=cmake-pinocchio-src-${PINOCCHIO_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
--mount=type=cache,target=./build,id=cmake-pinocchio-${PINOCCHIO_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
RUN --mount=type=cache,target=/pinocchio,id=cmake-pinocchio-src-${PINOCCHIO_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
--mount=type=cache,target=/build,id=cmake-pinocchio-${PINOCCHIO_TAG}-${TARGETPLATFORM}-${CACHEID},uid=1000 \
if [ ! -f pinocchio/CMakeLists.txt ]; then rm -rf pinocchio/* && git clone --depth 1 -b ${PINOCCHIO_TAG} --recursive https://github.com/stack-of-tasks/pinocchio; fi \
&& cmake -B build -S pinocchio -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON_INTERFACE=OFF -DBUILD_WITH_COLLISION_SUPPORT=ON -DCMAKE_INSTALL_PREFIX=/tmp/deps \
&& cmake --build build --target all install
Expand All @@ -111,20 +111,16 @@ FROM base as dependencies
ARG TARGETPLATFORM
ARG CACHEID
# Needed to build `osqp-eigen`
COPY --from=dep-base /tmp/deps /usr
COPY --from=base-dependencies /tmp/deps /usr
COPY dependencies/dependencies.cmake CMakeLists.txt
RUN --mount=type=cache,target=./build,id=cmake-deps-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake -B build -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build \
&& cmake --install build --prefix /tmp/deps
COPY --from=dep-base /tmp/deps /tmp/deps
COPY --from=dep-pinocchio /tmp/deps /tmp/deps
RUN --mount=type=cache,target=/build,id=cmake-deps-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake -B build -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release && cmake --build build && cmake --install build --prefix /tmp/deps
COPY --from=base-dependencies /tmp/deps /tmp/deps
COPY --from=pinocchio-dependencies /tmp/deps /tmp/deps

FROM base as code
WORKDIR /src
COPY --from=apt-dependencies /tmp/apt /
COPY --from=dependencies /tmp/deps /usr
COPY . /src

FROM code as development
# create and configure a new user
Expand Down Expand Up @@ -152,61 +148,60 @@ RUN ( \
COPY ./docker/sshd_entrypoint.sh /sshd_entrypoint.sh
RUN chmod 744 /sshd_entrypoint.sh

RUN chown -R ${USER}:${USER} /src
RUN mkdir /guidelines && cd /guidelines \
&& wget https://raw.githubusercontent.com/aica-technology/.github/v0.9.0/guidelines/.clang-format

USER ${USER}
WORKDIR /src
COPY --chown=${USER}:${USER} . .

FROM code as build
ARG TARGETPLATFORM
ARG CACHEID
RUN --mount=type=cache,target=./build,id=cmake-${TARGETPLATFORM}-${CACHEID},uid=1000 \
COPY licenses licenses
COPY protocol protocol
COPY source source
COPY CMakeLists.txt CMakeLists.txt
RUN --mount=type=cache,target=/build,id=cmake-build-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build

FROM build as cpp-test
ARG TARGETPLATFORM
ARG CACHEID
RUN --mount=type=cache,target=./build,id=cmake-${TARGETPLATFORM}-${CACHEID},uid=1000 \
RUN --mount=type=cache,target=/build,id=cmake-build-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake -B build -DBUILD_TESTING=ON && cd build && make && CTEST_OUTPUT_ON_FAILURE=1 make test

FROM build as install
ARG TARGETPLATFORM
ARG CACHEID
RUN --mount=type=cache,target=./build,id=cmake-${TARGETPLATFORM}-${CACHEID},uid=1000 \
RUN --mount=type=cache,target=/build,id=cmake-build-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake --install build --prefix /tmp/cl

FROM base as python
FROM code as python
ARG TARGETPLATFORM
ARG CACHEID
COPY --from=apt-dependencies /tmp/apt /
COPY --from=dependencies /tmp/deps /usr
COPY --from=install /tmp/cl /usr
COPY --chown=${USER}:${USER} ./python/include /python/include
COPY --chown=${USER}:${USER} ./python/source /python/source
COPY --chown=${USER}:${USER} ./python/pyproject.toml ./python/setup.py /python/
RUN --mount=type=cache,target=${HOME}/.cache,id=pip-${TARGETPLATFORM}-${CACHEID},uid=1000 \
COPY ./python/include /python/include
COPY ./python/source /python/source
COPY ./python/pyproject.toml ./python/setup.py /python/
RUN --mount=type=cache,target=/.cache,id=pip-${TARGETPLATFORM}-${CACHEID},uid=1000 \
python3 -m pip install --prefix=/tmp/python /python
RUN mv /tmp/python/local /tmp/python-usr

FROM cpp-test as python-test
ARG TARGETPLATFORM
ARG CACHEID
RUN pip install pytest
COPY --from=install /tmp/cl /usr
COPY --from=python /tmp/python-usr /usr
COPY --chown=${USER}:${USER} ./python/test /test
COPY ./python/test /test
RUN pytest /test

FROM base as python-stubs
FROM code as python-stubs
ARG TARGETPLATFORM
ARG CACHEID
COPY --from=apt-dependencies /tmp/apt /
COPY --from=dependencies /tmp/deps /usr
COPY --from=install /tmp/cl /usr
COPY --from=python /tmp/python-usr /usr
RUN pip install pybind11-stubgen
RUN --mount=type=cache,target=${HOME}/.cache,id=pip-${TARGETPLATFORM}-${CACHEID},uid=1000 \
RUN --mount=type=cache,target=/.cache,id=pip-${TARGETPLATFORM}-${CACHEID},uid=1000 \
<<HEREDOC
for PKG in state_representation dynamical_systems robot_model controllers clproto; do
python3 -c "import ${PKG}"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.3.7
7.3.8
2 changes: 1 addition & 1 deletion demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(control_libraries 7.3.7 CONFIG REQUIRED)
find_package(control_libraries 7.3.8 CONFIG REQUIRED)

set(DEMOS_SCRIPTS
task_space_control_loop
Expand Down
Loading

0 comments on commit 5747b2d

Please sign in to comment.