diff --git a/.github/workflows/cmake-format.yml b/.github/workflows/cmake-format.yml new file mode 100644 index 0000000..1e92f53 --- /dev/null +++ b/.github/workflows/cmake-format.yml @@ -0,0 +1,41 @@ +name: "CMake Format" + +on: + # always run on main branch + push: + branches: [ main ] + paths-ignore: + - 'README.md' + - 'CONTRIBUTING.md' + - 'LICENSE' + # run on PR to main branch if relevant files changed + pull_request: + branches: [ main ] + paths: + - '**/CMakeLists.txt' + - '.github/workflows/cmake-format.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + format: + name: "cmake-format" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + cache-dependency-path: '.github/workflows/cmake-format.yml' + cache: 'pip' + - name: Install CMake formatting tool + run: pip install cmake-format + + # Check all cmake files; ignore files in hidden directories + - name: Execute cmake-format + run: find . \( -path '*/.*' -prune \) -o + \( -type f -a -name 'CMakeLists.txt' \) + -exec echo "Format checking '{}'..." \; + -exec cmake-format --check -- {} + diff --git a/.github/workflows/cmake-lint.yml b/.github/workflows/cmake-lint.yml index 40b9c44..5f1407b 100644 --- a/.github/workflows/cmake-lint.yml +++ b/.github/workflows/cmake-lint.yml @@ -25,12 +25,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + cache-dependency-path: '.github/workflows/cmake-lint.yml' + cache: 'pip' - name: Install dependencies - run: | - sudo apt update -y - sudo apt -y --no-install-recommends install \ - python3-pip='22.*' - pip install cmakelint + run: pip install cmakelint + - name: Execute cmakelint run: find . \( \( -path './build' -o -path '*/.*' \) -prune \) -o \( -type f -a -iname 'CMakeLists.txt' \) diff --git a/.github/workflows/cpp-build.yml b/.github/workflows/cpp-build.yml index 10c9e60..7c5215f 100644 --- a/.github/workflows/cpp-build.yml +++ b/.github/workflows/cpp-build.yml @@ -1,4 +1,4 @@ -name: "C++ Build" +name: "Build|Test" on: # always run on main branch @@ -25,47 +25,56 @@ concurrency: jobs: build: - name: "gcc/clang build" + name: "build" runs-on: ubuntu-latest strategy: matrix: - cpp17_compatibility: [ "ON", "OFF" ] - cpp_compiler: [ "g++", "clang++" ] + include: + - cpp_compiler: "g++" + alpine_version: "v3.20" + cpp_version: "cpp17" + - cpp_compiler: "clang++" + alpine_version: "v3.19" + cpp_version: "cpp17" + - cpp_compiler: "g++" + alpine_version: "v3.19" + cpp_version: "cpp20" + - cpp_compiler: "clang++" + alpine_version: "v3.20" + cpp_version: "cpp20" steps: - uses: actions/checkout@v3 - uses: jirutka/setup-alpine@v1 with: - branch: v3.19 - - name: Install dependencies - run: | - apk update - apk add \ - cmake \ - ninja-build \ - g++ \ - clang \ - boost-dev \ - boost-filesystem \ - boost-python3 \ - lua5.2-dev \ - python3-dev \ - fmt-dev \ - gtest-dev - shell: alpine.sh --root {0} + branch: ${{ matrix.alpine_version }} + packages: > + cmake + ninja-build + g++ + clang + boost-dev + boost-filesystem + boost-python3 + lua5.2-dev + python3-dev + fmt-dev + gtest-dev - name: Fixup environment run: | ln -s liblua-5.2.so.0 /usr/lib/liblua-5.2.so ln -s /usr/lib/ninja-build/bin/ninja /usr/bin/ninja shell: alpine.sh --root {0} + - name: Prepare run: | - CXX=/usr/bin/${{ matrix.cpp_compiler }} \ - cmake . -B build -G Ninja \ - -DCMAKE_BUILD_TYPE=Debug \ - -DPPPLUGIN_SHARED=ON \ - -DPPPLUGIN_ENABLE_EXAMPLES=ON \ - -DPPPLUGIN_ENABLE_TESTS=ON \ - -DPPPLUGIN_ENABLE_CPP17_COMPATIBILITY=${{ matrix.cpp17_compatibility }} + CXX=/usr/bin/${{ matrix.cpp_compiler }} \ + cmake . -B build -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DPPPLUGIN_SHARED=ON \ + -DPPPLUGIN_ENABLE_EXAMPLES=ON \ + -DPPPLUGIN_ENABLE_TESTS=ON \ + -DPPPLUGIN_ENABLE_COVERAGE=${{ matrix.cpp_compiler == 'g++' && 'ON' || 'OFF' }} \ + -DPPPLUGIN_ENABLE_CPP17_COMPATIBILITY=${{ matrix.cpp_version == 'cpp17' && 'ON' || 'OFF' }} shell: alpine.sh {0} - name: Build run: | @@ -75,3 +84,63 @@ jobs: run: | cmake --install build shell: alpine.sh --root {0} + + - uses: actions/upload-artifact@v4 + with: + name: build_alpine-${{ matrix.alpine_version }}_${{ matrix.cpp_compiler }}_${{ matrix.cpp_version }} + path: build + retention-days: 5 + + unittest: + name: "unittest" + needs: build + runs-on: ubuntu-latest + strategy: + matrix: + cpp_version: [ "cpp17", "cpp20" ] + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v4 + with: + pattern: build_alpine-*_g++_${{ matrix.cpp_version }} + path: build + merge-multiple: true + - name: Fix artifact permissions + run: chmod +x build/test/tests + + - uses: jirutka/setup-alpine@v1 + with: + branch: v3.20 + packages: > + g++ + gtest-dev + lcov + gzip + + - name: Execute tests + run: | + lcov --capture --initial \ + --directory . \ + --ignore-errors mismatch,source \ + --output-file baseline_coverage + build/test/tests || echo $? + lcov --capture \ + --directory . \ + --ignore-errors mismatch,source \ + --output-file total_coverage + lcov \ + --add-tracefile baseline_coverage \ + --add-tracefile total_coverage \ + --ignore-errors mismatch,source \ + --output-file measured_coverage + lcov --remove measured_coverage "/usr*" \ + --ignore-errors mismatch,source \ + --output-file coverage_without_system_files + lcov --remove coverage_without_system_files "*/test/*" \ + --ignore-errors mismatch,source \ + --output-file coverage_without_system_and_test_files + genhtml \ + --output-directory coverage \ + --legend coverage_without_system_and_test_files + lcov --list coverage_without_system_and_test_files + shell: alpine.sh {0} diff --git a/.github/workflows/format.yml b/.github/workflows/cpp-format.yml similarity index 57% rename from .github/workflows/format.yml rename to .github/workflows/cpp-format.yml index f9d2f57..df59907 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/cpp-format.yml @@ -1,4 +1,4 @@ -name: "C++/CMake Format" +name: "C++ Format" on: # always run on main branch @@ -14,8 +14,7 @@ on: paths: - '**/*.cpp' - '**/*.h' - - '**/CMakeLists.txt' - - '.github/workflows/format.yml' + - '.github/workflows/cpp-format.yml' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -23,21 +22,16 @@ concurrency: jobs: format: - name: "clang-format/cmake-format" + name: "clang-format" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: jirutka/setup-alpine@v1 with: branch: v3.19 - - name: Install dependencies - run: | - apk update - apk add \ - clang-extra-tools \ - py3-pip - pip install --break-system-packages cmake-format - shell: alpine.sh --root {0} + packages: > + clang-extra-tools + # Check all source and header C++ files; ignore files in hidden directories - name: Execute clang-format run: find . \( -path '*/.*' -prune \) -o @@ -45,10 +39,3 @@ jobs: -exec echo "Format checking '{}'..." \; -exec clang-format --dry-run --Werror --Wno-error=unknown {} + shell: alpine.sh {0} - # Check all cmake files; ignore files in hidden directories - - name: Execute cmake-format - run: find . \( -path '*/.*' -prune \) -o - \( -type f -a -name 'CMakeLists.txt' \) - -exec echo "Format checking '{}'..." \; - -exec cmake-format --check -- {} + - shell: alpine.sh {0} diff --git a/.github/workflows/cpp-lint.yml b/.github/workflows/cpp-lint.yml index 7e52df3..65a0aaf 100644 --- a/.github/workflows/cpp-lint.yml +++ b/.github/workflows/cpp-lint.yml @@ -33,27 +33,24 @@ jobs: - uses: jirutka/setup-alpine@v1 with: branch: v3.19 - - name: Install dependencies - run: | - apk update - apk add \ - cmake \ - ninja-build \ - g++ \ - boost-dev \ - boost-filesystem \ - boost-python3 \ - lua5.2-dev \ - python3-dev \ - fmt-dev \ - gtest-dev \ - clang-extra-tools - shell: alpine.sh --root {0} + packages: > + cmake + ninja-build + g++ + boost-dev + boost-filesystem + boost-python3 + lua5.2-dev + python3-dev + fmt-dev + gtest-dev + clang-extra-tools - name: Fixup environment run: | ln -s liblua-5.2.so.0 /usr/lib/liblua-5.2.so ln -s /usr/lib/ninja-build/bin/ninja /usr/bin/ninja shell: alpine.sh --root {0} + - name: Generate compile_commands.json run: | cmake . -B build -G Ninja \ @@ -61,6 +58,7 @@ jobs: -DPPPLUGIN_ENABLE_TESTS=ON \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON shell: alpine.sh {0} + # Check all source and header C++ files; # ignore files in the build directory or in hidden directories - name: Execute clang-tidy diff --git a/.github/workflows/cpp-unittest.yml b/.github/workflows/cpp-unittest.yml deleted file mode 100644 index 0bff528..0000000 --- a/.github/workflows/cpp-unittest.yml +++ /dev/null @@ -1,99 +0,0 @@ -name: "C++ Unittests" - -on: - # always run on main branch - push: - branches: [ main ] - paths-ignore: - - 'README.md' - - 'CONTRIBUTING.md' - - 'LICENSE' - # run on PR to main branch if relevant files changed - pull_request: - branches: [ main ] - paths: - - 'src/**' - - 'include/**' - - 'test/**' - - 'CMakeLists.txt' - - '.github/workflows/cpp-unittest.yml' - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - - -jobs: - unittest: - name: "unittests" - runs-on: ubuntu-latest - strategy: - matrix: - cpp17_compatibility: [ "ON", "OFF" ] - steps: - - uses: actions/checkout@v3 - - uses: jirutka/setup-alpine@v1 - with: - branch: edge - extra-repositories: | - http://dl-cdn.alpinelinux.org/alpine/edge/testing - - name: Install dependencies - run: | - apk update - apk add \ - cmake \ - ninja-build \ - g++ \ - boost-dev \ - boost-filesystem \ - boost-python3 \ - lua5.2-dev \ - python3-dev \ - fmt-dev \ - gtest-dev \ - lcov gzip - shell: alpine.sh --root {0} - - name: Fixup environment - run: | - ln -s liblua-5.2.so.0 /usr/lib/liblua-5.2.so - ln -s /usr/lib/ninja-build/bin/ninja /usr/bin/ninja - shell: alpine.sh --root {0} - - name: Prepare - run: | - cmake . -B build -G Ninja \ - -DCMAKE_BUILD_TYPE=Debug \ - -DPPPLUGIN_ENABLE_TESTS=ON \ - -DPPPLUGIN_ENABLE_COVERAGE=ON \ - -DPPPLUGIN_ENABLE_CPP17_COMPATIBILITY=${{ matrix.cpp17_compatibility }} - shell: alpine.sh {0} - - name: Build - run: | - cmake --build build -j - shell: alpine.sh {0} - - name: Execute tests - run: | - lcov --capture --initial \ - --directory . \ - --ignore-errors mismatch \ - --output-file baseline_coverage - build/test/tests || echo $? - lcov --capture \ - --directory . \ - --ignore-errors mismatch \ - --output-file total_coverage - lcov \ - --add-tracefile baseline_coverage \ - --add-tracefile total_coverage \ - --ignore-errors mismatch \ - --output-file measured_coverage - lcov --remove measured_coverage "/usr*" \ - --ignore-errors mismatch \ - --output-file coverage_without_system_files - lcov --remove coverage_without_system_files "*/test/*" \ - --ignore-errors mismatch \ - --output-file coverage_without_system_and_test_files - genhtml \ - --output-directory coverage \ - --legend coverage_without_system_and_test_files - lcov --list coverage_without_system_and_test_files - shell: alpine.sh {0}