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