Merge pull request #45 from cappelletto/develop #30
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 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| # -------- Install deps (Ubuntu) -------- | |
| - name: Install dependencies (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential cmake ninja-build \ | |
| libopencv-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 | |
| # -------- 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: | | |
| $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") { | |
| $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}" | |
| ) | |
| } else { | |
| $cmakeArgs += @( | |
| "-DCMAKE_C_COMPILER_LAUNCHER=$env:CMAKE_C_COMPILER_LAUNCHER", | |
| "-DCMAKE_CXX_COMPILER_LAUNCHER=$env:CMAKE_CXX_COMPILER_LAUNCHER" | |
| ) | |
| } | |
| 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') # only on tag like v0.7.0 | |
| needs: [ build-test ] # wait for matrix to finish | |
| 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 }} |