|
| 1 | +name: cpp-cmake-ci |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - main |
| 8 | + tags: |
| 9 | + - "v*" |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - master |
| 13 | + - main |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +env: |
| 20 | + APP_NAME: YOLOClassifier |
| 21 | + BUILD_TYPE: Release |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: ${{ matrix.name }} |
| 26 | + runs-on: ${{ matrix.os }} |
| 27 | + strategy: |
| 28 | + fail-fast: false |
| 29 | + matrix: |
| 30 | + include: |
| 31 | + - name: Windows / Qt 5.12.12 |
| 32 | + os: windows-2022 |
| 33 | + qt_host: windows |
| 34 | + qt_arch: win64_msvc2017_64 |
| 35 | + vcpkg_triplet: x64-windows |
| 36 | + artifact_name: YOLOClassifier-windows-x64 |
| 37 | + - name: Linux / Qt 5.12.12 |
| 38 | + os: ubuntu-22.04 |
| 39 | + qt_host: linux |
| 40 | + qt_arch: gcc_64 |
| 41 | + vcpkg_triplet: x64-linux |
| 42 | + artifact_name: YOLOClassifier-linux-x64 |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Install Linux system packages |
| 49 | + if: runner.os == 'Linux' |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + sudo apt-get update |
| 53 | + sudo apt-get install -y ninja-build |
| 54 | +
|
| 55 | + - name: Setup MSVC |
| 56 | + if: runner.os == 'Windows' |
| 57 | + uses: ilammy/msvc-dev-cmd@v1 |
| 58 | + with: |
| 59 | + arch: x64 |
| 60 | + |
| 61 | + - name: Install Qt 5.12.12 |
| 62 | + uses: jurplel/install-qt-action@v4 |
| 63 | + with: |
| 64 | + version: 5.12.12 |
| 65 | + host: ${{ matrix.qt_host }} |
| 66 | + target: desktop |
| 67 | + arch: ${{ matrix.qt_arch }} |
| 68 | + cache: true |
| 69 | + install-deps: true |
| 70 | + |
| 71 | + - name: Bootstrap vcpkg on Windows |
| 72 | + if: runner.os == 'Windows' |
| 73 | + shell: pwsh |
| 74 | + run: | |
| 75 | + git clone https://github.com/microsoft/vcpkg.git "$env:RUNNER_TEMP\vcpkg" |
| 76 | + & "$env:RUNNER_TEMP\vcpkg\bootstrap-vcpkg.bat" -disableMetrics |
| 77 | + "VCPKG_ROOT=$env:RUNNER_TEMP\vcpkg" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 78 | +
|
| 79 | + - name: Bootstrap vcpkg on Linux |
| 80 | + if: runner.os == 'Linux' |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + git clone https://github.com/microsoft/vcpkg.git "$RUNNER_TEMP/vcpkg" |
| 84 | + "$RUNNER_TEMP/vcpkg/bootstrap-vcpkg.sh" -disableMetrics |
| 85 | + echo "VCPKG_ROOT=$RUNNER_TEMP/vcpkg" >> "$GITHUB_ENV" |
| 86 | +
|
| 87 | + - name: Install ONNX Runtime on Windows |
| 88 | + if: runner.os == 'Windows' |
| 89 | + shell: pwsh |
| 90 | + run: | |
| 91 | + & "$env:VCPKG_ROOT\vcpkg.exe" install "onnxruntime:${{ matrix.vcpkg_triplet }}" |
| 92 | +
|
| 93 | + - name: Install ONNX Runtime on Linux |
| 94 | + if: runner.os == 'Linux' |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + "$VCPKG_ROOT/vcpkg" install "onnxruntime:${{ matrix.vcpkg_triplet }}" |
| 98 | +
|
| 99 | + - name: Configure on Windows |
| 100 | + if: runner.os == 'Windows' |
| 101 | + shell: pwsh |
| 102 | + run: | |
| 103 | + cmake -S . -B build -G Ninja ` |
| 104 | + "-DCMAKE_BUILD_TYPE=${env:BUILD_TYPE}" ` |
| 105 | + "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" ` |
| 106 | + "-DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }}" ` |
| 107 | + "-DQt5_DIR=$env:Qt5_DIR" |
| 108 | +
|
| 109 | + - name: Configure on Linux |
| 110 | + if: runner.os == 'Linux' |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + cmake -S . -B build -G Ninja \ |
| 114 | + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ |
| 115 | + -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \ |
| 116 | + -DVCPKG_TARGET_TRIPLET="${{ matrix.vcpkg_triplet }}" \ |
| 117 | + -DQt5_DIR="${Qt5_DIR}" |
| 118 | +
|
| 119 | + - name: Build on Windows |
| 120 | + if: runner.os == 'Windows' |
| 121 | + shell: pwsh |
| 122 | + run: cmake --build build --config $env:BUILD_TYPE --parallel |
| 123 | + |
| 124 | + - name: Build on Linux |
| 125 | + if: runner.os == 'Linux' |
| 126 | + shell: bash |
| 127 | + run: cmake --build build --config "${BUILD_TYPE}" --parallel |
| 128 | + |
| 129 | + - name: Package Windows bundle |
| 130 | + if: runner.os == 'Windows' |
| 131 | + shell: pwsh |
| 132 | + env: |
| 133 | + BUILD_DIR: ${{ github.workspace }}\build |
| 134 | + DIST_DIR: ${{ github.workspace }}\dist |
| 135 | + VCPKG_TRIPLET: ${{ matrix.vcpkg_triplet }} |
| 136 | + run: .\scripts\package-windows.ps1 |
| 137 | + |
| 138 | + - name: Package Linux artifact |
| 139 | + if: runner.os == 'Linux' |
| 140 | + shell: bash |
| 141 | + run: | |
| 142 | + package_dir="dist/${{ matrix.artifact_name }}" |
| 143 | + mkdir -p "${package_dir}" |
| 144 | + cp "build/bin/${APP_NAME}" "${package_dir}/" |
| 145 | + cp README.md "${package_dir}/" |
| 146 | + if [ -f "models/cat_vs_dog/best.onnx" ]; then |
| 147 | + mkdir -p "${package_dir}/models/cat_vs_dog" |
| 148 | + cp "models/cat_vs_dog/best.onnx" "${package_dir}/models/cat_vs_dog/" |
| 149 | + fi |
| 150 | + tar -C dist -czf "dist/${{ matrix.artifact_name }}.tar.gz" "${{ matrix.artifact_name }}" |
| 151 | +
|
| 152 | + - name: Upload Windows artifact |
| 153 | + if: runner.os == 'Windows' |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: ${{ matrix.artifact_name }} |
| 157 | + path: dist/${{ matrix.artifact_name }}.zip |
| 158 | + if-no-files-found: error |
| 159 | + |
| 160 | + - name: Upload Linux artifact |
| 161 | + if: runner.os == 'Linux' |
| 162 | + uses: actions/upload-artifact@v4 |
| 163 | + with: |
| 164 | + name: ${{ matrix.artifact_name }} |
| 165 | + path: dist/${{ matrix.artifact_name }}.tar.gz |
| 166 | + if-no-files-found: error |
| 167 | + |
| 168 | + - name: Publish GitHub Release |
| 169 | + if: runner.os == 'Windows' && github.ref_type == 'tag' |
| 170 | + uses: softprops/action-gh-release@v2 |
| 171 | + with: |
| 172 | + files: dist/${{ matrix.artifact_name }}.zip |
| 173 | + generate_release_notes: true |
0 commit comments