Merge pull request #77 from cappelletto/develop #48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: C/C++ CI (Linux + Windows) | |
| on: | |
| push: | |
| branches: [ master ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ master ] | |
| workflow_dispatch: {} | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ ubuntu-latest, windows-latest ] | |
| build_type: [ Release ] | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| BUILD_TYPE: ${{ matrix.build_type }} | |
| VCPKG_ROOT: ${{ github.workspace }}/vcpkg | |
| OPENCV_VERSION: "4.12.0" | |
| OPENCV_VENDOR_PREFIX: ${{ github.workspace }}/third_party/_install/opencv-4.12.0 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| # -------- Install deps (Ubuntu) -------- | |
| # NOTE: We no longer install libopencv-dev as we are bundling | |
| # and caching OpenCV 4.12 | |
| - name: Install dependencies (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential cmake ninja-build \ | |
| libavcodec-dev libavformat-dev libswscale-dev \ | |
| doxygen graphviz \ | |
| libyaml-cpp-dev \ | |
| ccache \ | |
| dpkg-dev fakeroot | |
| - name: Enable ccache (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| echo "CMAKE_C_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV | |
| echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV | |
| ccache --max-size=250M || true | |
| # Cache vendored OpenCV install (Ubuntu) | |
| - name: Cache OpenCV vendor install (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| id: cache-opencv | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.OPENCV_VENDOR_PREFIX }} | |
| key: opencv-${{ env.OPENCV_VERSION }}-${{ runner.os }}-${{ hashFiles('third_party/opencv/CMakeLists.txt') }}-ffmpegON-lapackOFF-worldOFF-v1 | |
| restore-keys: | | |
| opencv-${{ env.OPENCV_VERSION }}-${{ runner.os }}- | |
| opencv- | |
| # Build vendored OpenCV only if cache miss (Ubuntu) | |
| - name: Build vendored OpenCV (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' && steps.cache-opencv.outputs.cache-hit != 'true' | |
| run: | | |
| cmake -S third_party/opencv -B third_party/opencv/build \ | |
| -DOPENCV_VERSION=${OPENCV_VERSION} \ | |
| -DOPENCV_WITH_CONTRIB=OFF \ | |
| -DOPENCV_BUILD_WORLD=OFF | |
| cmake --build third_party/opencv/build --target opencv_src --parallel 2 | |
| test -f "${OPENCV_VENDOR_PREFIX}/lib/cmake/opencv4/OpenCVConfig.cmake" | |
| # - name: Log cache status (Ubuntu) | |
| # if: matrix.os == 'ubuntu-latest' | |
| # run: echo "OpenCV cache hit: $steps.cache-opencv.outputs.cache-hit" | |
| # -------- Windows toolchain -------- | |
| - name: Setup MSVC (Windows) | |
| if: matrix.os == 'windows-latest' | |
| uses: ilammy/msvc-dev-cmd@v1 | |
| # Set a persistent binary cache path (Windows) | |
| - name: Define vcpkg binary cache path (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $cache = "${{ github.workspace }}\.vcpkg_cache" | |
| New-Item -ItemType Directory -Force -Path $cache | Out-Null | |
| echo "VCPKG_DEFAULT_BINARY_CACHE=$cache" >> $env:GITHUB_ENV | |
| echo "VCPKG_FEATURE_FLAGS=manifests,binarycaching" >> $env:GITHUB_ENV | |
| - name: Cache vcpkg repo + binary cache (Windows) | |
| if: matrix.os == 'windows-latest' | |
| uses: actions/cache@v4 | |
| with: | |
| key: vcpkg-${{ runner.os }}-x64-windows-${{ hashFiles('vcpkg.json') }} | |
| restore-keys: | | |
| vcpkg-${{ runner.os }}-x64-windows- | |
| vcpkg-${{ runner.os }}- | |
| path: | | |
| ${{ env.VCPKG_ROOT }} | |
| ${{ github.workspace }}\.vcpkg_cache | |
| ~/.cache/vcpkg/archives | |
| - name: Install vcpkg (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| if (!(Test-Path -Path $env:VCPKG_ROOT)) { | |
| git clone https://github.com/microsoft/vcpkg $env:VCPKG_ROOT | |
| & $env:VCPKG_ROOT\bootstrap-vcpkg.bat | |
| } | |
| # Manifest mode: do NOT pass package names | |
| - name: vcpkg install (Windows, manifest) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| if (!(Test-Path -Path $env:VCPKG_DEFAULT_BINARY_CACHE)) { | |
| New-Item -ItemType Directory -Force -Path $env:VCPKG_DEFAULT_BINARY_CACHE | Out-Null | |
| } | |
| & $env:VCPKG_ROOT\vcpkg.exe install --triplet x64-windows | |
| echo "VCPKG_TOOLCHAIN=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" >> $env:GITHUB_ENV | |
| echo "VCPKG_TARGET_TRIPLET=x64-windows" >> $env:GITHUB_ENV | |
| echo "VCPKG_HOST_TRIPLET=x64-windows" >> $env:GITHUB_ENV | |
| # Tag inference mechanism | |
| - name: Derive version from tag (or fallback) | |
| shell: bash | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then | |
| echo "PKG_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV | |
| else | |
| echo "PKG_VERSION=${{ env.BUILD_TYPE }}-snapshot" >> $GITHUB_ENV | |
| fi | |
| # -------- Configure -------- | |
| - name: Configure (CMake) | |
| shell: pwsh | |
| run: | | |
| # Decide MSVC runtime first (literal values only) | |
| $msvcRuntime = if ("${{ matrix.os }}" -eq "windows-latest" -and "${{ env.BUILD_TYPE }}" -eq "Debug") { "MultiThreadedDebugDLL" } else { "MultiThreadedDLL" } | |
| # Base args | |
| $cmakeArgs = @( | |
| "-S", ".", "-B", "build", | |
| "-G", "Ninja", | |
| "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}", | |
| "-DBUILD_TESTS=ON", | |
| "-DPROJECT_VERSION=${{ env.PKG_VERSION }}", | |
| "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build/bin", | |
| "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=build/lib", | |
| "-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=build/lib" | |
| ) | |
| if ("${{ matrix.os }}" -eq "windows-latest") { | |
| # Windows: use vcpkg OpenCV; do not vendor OpenCV | |
| $cmakeArgs += @( | |
| "-DCMAKE_TOOLCHAIN_FILE=${env:VCPKG_TOOLCHAIN}", | |
| "-DVCPKG_TARGET_TRIPLET=${env:VCPKG_TARGET_TRIPLET}", | |
| "-DVCPKG_HOST_TRIPLET=${env:VCPKG_HOST_TRIPLET}", | |
| "-DVCPKG_DEFAULT_BINARY_CACHE=${env:VCPKG_DEFAULT_BINARY_CACHE}", | |
| "-DVIDEOSTRIP_BUNDLE_OPENCV=OFF", | |
| "-DCMAKE_MSVC_RUNTIME_LIBRARY=$msvcRuntime" | |
| ) | |
| } else { | |
| # Linux: vendor OpenCV and (optionally) hint OpenCV_DIR if present | |
| $cmakeArgs += @( | |
| "-DVIDEOSTRIP_BUNDLE_OPENCV=ON", | |
| "-DVIDEOSTRIP_OPENCV_VERSION=${{ env.OPENCV_VERSION }}", | |
| "-DCMAKE_C_COMPILER_LAUNCHER=$env:CMAKE_C_COMPILER_LAUNCHER", | |
| "-DCMAKE_CXX_COMPILER_LAUNCHER=$env:CMAKE_CXX_COMPILER_LAUNCHER" | |
| ) | |
| $vendorCfg = "${{ env.OPENCV_VENDOR_PREFIX }}/lib/cmake/opencv4" | |
| if (Test-Path $vendorCfg) { $cmakeArgs += @("-DOpenCV_DIR=$vendorCfg") } | |
| } | |
| cmake @cmakeArgs | |
| # -------- Build -------- | |
| - name: Build (all) | |
| run: cmake --build build --config ${{ env.BUILD_TYPE }} -- -v | |
| # -------- Test -------- | |
| - name: CTest | |
| working-directory: build | |
| run: ctest --output-on-failure -C ${{ env.BUILD_TYPE }} | |
| # -------- Upload logs on failure -------- | |
| - name: Upload test artifacts on failure | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: logs-${{ matrix.os }} | |
| path: | | |
| build/Testing/Temporary/LastTest*.log | |
| build/Testing/**/Test.xml | |
| build/bin/**/*.log | |
| if-no-files-found: ignore | |
| retention-days: 30 | |
| # -------- Package (CPack via CMake target) -------- | |
| - name: Package (CPack) | |
| if: (github.ref == 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') | |
| working-directory: build | |
| run: cmake --build . --target package --config ${{ env.BUILD_TYPE }} | |
| # -------- Upload artifacts on master/tags -------- | |
| - name: Upload artifacts (Windows ZIP) | |
| if: (matrix.os == 'windows-latest') && ((github.ref == 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v')) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: videostrip-windows-${{ env.BUILD_TYPE }} | |
| path: | | |
| build/bin/**/*.exe | |
| build/bin/**/*.pdb | |
| build/lib/**/*.lib | |
| build/*.zip | |
| build/*.tar.gz | |
| retention-days: 14 | |
| - name: Upload artifacts (Linux packages) | |
| if: (matrix.os == 'ubuntu-latest') && ((github.ref == 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v')) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: videostrip-linux-${{ env.BUILD_TYPE }} | |
| path: | | |
| build/bin/videostrip_cli | |
| build/lib/**/*.a | |
| build/*.tar.gz | |
| build/*.deb | |
| retention-days: 14 | |
| release: | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: [ build-test ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download Windows artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: videostrip-windows-Release | |
| path: artifacts/windows | |
| - name: Download Linux artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: videostrip-linux-Release | |
| path: artifacts/linux | |
| - name: List files | |
| run: find artifacts -type f -maxdepth 3 -printf "%p\n" | |
| - name: Publish GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: ${{ github.ref_name }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| artifacts/windows/*.zip | |
| artifacts/windows/*.tar.gz | |
| artifacts/linux/*.tar.gz | |
| artifacts/linux/*.deb | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |