|
| 1 | +name: Build openDAQ SDK |
| 2 | +description: Configure, build and test openDAQ SDK |
| 3 | + |
| 4 | +inputs: |
| 5 | + additional-dependencies: |
| 6 | + description: 'Additional packages to install (apt on Linux, choco on Windows)' |
| 7 | + required: false |
| 8 | + default: '' |
| 9 | + cmake-generator: |
| 10 | + description: 'CMake generator (e.g., "Ninja", "Visual Studio 17 2022")' |
| 11 | + required: false |
| 12 | + default: '' |
| 13 | + cmake-config-preset: |
| 14 | + description: 'CMake configure preset name' |
| 15 | + required: false |
| 16 | + default: '' |
| 17 | + cmake-config-args: |
| 18 | + description: 'Additional CMake configure arguments (e.g., -D flags)' |
| 19 | + required: false |
| 20 | + default: '' |
| 21 | + cmake-build-type: |
| 22 | + description: 'Build configuration (Release, Debug). Required for multi-config generators (Visual Studio)' |
| 23 | + required: false |
| 24 | + default: '' |
| 25 | + enable-32bit: |
| 26 | + description: 'Build for 32-bit architecture' |
| 27 | + required: false |
| 28 | + default: 'false' |
| 29 | + enable-tests: |
| 30 | + description: 'Run tests after build' |
| 31 | + required: false |
| 32 | + default: 'false' |
| 33 | + ctest-preset: |
| 34 | + description: 'CTest preset name' |
| 35 | + required: false |
| 36 | + default: '' |
| 37 | + |
| 38 | +outputs: |
| 39 | + gtest-xml-path: |
| 40 | + description: 'Path to GTest XML reports directory' |
| 41 | + value: ${{ steps.test.outputs.gtest-xml-path }} |
| 42 | + |
| 43 | +runs: |
| 44 | + using: composite |
| 45 | + steps: |
| 46 | + - name: Check inputs |
| 47 | + shell: bash |
| 48 | + env: |
| 49 | + CMAKE_GENERATOR: ${{ inputs.cmake-generator }} |
| 50 | + run: | |
| 51 | + if [ -z "$CMAKE_GENERATOR" ]; then |
| 52 | + echo "::error::✗ The cmake-generator input is not set." |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Set up Python |
| 57 | + uses: actions/setup-python@v5 |
| 58 | + with: |
| 59 | + python-version: '3.14' |
| 60 | + architecture: ${{ inputs.enable-32bit == 'true' && 'x86' || 'x64' }} |
| 61 | + |
| 62 | + - name: Setup cmake |
| 63 | + uses: jwlawson/actions-setup-cmake@v2 |
| 64 | + |
| 65 | + - name: Install Windows dependencies |
| 66 | + if: runner.os == 'Windows' && inputs.additional-dependencies != '' |
| 67 | + shell: pwsh |
| 68 | + run: choco install ${{ inputs.additional-dependencies }} -y --no-progress |
| 69 | + |
| 70 | + - name: Install Linux dependencies |
| 71 | + if: runner.os == 'Linux' |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + sudo apt-get update && sudo apt-get install -y --no-install-recommends \ |
| 75 | + ${{ inputs.additional-dependencies || '' }} \ |
| 76 | + lld mono-runtime libmono-system-json-microsoft4.0-cil libmono-system-data4.0-cil \ |
| 77 | + libx11-dev libxi-dev libxcursor-dev libxrandr-dev libgl-dev libudev-dev libfreetype6-dev |
| 78 | +
|
| 79 | + - name: Install macOS dependencies |
| 80 | + if: runner.os == 'macOS' |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + HOMEBREW_NO_AUTO_UPDATE=1 brew install mono ${{ inputs.additional-dependencies }} |
| 84 | +
|
| 85 | + - name: Install ninja-build |
| 86 | + if: inputs.cmake-generator == 'Ninja' |
| 87 | + uses: seanmiddleditch/gha-setup-ninja@v5 |
| 88 | + |
| 89 | + - name: Setup MSYS2 MINGW64 |
| 90 | + if: runner.os == 'Windows' |
| 91 | + id: msys2 |
| 92 | + uses: msys2/setup-msys2@v2 |
| 93 | + with: |
| 94 | + msystem: MINGW64 |
| 95 | + update: false |
| 96 | + install: mingw-w64-x86_64-crt-git mingw-w64-x86_64-gcc |
| 97 | + |
| 98 | + - name: Add MSYS2 MINGW64 to PATH |
| 99 | + if: runner.os == 'Windows' |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + echo "${{ steps.msys2.outputs.msys2-location }}/mingw64/bin" >> $GITHUB_PATH |
| 103 | + echo "Added MSYS2 MINGW64 to PATH: ${{ steps.msys2.outputs.msys2-location }}/mingw64/bin" |
| 104 | +
|
| 105 | + # https://github.com/actions/runner-images/issues/10001 |
| 106 | + - name: Setup MSVC toolchain |
| 107 | + if: runner.os == 'Windows' |
| 108 | + uses: ilammy/msvc-dev-cmd@v1 |
| 109 | + |
| 110 | + - name: Install Python dependencies |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + echo "Installing numpy for Python versions: $(python --version)" |
| 114 | + python -m pip install numpy |
| 115 | + echo "Done installing Python dependencies" |
| 116 | +
|
| 117 | + - name: Configure |
| 118 | + id: cmake-config |
| 119 | + shell: bash |
| 120 | + env: |
| 121 | + CMAKE_BUILD_TYPE: ${{ inputs.cmake-build-type }} |
| 122 | + CMAKE_GENERATOR: ${{ inputs.cmake-generator }} |
| 123 | + CI_GIT_BRANCH: ${{ github.head_ref }} |
| 124 | + run: | |
| 125 | + CMAKE_BUILD_PATH="build" |
| 126 | + mkdir -p "$CMAKE_BUILD_PATH" |
| 127 | + CMAKE_BUILD_PATH=$(cd "$CMAKE_BUILD_PATH" && pwd) |
| 128 | + echo "build-path=$CMAKE_BUILD_PATH" >> "$GITHUB_OUTPUT" |
| 129 | +
|
| 130 | + CMAKE_ARGS="" |
| 131 | + if [ -n "${{ inputs.cmake-config-preset }}" ]; then |
| 132 | + CMAKE_ARGS="--preset ${{ inputs.cmake-config-preset }}" |
| 133 | + fi |
| 134 | +
|
| 135 | + # Visual Studio specific options |
| 136 | + if [[ "$CMAKE_GENERATOR" == "Visual Studio"* ]]; then |
| 137 | + CMAKE_ARGS="$CMAKE_ARGS -DOPENDAQ_MSVC_SINGLE_PROCESS_BUILD=ON" |
| 138 | + fi |
| 139 | +
|
| 140 | + if [ -n "$CMAKE_BUILD_TYPE" ]; then |
| 141 | + CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" |
| 142 | + fi |
| 143 | +
|
| 144 | + CMAKE_ARGS="$CMAKE_ARGS -DCI_GIT_BRANCH=$CI_GIT_BRANCH" |
| 145 | +
|
| 146 | + echo "::group::CMake Configure" |
| 147 | + cmake -B "$CMAKE_BUILD_PATH" -G "$CMAKE_GENERATOR" $CMAKE_ARGS ${{ inputs.cmake-config-args }} |
| 148 | + echo "::endgroup::" |
| 149 | +
|
| 150 | + - name: Build |
| 151 | + shell: bash |
| 152 | + env: |
| 153 | + SHORT_SHA: ci # .NET bindings version suffix (e.g., 1.0.0-beta-ci) |
| 154 | + CMAKE_BUILD_TYPE: ${{ inputs.cmake-build-type }} |
| 155 | + CMAKE_BUILD_PATH: ${{ steps.cmake-config.outputs.build-path }} |
| 156 | + run: | |
| 157 | + CMAKE_BUILD_ARGS="" |
| 158 | + if [ -n "$CMAKE_BUILD_TYPE" ]; then |
| 159 | + CMAKE_BUILD_ARGS="--config $CMAKE_BUILD_TYPE" |
| 160 | + fi |
| 161 | +
|
| 162 | + echo "::group::CMake Build" |
| 163 | + cmake --build "$CMAKE_BUILD_PATH" $CMAKE_BUILD_ARGS |
| 164 | + echo "::endgroup::" |
| 165 | +
|
| 166 | + - name: Test |
| 167 | + id: test |
| 168 | + if: inputs.enable-tests == 'true' |
| 169 | + shell: bash |
| 170 | + env: |
| 171 | + CMAKE_BUILD_TYPE: ${{ inputs.cmake-build-type }} |
| 172 | + CMAKE_BUILD_PATH: ${{ steps.cmake-config.outputs.build-path }} |
| 173 | + run: | |
| 174 | + GTEST_XML_PATH="$CMAKE_BUILD_PATH/test_results" |
| 175 | + mkdir -p "$GTEST_XML_PATH" |
| 176 | +
|
| 177 | + if command -v cygpath &> /dev/null; then |
| 178 | + GTEST_XML_PATH=$(cygpath -w "$GTEST_XML_PATH") |
| 179 | + fi |
| 180 | +
|
| 181 | + export GTEST_OUTPUT="xml:$GTEST_XML_PATH/" |
| 182 | + echo "gtest-xml-path=$GTEST_XML_PATH" >> "$GITHUB_OUTPUT" |
| 183 | +
|
| 184 | + CTEST_ARGS="" |
| 185 | + if [ -n "${{ inputs.ctest-preset }}" ]; then |
| 186 | + CTEST_ARGS="--preset ${{ inputs.ctest-preset }}" |
| 187 | + fi |
| 188 | +
|
| 189 | + if [ -n "$CMAKE_BUILD_TYPE" ]; then |
| 190 | + CTEST_ARGS="$CTEST_ARGS --build-config $CMAKE_BUILD_TYPE" |
| 191 | + fi |
| 192 | +
|
| 193 | + SUDO_CMD="" |
| 194 | + if command -v sudo &> /dev/null; then |
| 195 | + SUDO_CMD="sudo -E" |
| 196 | + fi |
| 197 | +
|
| 198 | + echo "::group::CTest" |
| 199 | + $SUDO_CMD ctest --test-dir "$CMAKE_BUILD_PATH" --output-on-failure $CTEST_ARGS |
| 200 | + echo "::endgroup::" |
0 commit comments