|
| 1 | +# CI workflow for cpp-library project itself |
| 2 | + |
| 3 | +name: CI |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [main, develop] |
| 8 | + pull_request: |
| 9 | + branches: [main] |
| 10 | + |
| 11 | +jobs: |
| 12 | + unit-tests: |
| 13 | + name: Unit Tests |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v6 |
| 18 | + |
| 19 | + - name: Run dependency mapping tests |
| 20 | + run: cmake -P tests/install/CMakeLists.txt |
| 21 | + |
| 22 | + - name: Run provider merging tests |
| 23 | + run: cmake -P tests/install/test_provider_merge.cmake |
| 24 | + |
| 25 | + integration-tests: |
| 26 | + name: Integration Tests |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v6 |
| 31 | + |
| 32 | + - name: Download CPM.cmake |
| 33 | + run: | |
| 34 | + mkdir -p cmake |
| 35 | + wget -q -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake |
| 36 | +
|
| 37 | + - name: Create test project |
| 38 | + run: | |
| 39 | + mkdir -p test-project/include/testlib |
| 40 | + cd test-project |
| 41 | + |
| 42 | + # Create CMakeLists.txt that uses cpp-library |
| 43 | + cat > CMakeLists.txt << 'EOF' |
| 44 | + cmake_minimum_required(VERSION 3.24) |
| 45 | + |
| 46 | + # Setup CPM before project() |
| 47 | + include(../cmake/CPM.cmake) |
| 48 | + |
| 49 | + # Fetch cpp-library before project() |
| 50 | + # Check https://github.com/stlab/cpp-library/releases for the latest version |
| 51 | + CPMAddPackage(NAME cpp-library SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) |
| 52 | + include(${cpp-library_SOURCE_DIR}/cpp-library.cmake) |
| 53 | + |
| 54 | + # Enable dependency tracking before project() |
| 55 | + cpp_library_enable_dependency_tracking() |
| 56 | + |
| 57 | + # Now call project() |
| 58 | + project(mylib VERSION 1.0.0) |
| 59 | + |
| 60 | + # Create a simple test library |
| 61 | + cpp_library_setup( |
| 62 | + DESCRIPTION "Test library for cpp-library" |
| 63 | + NAMESPACE testlib |
| 64 | + HEADERS mylib.hpp |
| 65 | + ) |
| 66 | + EOF |
| 67 | + |
| 68 | + # Create a simple header |
| 69 | + cat > include/testlib/mylib.hpp << 'EOF' |
| 70 | + #pragma once |
| 71 | + namespace testlib { |
| 72 | + inline int get_value() { return 42; } |
| 73 | + } |
| 74 | + EOF |
| 75 | +
|
| 76 | + - name: Configure test project |
| 77 | + run: | |
| 78 | + cd test-project |
| 79 | + cmake -B build -DCMAKE_BUILD_TYPE=Release |
| 80 | +
|
| 81 | + - name: Build test project |
| 82 | + run: | |
| 83 | + cd test-project |
| 84 | + cmake --build build |
| 85 | +
|
| 86 | + - name: Install test project |
| 87 | + run: | |
| 88 | + cd test-project |
| 89 | + cmake --install build --prefix ${{ runner.temp }}/install |
| 90 | +
|
| 91 | + - name: Verify installation |
| 92 | + run: | |
| 93 | + # Check that package config was installed |
| 94 | + if [ ! -f "${{ runner.temp }}/install/lib/cmake/testlib-mylib/testlib-mylibConfig.cmake" ]; then |
| 95 | + echo "Error: Package config not found" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + echo "✓ Installation successful" |
| 99 | +
|
| 100 | + - name: Test find_package |
| 101 | + run: | |
| 102 | + mkdir -p test-consumer |
| 103 | + cd test-consumer |
| 104 | + |
| 105 | + # Create a consumer project |
| 106 | + cat > CMakeLists.txt << 'EOF' |
| 107 | + cmake_minimum_required(VERSION 3.20) |
| 108 | + project(test-consumer) |
| 109 | + |
| 110 | + find_package(testlib-mylib REQUIRED) |
| 111 | + |
| 112 | + add_executable(consumer main.cpp) |
| 113 | + target_link_libraries(consumer PRIVATE testlib::mylib) |
| 114 | + EOF |
| 115 | + |
| 116 | + # Create main.cpp |
| 117 | + cat > main.cpp << 'EOF' |
| 118 | + #include <testlib/mylib.hpp> |
| 119 | + #include <iostream> |
| 120 | + int main() { |
| 121 | + std::cout << "Value: " << testlib::get_value() << std::endl; |
| 122 | + return 0; |
| 123 | + } |
| 124 | + EOF |
| 125 | + |
| 126 | + # Configure with installed package |
| 127 | + cmake -B build -DCMAKE_PREFIX_PATH=${{ runner.temp }}/install |
| 128 | + |
| 129 | + # Build |
| 130 | + cmake --build build |
| 131 | + |
| 132 | + echo "✓ Consumer project built successfully" |
| 133 | +
|
| 134 | + documentation: |
| 135 | + name: Documentation Test |
| 136 | + runs-on: ubuntu-latest |
| 137 | + |
| 138 | + steps: |
| 139 | + - uses: actions/checkout@v6 |
| 140 | + |
| 141 | + - name: Check README examples |
| 142 | + run: | |
| 143 | + # Extract and validate code blocks from README |
| 144 | + grep -A 20 '```cmake' README.md | head -50 |
| 145 | + echo "✓ README documentation looks valid" |
| 146 | +
|
| 147 | + - name: Validate template files |
| 148 | + run: | |
| 149 | + # Check that all template files exist |
| 150 | + test -f templates/CMakePresets.json |
| 151 | + test -f templates/Config.cmake.in |
| 152 | + test -f templates/Doxyfile.in |
| 153 | + test -f templates/custom.css |
| 154 | + echo "✓ All template files present" |
| 155 | +
|
0 commit comments