From 284b12415638085fbc664b10b07ea3913d6d21b7 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 12 Apr 2024 09:08:47 -0700 Subject: [PATCH] Migrate CI to use Github Actions (#6075) Migrate CI to use Github Actions. Update Google Test to a newer version (some version in 2022). The latest commit has errors I don't know how to fix. Use `FetchContent` instead of `ExternalProject` to bring in googletest according to its documentation https://google.github.io/googletest/quickstart-cmake.html Fixes https://github.com/onnx/onnx/issues/6074 Fixes https://github.com/onnx/onnx/issues/6073 --------- Signed-off-by: Justin Chu --- .azure-pipelines/Linux-CI.yml | 154 --------------- .azure-pipelines/MacOS-CI.yml | 138 -------------- .azure-pipelines/Windows-CI.yml | 142 -------------- .github/workflows/main.yml | 200 ++++++++++++++++++++ .github/workflows/release_linux_aarch64.yml | 4 + .github/workflows/release_linux_x86_64.yml | 4 + .github/workflows/release_mac.yml | 4 + .github/workflows/release_win.yml | 4 + CMakeLists.txt | 8 +- cmake/external/googletest.cmake | 49 +---- cmake/unittest.cmake | 10 +- 11 files changed, 230 insertions(+), 487 deletions(-) delete mode 100644 .azure-pipelines/Linux-CI.yml delete mode 100644 .azure-pipelines/MacOS-CI.yml delete mode 100644 .azure-pipelines/Windows-CI.yml create mode 100644 .github/workflows/main.yml diff --git a/.azure-pipelines/Linux-CI.yml b/.azure-pipelines/Linux-CI.yml deleted file mode 100644 index c1d24d6e739..00000000000 --- a/.azure-pipelines/Linux-CI.yml +++ /dev/null @@ -1,154 +0,0 @@ -# Copyright (c) ONNX Project Contributors -# -# SPDX-License-Identifier: Apache-2.0 - -schedules: -- cron: '0 0 * * *' - displayName: Nightly Linux CI in main branch - branches: - include: - - main - -trigger: -- gh-readonly-queue/** - -jobs: -- job: 'Test' - pool: - vmImage: 'Ubuntu-20.04' - strategy: - matrix: - py312-internal-protobuf: - python.version: '3.12' - onnx_ml: 1 - build_type: 'Release' - documentation: 0 - protobuf_type: 'Internal' - py311-ml-debug-external-protobuf: - python.version: '3.11' - onnx_ml: 1 - build_type: 'Debug' - documentation: 0 - protobuf_type: 'External' - py310-internal-protobuf: - python.version: '3.10' - onnx_ml: 0 - build_type: 'Release' - documentation: 0 - protobuf_type: 'Internal' - py39-ml-doc-external-protobuf: - python.version: '3.9' - onnx_ml: 1 - build_type: 'Release' - documentation: 1 - protobuf_type: 'External' - py38-internal-protobuf: - python.version: '3.8' - onnx_ml: 0 - build_type: 'Release' - documentation: 0 - protobuf_type: 'Internal' - maxParallel: 4 - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - addToPath: true - - - script: | - python -m pip -q install virtualenv - python -m virtualenv venv - source venv/bin/activate - - if [ '$(protobuf_type)' == 'External' ]; then - sudo apt-get install libprotobuf-dev protobuf-compiler - elif [ '$(protobuf_type)' == 'Internal' ]; then - echo "Use the internal protobuf build" - fi - - python -m pip install --upgrade pip - python -m pip install -r requirements-release.txt - # still test protobuf==3.20.2 at least in a CI - python -m pip install protobuf==3.20.2 - - sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y --no-install-recommends dos2unix - - git submodule update --init --recursive - export ONNX_BUILD_TESTS=1 - if [ '$(build_type)' == 'Debug' ]; then - export DEBUG=1 - fi - if [ '$(onnx_ml)' == '1' ]; then - export ONNX_ML=1 - fi - export CMAKE_ARGS="-DONNX_WERROR=ON -DONNX_USE_PROTOBUF_SHARED_LIBS=ON" - # Enable more sanitizers - export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_CXX_FLAGS='-fsanitize=undefined -fno-sanitize-recover=all '" - pip install -e ".[reference]" -v - displayName: 'Install ONNX and dependencies' - - - script: | - source venv/bin/activate - - pytest -sv --cov=onnx --cov-report=xml --cov-append --cov-branch --junit-xml pytest.xml -n auto --dist loadscope - if [ $? -ne 0 ]; then - echo "pytest failed" - exit 1 - fi - - # onnx c++ API tests - export LD_LIBRARY_PATH="./.setuptools-cmake-build/:$LD_LIBRARY_PATH" - ./.setuptools-cmake-build/onnx_gtests - if [ $? -ne 0 ]; then - echo "onnx_gtests failed" - exit 1 - fi - - displayName: 'Run ONNX tests' - - - script: | - curl -Os https://uploader.codecov.io/latest/linux/codecov - chmod +x codecov - ./codecov - - continueOnError: true - displayName: 'Upload to codecov' - - - script: | - source venv/bin/activate - python onnx/backend/test/cmd_tools.py generate-data --clean - git status - # Skip *output_*.pb because NumPy functions might behave differently on different platforms - # Skip test_log's input.pb because it uses np.random, which might behave differently on different platforms - git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb' - if [ $? -ne 0 ]; then - echo "git diff for test generation returned failures. Please check updated node test files" - exit 1 - fi - git diff --exit-code --diff-filter=ADR -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' - if [ $? -ne 0 ]; then - echo "Test generation returned failures. Please check the number of node test files (input_*.pb or output_*.pb)" - exit 1 - fi - - pip uninstall -y pillow - python onnx/backend/test/cmd_tools.py generate-data --clean - git status - # Verify test generation without pillow for ImageDecoder, it should directly use frozen data - git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb' - if [ $? -ne 0 ]; then - echo "git diff for test generation without pillow returned failures. Please check updated node test files" - exit 1 - fi - - displayName: Test backend test data - - - script: | - if [ '$(documentation)' == '1' ]; then - source venv/bin/activate - pip install -r docs/docsgen/source/requirements.txt - cd docs/docsgen && make text - fi - displayName: Test documentation - continueOnError: true # the documentation generates errors due to operators documentation diff --git a/.azure-pipelines/MacOS-CI.yml b/.azure-pipelines/MacOS-CI.yml deleted file mode 100644 index 6e2bf282515..00000000000 --- a/.azure-pipelines/MacOS-CI.yml +++ /dev/null @@ -1,138 +0,0 @@ -# Copyright (c) ONNX Project Contributors -# -# SPDX-License-Identifier: Apache-2.0 - -schedules: -- cron: '0 0 * * *' - displayName: Nightly MacOS CI in main branch - branches: - include: - - main - -trigger: -- gh-readonly-queue/** - -jobs: -- job: 'Test' - pool: - vmImage: 'macOS-11' - strategy: - matrix: - py312-internal-protobuf: - python.version: '3.12' - onnx_ml: 1 - build_type: 'Release' - documentation: 0 - protobuf_type: 'Internal' - py311-external-protobuf: - python.version: '3.11' - onnx_ml: 0 - build_type: 'Release' - protobuf_type: 'External' - onnx_lite: 0 - py310-lite-internal-protobuf: - python.version: '3.10' - onnx_ml: 0 - build_type: 'Release' - protobuf_type: 'Internal' - onnx_lite: 1 - py39-ml-lite-external-protobuf: - python.version: '3.9' - onnx_ml: 1 - build_type: 'Release' - protobuf_type: 'External' - onnx_lite: 1 - py38-ml-debug-external-protobuf: - python.version: '3.8' - onnx_ml: 1 - build_type: 'Debug' - protobuf_type: 'External' - onnx_lite: 0 - maxParallel: 4 - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - - - script: | - # Install Protobuf from source - export NUM_CORES=`sysctl -n hw.logicalcpu` - if [ '$(build_type)' == 'Debug' ]; then - export DEBUG=1 - fi - if [ '$(protobuf_type)' == 'External' ]; then - source workflow_scripts/protobuf/build_protobuf_unix.sh $NUM_CORES $(pwd)/protobuf/protobuf_install $(build_type) - elif [ '$(protobuf_type)' == 'Internal' ]; then - echo "Use the internal protobuf build" - fi - - git submodule update --init --recursive - python -m pip install --upgrade pip - python -m pip install -r requirements-release.txt - - if [ '$(onnx_ml)' == '1' ]; then - export ONNX_ML=1 - fi - export ONNX_BUILD_TESTS=1 - export CMAKE_ARGS="-DONNX_WERROR=ON" - if [ '$(onnx_lite)' == '1' ]; then - export CMAKE_ARGS="${CMAKE_ARGS} -DONNX_USE_LITE_PROTO=ON" - fi - pip install -e ".[reference]" -v - displayName: 'Install dependencies and ONNX' - - - script: | - pytest -n auto --dist loadscope - if [ $? -ne 0 ]; then - echo "pytest failed" - exit 1 - fi - - python -m pip install onnxruntime - export ORT_MAX_IR_SUPPORTED_VERSION=9 - export ORT_MAX_ML_OPSET_SUPPORTED_VERSION=3 - export ORT_MAX_ONNX_OPSET_SUPPORTED_VERSION=20 - pytest -n auto --dist loadscope - if [ $? -ne 0 ]; then - echo "pytest failed when testing onnx with onnxruntime" - exit 1 - fi - - # onnx c++ API tests - export LD_LIBRARY_PATH="./.setuptools-cmake-build/:$LD_LIBRARY_PATH" - ./.setuptools-cmake-build/onnx_gtests - if [ $? -ne 0 ]; then - echo "onnx_gtests failed" - exit 1 - fi - - python onnx/backend/test/cmd_tools.py generate-data --clean - git status - git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb' - if [ $? -ne 0 ]; then - echo "git diff for test generation returned failures. Please check updated node test files" - exit 1 - fi - git diff --exit-code --diff-filter=ADR -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' - if [ $? -ne 0 ]; then - echo "Test generation returned failures. Please check the number of node test files (input_*.pb or output_*.pb)" - exit 1 - fi - - pip uninstall -y pillow - python onnx/backend/test/cmd_tools.py generate-data --clean - git status - git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb' - if [ $? -ne 0 ]; then - echo "git diff for test generation without pillow returned failures. Please check updated node test files" - exit 1 - fi - # Internal Protobuf won't have other untrack files like protobuf/ - if [ '$(protobuf_type)' == 'Internal' ]; then - if [[ $(git ls-files --others --exclude-standard) ]]; then - echo "Some test-generated files not included in the PR. Did you forget to add any test-generated files?" - exit 1 - fi - fi - displayName: 'Run ONNX Tests' diff --git a/.azure-pipelines/Windows-CI.yml b/.azure-pipelines/Windows-CI.yml deleted file mode 100644 index f30716be376..00000000000 --- a/.azure-pipelines/Windows-CI.yml +++ /dev/null @@ -1,142 +0,0 @@ -# Copyright (c) ONNX Project Contributors -# -# SPDX-License-Identifier: Apache-2.0 - -schedules: -- cron: '0 0 * * *' - displayName: Nightly Windows CI in main branch - branches: - include: - - main - -trigger: -- gh-readonly-queue/** - -jobs: - -- job: 'Test' - pool: - vmImage: 'windows-2019' - strategy: - matrix: - py312-internal-protobuf: - python.version: '3.12' - onnx_ml: 1 - build_type: 'Release' - documentation: 0 - protobuf_type: 'Internal' - py311-ml-external-protobuf: - python.version: '3.11' - onnx_ml: 1 - onnx_verify_proto: 0 - protobuf_type: 'External' - py310_verify_proto_internal_protobuf: - python.version: '3.10' - onnx_ml: 0 - onnx_verify_proto: 1 - protobuf_type: 'Internal' - py39_ml_external_protobuf: - python.version: '3.9' - onnx_ml: 1 - onnx_verify_proto: 0 - protobuf_type: 'External' - py38_verify_proto_internal_protobuf: - python.version: '3.8' - onnx_ml: 0 - onnx_verify_proto: 1 - protobuf_type: 'Internal' - maxParallel: 4 - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - architecture: 'x64' - - - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - displayName: Add conda to PATH - - - script: | - conda create --yes --quiet --name py$(python.version) python=$(python.version) - if '$(protobuf_type)' == 'External' ( - conda install -n py$(python.version) -y -c conda-forge numpy libprotobuf==3.21.5 - ) else ( - conda install -n py$(python.version) -y -c conda-forge numpy - ) - displayName: Create Anaconda environment - - - powershell: echo "##vso[task.setvariable variable=CMAKE_PREFIX_PATH]$env:CONDA/envs/py$(python.version)/Library" - displayName: Set CMAKE_PREFIX_PATH - - - script: | - call activate py$(python.version) - python -m pip install --upgrade pip - python -m pip install -r requirements-release.txt - - git submodule update --init --recursive - set ONNX_BUILD_TESTS=1 - set ONNX_ML=$(onnx_ml) - set ONNX_VERIFY_PROTO_3=$(onnx_verify_proto) - if '$(protobuf_type)' == 'External' ( - set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DONNX_WERROR=ON - ) else ( - REM Disable ONNX_WERROR since the new protobuf version has build warnings that are treated as errors. - set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DONNX_USE_LITE_PROTO=ON -DONNX_WERROR=OFF - ) - - pip install -e ".[reference]" -v - pytest -n auto --dist loadscope - IF NOT %ERRORLEVEL% EQU 0 ( - @echo "pytest failed" - EXIT 1 - ) - - python onnx/backend/test/cmd_tools.py generate-data --clean - git status - git diff --exit-code -- . :!onnx/onnx-data.proto :!onnx/onnx-data.proto3 :!*output_*.pb :!*input_*.pb - IF NOT %ERRORLEVEL% EQU 0 ( - @echo "git diff for test generation returned failures. Please check updated node test files" - EXIT 1 - ) - git diff --exit-code --diff-filter=ADR -- . :!onnx/onnx-data.proto :!onnx/onnx-data.proto3 - IF NOT %ERRORLEVEL% EQU 0 ( - @echo "Test generation returned failures. Please check the number of node test files (input_*.pb or output_*.pb)." - EXIT 1 - ) - - pip uninstall -y pillow - python onnx/backend/test/cmd_tools.py generate-data --clean - git status - git diff --exit-code -- . :!onnx/onnx-data.proto :!onnx/onnx-data.proto3 :!*output_*.pb :!*input_*.pb - IF NOT %ERRORLEVEL% EQU 0 ( - @echo "git diff for test generation without pillow returned failures. Please check updated node test files" - EXIT 1 - ) - - rm -rf .setuptools-cmake-build - if '$(protobuf_type)' == 'External' ( - conda install -y -c conda-forge libprotobuf=3.20 - ) - displayName: Install and test ONNX - - - script: | - if '$(protobuf_type)' == 'External' ( - call activate py$(python.version) - python -m pip install protobuf==3.20.2 - - set ONNX_BUILD_TESTS=1 - set ONNX_ML=$(onnx_ml) - set CMAKE_ARGS=-DONNX_USE_PROTOBUF_SHARED_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DONNX_WERROR=ON - python -m pip install -r requirements-release.txt - pip uninstall -y onnx - pip install . - - pytest -n auto --dist loadscope - IF NOT %ERRORLEVEL% EQU 0 ( - @echo "pytest failed when testing onnx with libprotobuf=3.20" - EXIT 1 - ) - ) else ( - REM Skip the test for externally installing lower version of Protobuf. - ) - displayName: Test Protobuf 3.20 from conda-forge diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000000..b84942233aa --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,200 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + merge_group: + workflow_dispatch: + +permissions: # set top-level default permissions as security best practice + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + +jobs: + test: + name: "Test" + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest,macos-latest] + python_version: ['3.12', '3.11', '3.10', '3.9', '3.8'] + include: + - python_version: '3.12' + onnx_ml: 1 + debug_build: 1 + documentation: 1 + protobuf_type: 'Internal' + - python_version: '3.11' + onnx_ml: 1 + debug_build: 0 + documentation: 0 + protobuf_type: 'External' + - python_version: '3.10' + onnx_ml: 0 + debug_build: 0 + documentation: 0 + protobuf_type: 'Internal' + - python_version: '3.9' + onnx_ml: 1 + debug_build: 0 + documentation: 0 + protobuf_type: 'External' + - python_version: '3.8' + onnx_ml: 0 + debug_build: 0 + documentation: 0 + protobuf_type: 'Internal' + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python_version }} + + - name: Show versions + run: | + python --version + cmake --version + + - name: Install external protobuf - Linux + if: matrix.protobuf_type == 'External' && matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install libprotobuf-dev protobuf-compiler + + - name: Install external protobuf - MacOS + if: matrix.protobuf_type == 'External' && matrix.os == 'macos-latest' + run: | + source workflow_scripts/protobuf/build_protobuf_unix.sh 3 $(pwd)/protobuf/protobuf_install + + - name: Set up MSBuild + if: matrix.os == 'windows-latest' + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0 + with: + msbuild-architecture: ${{ matrix.architecture }} + + - name: Install external protobuf - Windows + if: matrix.protobuf_type == 'External' && matrix.os == 'windows-latest' + run: | + workflow_scripts/protobuf/build_protobuf_win.ps1 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements-release.txt + python -m pip install protobuf==3.20.2 + git submodule update --init --recursive + + - name: Build and install ONNX - Linux + if: matrix.os == 'ubuntu-latest' + run: | + if [ "${{ matrix.protobuf_type }}" == "External" ]; then + export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DONNX_USE_PROTOBUF_SHARED_LIBS=ON" + fi + pip install -e ".[reference]" -v + env: + DEBUG: ${{ matrix.debug_build }} + ONNX_ML: ${{ matrix.onnx_ml }} + ONNX_BUILD_TESTS: 1 + CMAKE_ARGS: "-DONNX_WERROR=ON -DCMAKE_CXX_FLAGS='-fsanitize=undefined -fno-sanitize-recover=all '" + + - name: Build and install ONNX - MacOS + if: matrix.os == 'macos-latest' + run: | + pip install -e ".[reference]" -v + env: + DEBUG: ${{ matrix.debug_build }} + ONNX_ML: ${{ matrix.onnx_ml }} + ONNX_BUILD_TESTS: 1 + CMAKE_ARGS: "-DONNX_WERROR=ON" + + - name: Build and install ONNX - Windows + if: matrix.os == 'windows-latest' + run: | + pip install -e ".[reference]" -v + env: + DEBUG: ${{ matrix.debug_build }} + ONNX_ML: ${{ matrix.onnx_ml }} + ONNX_BUILD_TESTS: 1 + CMAKE_ARGS: "-DONNX_WERROR=OFF -DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DONNX_USE_LITE_PROTO=ON" + + - name: Run Python tests + run: | + pytest -sv --cov=onnx --cov-report=xml --cov-append --cov-branch --junit-xml pytest.xml -n auto --dist loadscope + + - name: Run C++ tests + if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' + run: | + export LD_LIBRARY_PATH="./.setuptools-cmake-build/:$LD_LIBRARY_PATH" + ./.setuptools-cmake-build/onnx_gtests + + - name: Upload coverage to Codecov + if: always() + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: Test Results (${{ matrix.os }}-{{ matrix.python_version }}) + path: pytest.xml + + - name: Test backend test data + if: matrix.documentation == 1 && matrix.os == 'ubuntu-latest' + run: | + python onnx/backend/test/cmd_tools.py generate-data --clean + git status + git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb' + if [ $? -ne 0 ]; then + echo "git diff for test generation returned failures. Please check updated node test files" + exit 1 + fi + git diff --exit-code --diff-filter=ADR -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' + if [ $? -ne 0 ]; then + echo "Test generation returned failures. Please check the number of node test files (input_*.pb or output_*.pb)" + exit 1 + fi + pip uninstall -y pillow + python onnx/backend/test/cmd_tools.py generate-data --clean + git status + git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb' + if [ $? -ne 0 ]; then + echo "git diff for test generation without pillow returned failures. Please check updated node test files" + exit 1 + fi + + - name: Test documentation + if: matrix.documentation == 1 + run: | + pip install -r docs/docsgen/source/requirements.txt + cd docs/docsgen && make text + continue-on-error: true + + publish-test-results: + name: "Publish Test Results to Github" + needs: test + runs-on: ubuntu-latest + permissions: + checks: write + # only needed unless run with comment_mode: off + pull-requests: write + if: always() + steps: + - name: Download Artifacts + uses: actions/download-artifact@v3 + with: + path: artifacts + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + with: + files: "artifacts/**/*.xml" diff --git a/.github/workflows/release_linux_aarch64.yml b/.github/workflows/release_linux_aarch64.yml index 6a0d6e3eaeb..fee7e8397a3 100644 --- a/.github/workflows/release_linux_aarch64.yml +++ b/.github/workflows/release_linux_aarch64.yml @@ -13,6 +13,10 @@ on: permissions: # set top-level default permissions as security best practice contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + jobs: build: if: github.event_name != 'pull_request' || startsWith( github.base_ref, 'rel-') || contains( github.event.pull_request.labels.*.name, 'run release CIs') diff --git a/.github/workflows/release_linux_x86_64.yml b/.github/workflows/release_linux_x86_64.yml index 3cfeaa7b7b2..a5c004644e8 100644 --- a/.github/workflows/release_linux_x86_64.yml +++ b/.github/workflows/release_linux_x86_64.yml @@ -13,6 +13,10 @@ on: permissions: # set top-level default permissions as security best practice contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + jobs: build: if: github.event_name != 'pull_request' || startsWith( github.base_ref, 'rel-') || contains( github.event.pull_request.labels.*.name, 'run release CIs') diff --git a/.github/workflows/release_mac.yml b/.github/workflows/release_mac.yml index a1ac311bcb9..0a541a1633b 100644 --- a/.github/workflows/release_mac.yml +++ b/.github/workflows/release_mac.yml @@ -17,6 +17,10 @@ env: permissions: contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + jobs: build: if: github.event_name != 'pull_request' || startsWith( github.base_ref, 'rel-') || contains( github.event.pull_request.labels.*.name, 'run release CIs') diff --git a/.github/workflows/release_win.yml b/.github/workflows/release_win.yml index 1872fed6121..dde32ed9b3a 100644 --- a/.github/workflows/release_win.yml +++ b/.github/workflows/release_win.yml @@ -13,6 +13,10 @@ on: permissions: # set top-level default permissions as security best practice contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + jobs: build: if: github.event_name != 'pull_request' || startsWith( github.base_ref, 'rel-') || contains( github.event.pull_request.labels.*.name, 'run release CIs') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6550fc464f0..c26b312b15b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # Minimum CMake required -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.14) include(cmake/Utils.cmake) # Set default build type if(NOT CMAKE_BUILD_TYPE) @@ -119,13 +119,11 @@ endif() if(ONNX_BUILD_TESTS) find_package(GTest) - if(GTest_FOUND) - set(googletest_INCLUDE_DIRS) - set(googletest_STATIC_LIBRARIES GTest::gtest) - else() + if(NOT GTest_FOUND) list(APPEND CMAKE_MODULE_PATH ${ONNX_ROOT}/cmake/external) include(googletest) endif() + set(googletest_STATIC_LIBRARIES GTest::gtest) endif() if((ONNX_USE_LITE_PROTO AND TARGET protobuf::libprotobuf-lite) OR ((NOT ONNX_USE_LITE_PROTO) AND TARGET protobuf::libprotobuf)) diff --git a/cmake/external/googletest.cmake b/cmake/external/googletest.cmake index e5a89965585..9f88d3c9b79 100644 --- a/cmake/external/googletest.cmake +++ b/cmake/external/googletest.cmake @@ -2,45 +2,12 @@ # # SPDX-License-Identifier: Apache-2.0 -include (ExternalProject) - -set(googletest_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/googletest/src/googletest/googletest/include) -set(googletest_URL https://github.com/google/googletest.git) -set(googletest_BUILD ${CMAKE_CURRENT_BINARY_DIR}/googletest/) -set(googletest_TAG e93da23920e5b6887d6a6a291c3a59f83f5b579e) -#0fe96607d85cf3a25ac40da369db62bbee2939a5 - -if(WIN32 AND CMAKE_BUILD_TYPE MATCHES Debug) - set(googletest_STATIC_LIBRARIES - ${CMAKE_CURRENT_BINARY_DIR}/googletest/src/googletest/googletest/Debug/gtestd.lib) -elseif(WIN32 AND NOT CMAKE_BUILD_TYPE MATCHES Debug) - set(googletest_STATIC_LIBRARIES - ${CMAKE_CURRENT_BINARY_DIR}/googletest/src/googletest/googletest/Release/gtest.lib) -elseif(CMAKE_BUILD_TYPE MATCHES Debug) - set(googletest_STATIC_LIBRARIES - ${CMAKE_CURRENT_BINARY_DIR}/googletest/src/googletest/googletest/libgtestd.a) -else() - set(googletest_STATIC_LIBRARIES - ${CMAKE_CURRENT_BINARY_DIR}/googletest/src/googletest/googletest/libgtest.a) -endif() - -if(ONNX_USE_MSVC_STATIC_RUNTIME) - set(ONNX_USE_MSVC_SHARED_RUNTIME OFF) -else() - set(ONNX_USE_MSVC_SHARED_RUNTIME ON) -endif() -ExternalProject_Add(googletest - PREFIX googletest - GIT_REPOSITORY ${googletest_URL} - GIT_TAG ${googletest_TAG} - DOWNLOAD_DIR "${DOWNLOAD_LOCATION}" - BUILD_IN_SOURCE 1 - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} --target gtest - INSTALL_COMMAND "" - CMAKE_CACHE_ARGS - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DBUILD_GMOCK:BOOL=OFF - -DBUILD_GTEST:BOOL=ON - -Dgtest_force_shared_crt:BOOL=${ONNX_USE_MSVC_SHARED_RUNTIME} - BUILD_BYPRODUCTS ${googletest_STATIC_LIBRARIES} +include(FetchContent) +FetchContent_Declare( + googletest + # Specify the commit you depend on and update it regularly. + URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip ) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) diff --git a/cmake/unittest.cmake b/cmake/unittest.cmake index cc825a0344e..33fa7f683b6 100644 --- a/cmake/unittest.cmake +++ b/cmake/unittest.cmake @@ -24,13 +24,9 @@ function(AddTest) add_executable(${_UT_TARGET} ${_UT_SOURCES}) add_dependencies(${_UT_TARGET} onnx onnx_proto) - if(NOT GTest_FOUND) - add_dependencies(${_UT_TARGET} googletest) - endif() target_include_directories(${_UT_TARGET} - PUBLIC ${googletest_INCLUDE_DIRS} - ${ONNX_INCLUDE_DIRS} + PUBLIC ${ONNX_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS} ${ONNX_ROOT} ${CMAKE_CURRENT_BINARY_DIR}) @@ -56,9 +52,9 @@ function(AddTest) # unsigned from include\google\protob # uf\wire_format_lite.h /wd4244 # 'argument': conversion from 'google:: - # protobuf::uint64' to 'int', possible + # protobuf::uint64' to 'int', possible # loss of data - /wd4267 # Conversion from 'size_t' to 'int', + /wd4267 # Conversion from 'size_t' to 'int', # possible loss of data /wd4996 # The second parameter is ignored. )