From c10672e763d1023b02077910e901f54733e50ac8 Mon Sep 17 00:00:00 2001 From: black-desk Date: Fri, 20 Sep 2024 22:15:11 +0800 Subject: [PATCH] ci: add github workflow checks --- .github/dependabot.yml | 10 ++++ .github/workflows/checks.yaml | 61 ++++++++++++++++++++ CMakeLists.txt | 3 +- CMakePresets.json | 48 +++++++++++++++ cmake/.cmake-format.py | 2 + examples/print-messages/src/main.cpp | 4 +- include/errors/error.hpp | 11 ++++ include/errors/source_location.hpp | 22 +++++-- tests/errors-unit-tests/src/common_error.cpp | 3 +- 9 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/checks.yaml create mode 100644 CMakePresets.json create mode 100644 cmake/.cmake-format.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..10d8d66 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - directory: / + package-ecosystem: gitsubmodule + schedule: + interval: daily + - directory: / + package-ecosystem: github-actions + schedule: + interval: daily diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml new file mode 100644 index 0000000..27e4fa3 --- /dev/null +++ b/.github/workflows/checks.yaml @@ -0,0 +1,61 @@ +name: Checks + +on: [pull_request] + +jobs: + checks: + name: Run black-desk/checks + permissions: + checks: write + contents: read + issues: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: black-desk/checks@master + build-and-test: + name: Build and tests + runs-on: "ubuntu-latest" + strategy: + matrix: + container: + - debian:oldstable-slim + - debian:stable-slim + - debian:sid-slim + cxx: [g++, clang++] + container: + image: ${{ matrix.container }} + steps: + - name: Checkout project + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Cache CPM.cmake Source + uses: actions/cache@v4 + with: + path: .cache/cpm/source + key: ${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v2.0 + - name: Install system dependencies + run: | + apt update && + apt install pkg-config make git g++ clang -y + - name: Build project with cmake by preset debug + run: | + mkdir -p .cache/cpm/source && + export CXX="${{ matrix.cxx }}" && + export CPM_SOURCE_CACHE="$PWD/.cache/cpm/source" && + cmake --workflow --preset debug + pass: + name: Pass + if: always() + needs: + - checks + - build-and-test + runs-on: ubuntu-latest + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} diff --git a/CMakeLists.txt b/CMakeLists.txt index f51a87d..5643ed9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,8 @@ macro(cpm_add_dependencies) VERSION 1.0.0 GITHUB_REPOSITORY TartanLlama/expected GIT_TAG v1.1.0 - EXCLUDE_FROM_ALL ON) + EXCLUDE_FROM_ALL ON + OPTIONS "EXPECTED_BUILD_TESTS OFF") if(NOT TARGET tl::expected) add_library(tl::expected ALIAS tl-expected) endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..c80b5f6 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,48 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "configurePresets": [ + { + "name": "debug", + "displayName": "Debug configuration", + "description": "Configure errors for development and debugging.", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CPM_DOWNLOAD_ALL": "ON", + "OCPPI_WITH_SPDLOG": true, + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Og -g -fsanitize=address,undefined", + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_COLOR_DIAGNOSTICS": true + } + } + ], + "buildPresets": [ + { + "name": "debug", + "displayName": "Debug build", + "description": "Build errors for development and debugging.", + "configurePreset": "debug" + } + ], + "workflowPresets": [ + { + "name": "debug", + "displayName": "Workflow for developers", + "description": "Configure, build then test for developing and debuging ocppi.", + "steps": [ + { + "type": "configure", + "name": "debug" + }, + { + "type": "build", + "name": "debug" + } + ] + } + ] +} diff --git a/cmake/.cmake-format.py b/cmake/.cmake-format.py new file mode 100644 index 0000000..856d139 --- /dev/null +++ b/cmake/.cmake-format.py @@ -0,0 +1,2 @@ +with section("format"): + disable = True diff --git a/examples/print-messages/src/main.cpp b/examples/print-messages/src/main.cpp index e5e7e47..17e438b 100644 --- a/examples/print-messages/src/main.cpp +++ b/examples/print-messages/src/main.cpp @@ -1,3 +1,4 @@ +#include #include #include "errors/error.hpp" @@ -105,7 +106,8 @@ std::ostream &operator<<(std::ostream &os, const errors::error_ptr &err) for (; current_err != nullptr; current_err = current_err->cause().get()) { os << std::endl - << "[function " << current_err->location().function_name() << " at " + << "[function " << current_err->location().function_name() + << " at " << std::filesystem::path(current_err->location().file_name()) .filename() .string() diff --git a/include/errors/error.hpp b/include/errors/error.hpp index 618d973..c0adcbf 100644 --- a/include/errors/error.hpp +++ b/include/errors/error.hpp @@ -178,7 +178,13 @@ inline std::ostream &operator<<(std::ostream &os, const errors::error_ptr &err) #if defined(ERRORS_ENABLE_NLOHMANN_JSON_SUPPORT) #include "nlohmann/json.hpp" +#if defined(NLOHMANN_JSON_NAMESPACE_BEGIN) && \ + defined(NLOHMANN_JSON_NAMESPACE_END) NLOHMANN_JSON_NAMESPACE_BEGIN +#else +namespace nlohmann +{ +#endif template <> struct adl_serializer< ::errors::error_ptr> { static void to_json(::nlohmann::json &j, const ::errors::error_ptr &err) @@ -198,5 +204,10 @@ struct adl_serializer< ::errors::error_ptr> { } } }; +#if defined(NLOHMANN_JSON_NAMESPACE_BEGIN) && \ + defined(NLOHMANN_JSON_NAMESPACE_END) NLOHMANN_JSON_NAMESPACE_END +#else +} +#endif #endif diff --git a/include/errors/source_location.hpp b/include/errors/source_location.hpp index 8546688..eed7968 100644 --- a/include/errors/source_location.hpp +++ b/include/errors/source_location.hpp @@ -99,10 +99,10 @@ struct source_location { constexpr source_location(const char *file, const char *function, uint_least32_t line, uint_least32_t column) noexcept - : file_name_(file), - function_name_(function), - line_number(line), - column_(column) + : file_name_(file) + , function_name_(function) + , line_number(line) + , column_(column) { } @@ -117,8 +117,15 @@ struct source_location { #if defined(ERRORS_ENABLE_NLOHMANN_JSON_SUPPORT) #include "nlohmann/json.hpp" +#if defined(NLOHMANN_JSON_NAMESPACE_BEGIN) && \ + defined(NLOHMANN_JSON_NAMESPACE_END) NLOHMANN_JSON_NAMESPACE_BEGIN -template <> struct adl_serializer< ::errors::source_location> { +#else +namespace nlohmann +{ +#endif +template <> +struct adl_serializer< ::errors::source_location> { static void to_json(::nlohmann::json &j, const ::errors::source_location &loc) { @@ -128,5 +135,10 @@ template <> struct adl_serializer< ::errors::source_location> { j["column"] = loc.column(); } }; +#if defined(NLOHMANN_JSON_NAMESPACE_BEGIN) && \ + defined(NLOHMANN_JSON_NAMESPACE_END) NLOHMANN_JSON_NAMESPACE_END +#else +} +#endif #endif diff --git a/tests/errors-unit-tests/src/common_error.cpp b/tests/errors-unit-tests/src/common_error.cpp index 319f3d9..aa024a2 100644 --- a/tests/errors-unit-tests/src/common_error.cpp +++ b/tests/errors-unit-tests/src/common_error.cpp @@ -1,7 +1,6 @@ -#include - #include "catch2/catch_test_macros.hpp" #include "errors/error.hpp" +#include "nlohmann/json.hpp" namespace {