diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d71d4b3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.github +ci/Dockerfile \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 7fb7d18..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: Build and test - -on: - push: - branches: ['master'] - pull_request: - -env: - BUILD_TYPE: Release - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-20.04, ubuntu-22.04] - - steps: - - name: Install dependencies - run: | - sudo apt install build-essential cmake git libboost-system-dev libboost-thread-dev - git clone https://github.com/google/googletest.git - cd googletest - cmake CMakeLists.txt - make - sudo make install - - - uses: actions/checkout@v2 - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_FLAGS="-Werror" - - - 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}} diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml new file mode 100644 index 0000000..5a1e8f4 --- /dev/null +++ b/.github/workflows/package.yaml @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..fb0bcce --- /dev/null +++ b/.github/workflows/test.yaml @@ -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}} diff --git a/CMakeLists.txt b/CMakeLists.txt index ce7beb2..e39cf16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,17 @@ +######### +# 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) @@ -5,12 +19,14 @@ # 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) @@ -203,3 +219,9 @@ if(LIBCREATE_BUILD_TESTS AND ${GTEST_FOUND}) else() message("No GTest installation found. Skipping tests.") endif() + +############# +# Packaging # +############# + +include(Packing) \ No newline at end of file diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..bf82ed3 --- /dev/null +++ b/ci/Dockerfile @@ -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"] diff --git a/ci/entrypoint.sh b/ci/entrypoint.sh new file mode 100755 index 0000000..779d753 --- /dev/null +++ b/ci/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/cmake/Packing.cmake b/cmake/Packing.cmake new file mode 100644 index 0000000..58d81b8 --- /dev/null +++ b/cmake/Packing.cmake @@ -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 "kontakt@comp-air.at") +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) \ No newline at end of file diff --git a/cmake/Versioning.cmake b/cmake/Versioning.cmake new file mode 100644 index 0000000..d659c5c --- /dev/null +++ b/cmake/Versioning.cmake @@ -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() \ No newline at end of file diff --git a/include/create/packet.h b/include/create/packet.h index d1e7928..60ff0f2 100644 --- a/include/create/packet.h +++ b/include/create/packet.h @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #define CREATE_PACKET_H #include +#include namespace create { class Packet { diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..e69de29 diff --git a/tests/test_data.cpp b/tests/test_data.cpp index e9752a0..e347fb1 100644 --- a/tests/test_data.cpp +++ b/tests/test_data.cpp @@ -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(data_v_3.getNumPackets()), 30); + // 17 + 17 = 34 + EXPECT_EQ(static_cast(data_v_3.getNumPackets()), 34); create::Data data_v_all(create::V_ALL); - EXPECT_EQ(static_cast(data_v_all.getNumPackets()), 33); + EXPECT_EQ(static_cast(data_v_all.getNumPackets()), 37); } TEST(DataTest, GetPacket) @@ -108,7 +108,7 @@ TEST(DataTest, GetPacketIDs) create::Data data_v_3(create::V_3); const std::vector packet_ids = data_v_3.getPacketIDs(); // Vector should have same length as reported by getNumPackets() - ASSERT_EQ(static_cast(packet_ids.size()), 30); + ASSERT_EQ(static_cast(packet_ids.size()), 34); // Vector should contain ID_LEFT_ENC bool found = false; @@ -133,9 +133,9 @@ TEST(DataTest, GetTotalDataBytes) create::Data data_v_2(create::V_2); EXPECT_EQ(static_cast(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(data_v_3.getTotalDataBytes()), 42); + EXPECT_EQ(static_cast(data_v_3.getTotalDataBytes()), 50); } TEST(DataTest, IsValidPacketID)