CMake Build (czicompress) #97
This file contains 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: CMake Build (czicompress) | |
on: | |
push: | |
branches: ["main"] # run only when merge with main branch | |
pull_request: | |
branches: ["main"] # run only when merge with main branch | |
workflow_dispatch: {} | |
permissions: | |
contents: read | |
jobs: | |
build-tests: | |
defaults: | |
run: | |
working-directory: ${{github.workspace}}/czicompress | |
# https://stackoverflow.com/questions/69636799/how-do-i-pass-the-job-name-into-a-github-actions-input | |
env: | |
name: ${{matrix.config.name}}-${{matrix.build}} | |
name: ${{matrix.config.name}}-${{matrix.build}} | |
runs-on: ${{matrix.config.os}} | |
strategy: | |
fail-fast: false | |
matrix: | |
build: [Release, Debug] | |
config: # Create matrix with combinations of compiler and options. | |
# Notes: | |
# The property 'package' is controlling whether the build-time-dependencies (i.e. eigen3, cli11, catch2) are pulled in via the system's package manager or via CMake at build-time. | |
- { | |
name: windows-64-msvc-package-on, | |
os: windows-latest, | |
platform: x64-windows-static, | |
package: ON, | |
path-cache: '${{ github.workspace }}\vcpkg\installed', | |
path-toolchain: 'C:/vcpkg/scripts/buildsystems/vcpkg.cmake', | |
os-id: 'windows', | |
} | |
- { | |
name: ubuntu-package-off, | |
os: ubuntu-20.04, # we want to use an older version in order to increase likelihood that binaries work on other distros | |
platform: x64-linux, | |
package: OFF, | |
path-cache: '/usr/local/share/vcpkg/installed', | |
path-toolchain: '/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake', | |
os-id: 'linux', | |
} | |
exclude: | |
# From https://github.com/actions/runner/issues/1512 | |
- build: Debug | |
config: {name: ubuntu-package-off, os: ubuntu-20.04, platform: x64-linux, package: OFF, path-cache: '/usr/local/share/vcpkg/installed', path-toolchain: '/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake', os-id: 'linux'} | |
steps: | |
- name: Checkout the source codes. | |
uses: actions/checkout@v4 | |
- uses: ./.github/actions/cmake-build | |
with: | |
path-cache: ${{matrix.config.path-cache}} | |
path-toolchain: ${{matrix.config.path-toolchain}} | |
os-id: ${{matrix.config.os-id}} | |
build-type: ${{matrix.build}} | |
package: ${{matrix.config.package}} | |
platform: ${{matrix.config.platform}} | |
src-dir: '${{github.workspace}}/czicompress' | |
- name: Run unit tests | |
working-directory: ${{github.workspace}}/czicompress/build | |
# Execute tests defined by the CMake configuration. | |
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | |
run: ctest -C ${{matrix.build}} | |
# Coverage collection based on https://about.codecov.io/blog/how-to-set-up-codecov-with-c-plus-plus-and-github-actions/ | |
- name: Prepare Coverage | |
if: ${{ (matrix.config.os == 'windows-latest') && (matrix.build == 'Debug') }} | |
shell: pwsh | |
run: | | |
choco install OpenCppCoverage -y | |
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH | |
- name: Get Coverage | |
if: ${{ (matrix.config.os == 'windows-latest') && (matrix.build == 'Debug') }} | |
working-directory: ${{github.workspace}}/czicompress/build/tests/${{matrix.build}} | |
shell: cmd | |
run: OpenCppCoverage.exe --export_type cobertura:${{github.workspace}}\TestResults\coverage.xml --sources "${{github.workspace}}\czicompress" --excluded_sources "${{github.workspace}}\czicompress\tests" --modules czicompress -- czicompress_tests.exe | |
- name: Upload Coverage | |
uses: codecov/codecov-action@v3 | |
if: ${{ (matrix.config.os == 'windows-latest') && (matrix.build == 'Debug') }} | |
with: | |
files: coverage.xml | |
fail_ci_if_error: true | |
directory: ${{ github.workspace }}/TestResults | |
verbose: true | |
- name: Prepare licenses | |
if: matrix.build == 'Release' | |
shell: bash | |
run: | | |
set -e | |
mkdir ./czicompress-${{env.name}} | |
cp -R ./THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt ./czicompress-${{env.name}}/ | |
cp -R ./build/app/THIRD_PARTY_LICENSES.txt ./czicompress-${{env.name}}/ | |
# gather the binaries | |
- name: Prepare Linux binaries | |
if: ${{ (matrix.config.os == 'ubuntu-20.04') && (matrix.build == 'Release') }} | |
shell: bash | |
run: | | |
cp ./build/app/czicompress ./build/capi/libczicompressc.so ./czicompress-${{env.name}}/ | |
- name: Prepare Windows binaries | |
if: ${{ (matrix.config.os == 'windows-latest') && (matrix.build == 'Release') }} | |
shell: bash | |
run: | | |
cp ./build/app/${{matrix.build}}/*.exe ./build/capi/${{matrix.build}}/libczicompressc.dll ./czicompress-${{env.name}}/ | |
# upload the build-results to artifacts-store | |
- name: Upload artifacts | |
if: matrix.build == 'Release' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: czicompress-${{env.name}} | |
path: czicompress/czicompress-${{env.name}}/ | |
package: | |
# TODO: Restrict to runs on main only (no need to remove workflow_dispatch since -SkipDuplicate is specified) | |
needs: build-tests | |
runs-on: windows-latest | |
permissions: | |
packages: write | |
steps: | |
- name: Checkout the source codes. | |
uses: actions/checkout@v4 | |
# Download all artifacts from previous job | |
# No wildcard possible as of v3 | |
# https://github.com/actions/download-artifact/issues/6 | |
# Downloading to ${{github.workspace}} as of https://github.com/actions/download-artifact | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
- name: Copy Natives | |
run: | | |
mkdir -p ./czicompress/pack/runtimes/win-x64/native | |
mkdir -p ./czicompress/pack/runtimes/linux-x64/native | |
cp ./czicompress-windows-64-msvc-package-on-Release/libczicompressc.dll ./czicompress/pack/runtimes/win-x64/native | |
cp ./czicompress-windows-64-msvc-package-on-Release/THIRD_PARTY_LICENSES*.txt ./czicompress/pack | |
cp ./czicompress-ubuntu-package-off-Release/libczicompressc.so ./czicompress/pack/runtimes/linux-x64/native | |
# https://github.com/marketplace/actions/setup-nuget-exe-for-use-with-actions#usage | |
- uses: nuget/setup-nuget@v1 | |
with: | |
nuget-version: '>=5.1 <6' | |
- name: Get libczicompressc Version | |
# See https://github.com/orgs/community/discussions/25713 | |
# Note: FileVersionRaw.Revision is ignored as per https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#version-basics | |
shell: pwsh | |
working-directory: ${{github.workspace}}/czicompress/pack | |
run: | | |
$NewFileVersion = (Get-Item "./runtimes/win-x64/native/libczicompressc.dll").VersionInfo.FileVersionRaw | |
$NewLibVersion = $NewFileVersion.Major, $NewFileVersion.Minor, $NewFileVersion.Build | Join-String -Separator '.' | |
"LibVersion=$NewLibVersion" >> $env:GITHUB_ENV | |
- name: Create NuGet Package | |
# See https://learn.microsoft.com/en-us/nuget/reference/nuspec#replacement-tokens | |
working-directory: ${{github.workspace}}/czicompress/pack | |
run: | | |
nuget pack libczicompressc.nuspec -properties token_version=${{env.LibVersion}} | |
- uses: actions/setup-dotnet@v3 | |
# No requirements on version (only pushing) | |
# https://github.com/actions/setup-dotnet#github-package-registry-gpr | |
with: | |
source-url: https://nuget.pkg.github.com/ZEISS/index.json | |
env: | |
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
- name: Publish NuGet Package | |
working-directory: ${{github.workspace}}/czicompress/pack | |
run: | | |
dotnet nuget push libczicompressc.${{env.LibVersion}}.nupkg --skip-duplicate |