Skip to content

Commit

Permalink
Merge pull request #2 from F-WuTS/feature/ci-packing
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-heiss authored Sep 26, 2024
2 parents aaa7b50 + 5a591cf commit d5885d4
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github
ci/Dockerfile
38 changes: 0 additions & 38 deletions .github/workflows/ci.yaml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Package

on:
push:
tags:
- "*"

jobs:
package:
runs-on: ubuntu-24.04
strategy:
matrix:
platform: [linux/arm64/v8]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/arm64

- name: Prepare container
run: docker buildx build -f ci/Dockerfile . -t libcreate --platform ${{ matrix.platform }} --load
- name: Build
run: docker run --platform ${{ matrix.platform }} -v ./output:/libcreate/_packages libcreate
- name: Push deb to compREP
uses: cpina/github-action-push-to-another-repository@main
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
source-directory: "output/"
target-directory: "debs/libcreate/"
destination-github-username: "F-WuTS"
destination-repository-name: "compREP"
target-branch: master
30 changes: 30 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and test

on:
push:
branches: ["master"]
pull_request:

env:
BUILD_TYPE: Release

jobs:
test:
runs-on: ubuntu-24.04

steps:
- name: Install dependencies
run: |
sudo apt install build-essential cmake git libboost-system-dev libboost-thread-dev file libgtest-dev googletest
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
#########
# Setup #
#########

cmake_minimum_required(VERSION 3.25)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(Versioning)

########
# Main #
########

# After installation this project can be found by 'find_package' command:
#
# find_package(libcreate REQUIRED)
# include_directores(${libcreate_INCLUDE_DIRS})
# target_link_libraries(... ${libcreate_LIBRARIES})
#

cmake_minimum_required(VERSION 2.8.12)
project(libcreate)
project(
libcreate
VERSION ${TAG_VERSION_MAJOR}.${TAG_VERSION_MINOR}.${TAG_VERSION_PATCH}
)

add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wall -Wextra -Wpedantic -Werror)

set(PACKAGE_VERSION 3.0.0)
set(PACKAGE_VERSION ${TAG_VERSION_MAJOR}.${TAG_VERSION_MINOR}.${TAG_VERSION_PATCH})

option(LIBCREATE_BUILD_TESTS "Enable the build of tests." ON)

Expand Down Expand Up @@ -203,3 +219,9 @@ if(LIBCREATE_BUILD_TESTS AND ${GTEST_FOUND})
else()
message("No GTest installation found. Skipping tests.")
endif()

#############
# Packaging #
#############

include(Packing)
14 changes: 14 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM debian:bookworm

RUN apt update && \
apt install -y \
build-essential cmake git file tree \
libboost-system-dev libboost-thread-dev \
libgtest-dev googletest && \
rm -rf /var/lib/apt/lists/*

WORKDIR /libcreate
COPY . .

WORKDIR /libcreate/build
ENTRYPOINT ["/bin/bash", "/libcreate/ci/entrypoint.sh"]
15 changes: 15 additions & 0 deletions ci/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

cmake -B /libcreate/build -S /libcreate -DCMAKE_BUILD_TYPE=Release
cmake --build /libcreate/build --config Release
ctest -C Release --output-on-failure
cpack --build /libcreate/build -G DEB

debs=(/libcreate/_packages/*.deb)
cp "${debs[0]}" /tmp/libcreate.deb
dpkg-deb -R /tmp/libcreate.deb /tmp/libcreate
tree /tmp/libcreate
41 changes: 41 additions & 0 deletions cmake/Packing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# these are cache variables, so they could be overwritten with -D,
set(CPACK_PACKAGE_NAME ${PROJECT_NAME}
CACHE STRING "The resulting package name"
)
# which is useful in case of packing only selected components instead of the whole thing
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ library for interfacing with iRobot's Create 1 and 2"
CACHE STRING "Package description for the package metadata"
)
set(CPACK_PACKAGE_VENDOR "Verein zur Förderung von Jugendlichen durch Robotikwettbewerbe")

set(CPACK_VERBATIM_VARIABLES YES)

set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
SET(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_SOURCE_DIR}/_packages")

set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})

set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "comp-air dev team")

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")

# Discover and set dependencies correcly
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES)

# The installation path directory should have 0755 permissions
set(
CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)

# package name for deb. If set, then instead of some-application-0.9.2-Linux.deb
# you'll get some-application_0.9.2_amd64.deb (note the underscores too)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

include(CPack)
31 changes: 31 additions & 0 deletions cmake/Versioning.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
find_package(Git)

if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
OUTPUT_VARIABLE TAG_VERSION
RESULT_VARIABLE ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(DEFINED ENV{GITHUB_REF} AND ENV{GITHUB_REF_TYPE} EQUAL "tag")
set(TAG_VERSION $ENV{GITHUB_REF})
message(STATUS "Extracted version from GITHUB_REF")
endif()

if(TAG_VERSION STREQUAL "")
set(TAG_VERSION 0.0.0)
message(WARNING "Failed to determine version from Git tags. Using default version \"${TAG_VERSION}\".")
endif()

message(STATUS "Project version: ${TAG_VERSION}")

# Split into major, minor, patch
string(
REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)"
TAG_VERSION_MATCH ${TAG_VERSION}
)
set(TAG_VERSION_MAJOR ${CMAKE_MATCH_1})
set(TAG_VERSION_MINOR ${CMAKE_MATCH_2})
set(TAG_VERSION_PATCH ${CMAKE_MATCH_3})
endif()
1 change: 1 addition & 0 deletions include/create/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define CREATE_PACKET_H

#include <mutex>
#include <string>

namespace create {
class Packet {
Expand Down
Empty file added package.sh
Empty file.
12 changes: 6 additions & 6 deletions tests/test_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ TEST(DataTest, GetNumPackets)

create::Data data_v_3(create::V_3);
// Number exclusive to V_3 = 13
// 17 + 13 = 30
EXPECT_EQ(static_cast<int>(data_v_3.getNumPackets()), 30);
// 17 + 17 = 34
EXPECT_EQ(static_cast<int>(data_v_3.getNumPackets()), 34);

create::Data data_v_all(create::V_ALL);
EXPECT_EQ(static_cast<int>(data_v_all.getNumPackets()), 33);
EXPECT_EQ(static_cast<int>(data_v_all.getNumPackets()), 37);
}

TEST(DataTest, GetPacket)
Expand Down Expand Up @@ -108,7 +108,7 @@ TEST(DataTest, GetPacketIDs)
create::Data data_v_3(create::V_3);
const std::vector<uint8_t> packet_ids = data_v_3.getPacketIDs();
// Vector should have same length as reported by getNumPackets()
ASSERT_EQ(static_cast<int>(packet_ids.size()), 30);
ASSERT_EQ(static_cast<int>(packet_ids.size()), 34);

// Vector should contain ID_LEFT_ENC
bool found = false;
Expand All @@ -133,9 +133,9 @@ TEST(DataTest, GetTotalDataBytes)
create::Data data_v_2(create::V_2);
EXPECT_EQ(static_cast<int>(data_v_2.getTotalDataBytes()), 26);

// V_3 has an additional 21 bytes
// V_3 has an additional 29 bytes
create::Data data_v_3(create::V_3);
EXPECT_EQ(static_cast<int>(data_v_3.getTotalDataBytes()), 42);
EXPECT_EQ(static_cast<int>(data_v_3.getTotalDataBytes()), 50);
}

TEST(DataTest, IsValidPacketID)
Expand Down

0 comments on commit d5885d4

Please sign in to comment.