|
| 1 | +name: 'Build and Test' |
| 2 | +description: 'Builds WinDevices library (Debug + Release) and runs tests' |
| 3 | + |
| 4 | +inputs: |
| 5 | + build-type: |
| 6 | + description: 'Build configuration (Debug or Release) - both are always built' |
| 7 | + required: false |
| 8 | + default: 'Debug' |
| 9 | + enable-testing: |
| 10 | + description: 'Enable running unit tests' |
| 11 | + required: false |
| 12 | + default: 'true' |
| 13 | + enable-e2e-tests: |
| 14 | + description: 'Enable building E2E tests (requires hardware)' |
| 15 | + required: false |
| 16 | + default: 'false' |
| 17 | + upload-artifacts: |
| 18 | + description: 'Whether to upload build artifacts' |
| 19 | + required: false |
| 20 | + default: 'false' |
| 21 | + artifact-name: |
| 22 | + description: 'Name for uploaded artifacts' |
| 23 | + required: false |
| 24 | + default: 'build-artifacts' |
| 25 | + upload-test-results: |
| 26 | + description: 'Whether to upload test results' |
| 27 | + required: false |
| 28 | + default: 'false' |
| 29 | + test-results-name: |
| 30 | + description: 'Name for uploaded test results' |
| 31 | + required: false |
| 32 | + default: 'test-results' |
| 33 | + publish-test-results: |
| 34 | + description: 'Whether to publish test results to PR' |
| 35 | + required: false |
| 36 | + default: 'false' |
| 37 | + |
| 38 | +outputs: |
| 39 | + build-path: |
| 40 | + description: 'Path to the build directory' |
| 41 | + value: ${{ steps.build-info.outputs.build-path }} |
| 42 | + binary-path: |
| 43 | + description: 'Path to the binary directory' |
| 44 | + value: ${{ steps.build-info.outputs.binary-path }} |
| 45 | + test-executable: |
| 46 | + description: 'Path to the test executable' |
| 47 | + value: ${{ steps.build-info.outputs.test-executable }} |
| 48 | + tests-passed: |
| 49 | + description: 'Whether all tests passed' |
| 50 | + value: ${{ steps.run-tests.outputs.tests-passed }} |
| 51 | + |
| 52 | +runs: |
| 53 | + using: 'composite' |
| 54 | + steps: |
| 55 | + - name: Setup CMake |
| 56 | + uses: jwlawson/actions-setup-cmake@v1.14 |
| 57 | + with: |
| 58 | + cmake-version: '3.29' |
| 59 | + |
| 60 | + - name: Configure CMake |
| 61 | + shell: cmd |
| 62 | + run: | |
| 63 | + echo Configuring CMake with tests enabled... |
| 64 | + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_E2E_TESTS=OFF -DENABLE_COVERAGE=OFF |
| 65 | + if errorlevel 1 ( |
| 66 | + echo CMake configuration failed |
| 67 | + exit /b 1 |
| 68 | + ) |
| 69 | + echo CMake configuration completed |
| 70 | +
|
| 71 | + - name: Build Debug |
| 72 | + shell: cmd |
| 73 | + run: | |
| 74 | + echo Building Debug configuration... |
| 75 | + cmake --build build --config Debug --parallel |
| 76 | + if errorlevel 1 ( |
| 77 | + echo Debug build failed |
| 78 | + exit /b 1 |
| 79 | + ) |
| 80 | + echo Debug build completed successfully |
| 81 | +
|
| 82 | + - name: Build Release |
| 83 | + shell: cmd |
| 84 | + run: | |
| 85 | + echo Building Release configuration... |
| 86 | + cmake --build build --config Release --parallel |
| 87 | + if errorlevel 1 ( |
| 88 | + echo Release build failed |
| 89 | + exit /b 1 |
| 90 | + ) |
| 91 | + echo Release build completed successfully |
| 92 | +
|
| 93 | + - name: Run Tests |
| 94 | + id: run-tests |
| 95 | + if: ${{ inputs.enable-testing == 'true' }} |
| 96 | + shell: cmd |
| 97 | + run: | |
| 98 | + echo Running tests... |
| 99 | + echo. |
| 100 | + echo Looking for test executable... |
| 101 | +
|
| 102 | + if exist "build\bin\Debug\WinDevicesTests.exe" ( |
| 103 | + echo Found: build\bin\Debug\WinDevicesTests.exe |
| 104 | + build\bin\Debug\WinDevicesTests.exe --gtest_output=xml:test-results.xml |
| 105 | + ) else if exist "build\bin\WinDevicesTests.exe" ( |
| 106 | + echo Found: build\bin\WinDevicesTests.exe |
| 107 | + build\bin\WinDevicesTests.exe --gtest_output=xml:test-results.xml |
| 108 | + ) else ( |
| 109 | + echo ERROR: WinDevicesTests.exe not found |
| 110 | + echo. |
| 111 | + echo Contents of build\bin: |
| 112 | + dir /s build\bin |
| 113 | + exit /b 1 |
| 114 | + ) |
| 115 | +
|
| 116 | + if errorlevel 1 ( |
| 117 | + echo Tests failed |
| 118 | + echo tests-passed=false>> %GITHUB_OUTPUT% |
| 119 | + exit /b 1 |
| 120 | + ) |
| 121 | +
|
| 122 | + echo All tests passed |
| 123 | + echo tests-passed=true>> %GITHUB_OUTPUT% |
| 124 | +
|
| 125 | + - name: Set build information outputs |
| 126 | + id: build-info |
| 127 | + shell: powershell |
| 128 | + run: | |
| 129 | + $buildPath = "build" |
| 130 | + $binaryPath = "build\bin" |
| 131 | +
|
| 132 | + Write-Host "Build directory: $buildPath" |
| 133 | +
|
| 134 | + if (Test-Path "build\bin\Debug") { |
| 135 | + Write-Host "Debug build contents:" |
| 136 | + Get-ChildItem "build\bin\Debug" | ForEach-Object { Write-Host " $($_.Name)" } |
| 137 | + $testExe = "build\bin\Debug\WinDevicesTests.exe" |
| 138 | + } elseif (Test-Path "build\bin") { |
| 139 | + Write-Host "Build bin contents:" |
| 140 | + Get-ChildItem "build\bin" | ForEach-Object { Write-Host " $($_.Name)" } |
| 141 | + $testExe = "build\bin\WinDevicesTests.exe" |
| 142 | + } else { |
| 143 | + $testExe = "" |
| 144 | + } |
| 145 | +
|
| 146 | + if (Test-Path "build\bin\Release") { |
| 147 | + Write-Host "Release build contents:" |
| 148 | + Get-ChildItem "build\bin\Release" | ForEach-Object { Write-Host " $($_.Name)" } |
| 149 | + } |
| 150 | +
|
| 151 | + "build-path=$buildPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 |
| 152 | + "binary-path=$binaryPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 |
| 153 | + "test-executable=$testExe" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 |
| 154 | +
|
| 155 | + - name: Upload Build Artifacts |
| 156 | + if: ${{ inputs.upload-artifacts == 'true' }} |
| 157 | + uses: actions/upload-artifact@v4 |
| 158 | + with: |
| 159 | + name: ${{ inputs.artifact-name }} |
| 160 | + path: | |
| 161 | + build/bin/ |
| 162 | + build/lib/ |
| 163 | + include/ |
| 164 | + build/include/ |
| 165 | + retention-days: 30 |
| 166 | + if-no-files-found: warn |
| 167 | + |
| 168 | + - name: Upload Test Results Artifacts |
| 169 | + if: ${{ inputs.upload-test-results == 'true' && inputs.enable-testing == 'true' && always() }} |
| 170 | + uses: actions/upload-artifact@v4 |
| 171 | + with: |
| 172 | + name: ${{ inputs.test-results-name }} |
| 173 | + path: | |
| 174 | + test-results.xml |
| 175 | + build/Testing/ |
| 176 | + retention-days: 30 |
| 177 | + if-no-files-found: warn |
0 commit comments