diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 374c64a6f..4ff06dd9c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -17,86 +17,37 @@ jobs: (github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'no_ci')) strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + config: + - os: ubuntu-latest + if: always() + python-versions: ${{((github.event_name == 'workflow_dispatch') && ['3.10', '3.11', '3.12'] || ['3.10', '3.12'])}} + tox-skip-env: ${{((github.event_name == 'workflow_dispatch') && '' || '.*?(py311).*?')}} + coverage: true + - os: windows-latest + if: always() + python-versions: ${{((github.event_name == 'workflow_dispatch') && ['3.10', '3.11', '3.12'] || ['3.10', '3.12'])}} + tox-skip-env: ${{((github.event_name == 'workflow_dispatch') && '' || '.*?(py311).*?')}} + coverage: false + - os: macos-latest + if: always() + python-versions: ${{((github.event_name == 'workflow_dispatch') && ['3.10', '3.11', '3.12'] || ['3.10', '3.12'])}} + tox-skip-env: ${{((github.event_name == 'workflow_dispatch') && '' || '.*?(py311).*?')}} + coverage: false + - os: macos-13 + if: ${{((github.event_name == 'workflow_dispatch') + python-versions: ['3.10', '3.11', '3.12'] + tox-skip-env: '' + coverage: false fail-fast: false - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Ensure tags are fetched for versioning - fetch-tags: true - - uses: actions/setup-python@v5 - with: - python-version: | - 3.10 - 3.11 - 3.12 - - name: Install llvm on MacOS - if: startsWith(matrix.os, 'macos') - shell: bash -l {0} - env: - # Homebrew location is different on Intel Mac - LLVM_DIR: ${{ (matrix.os == 'macos-13') && '/usr/local/opt/llvm' || '/opt/homebrew/opt/llvm' }} - run: | - brew install llvm - echo CC="${LLVM_DIR}/bin/clang" >> $GITHUB_ENV - echo LDFLAGS="-L${LLVM_DIR}/lib $LDFLAGS" >> $GITHUB_ENV - echo CPPFLAGS="-I${LLVM_DIR}/include $CPPFLAGS" >> $GITHUB_ENV - - - name: Windows - find MSVC and set environment variables - if: startsWith(matrix.os, 'windows') - shell: bash -l {0} - env: - MSVC_PREFIX: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' - run: | - echo "Available MSVC installations:" - ls "$MSVC_PREFIX" - - MSVC_BIN=$(ls "$MSVC_PREFIX" | tail -n 1)\\bin\\HostX64\\x64 - CC="$MSVC_PREFIX\\$MSVC_BIN\\cl.exe" - echo "CC: $CC" - echo "CC=$CC" >> $GITHUB_ENV - - CC_LD="$MSVC_PREFIX\\$MSVC_BIN\\link.exe" - echo "CC_LD: $CC_LD" - echo "CC_LD=$CC_LD" >> $GITHUB_ENV - - - name: Update pip and install dependencies - shell: bash -l {0} - run: | - python -m pip install --upgrade pip - python -m pip install -r tests_and_analysis/ci_requirements.txt - - - name: Run tests, skip Python 3.11 unless workflow dispatch - if: github.event_name != 'workflow_dispatch' - env: - TOX_SKIP_ENV: '.*?(py311).*?' - shell: bash -l {0} - run: python -m tox run-parallel - - - name: Run tests, workflow dispatch so test all Python versions - if: github.event_name == 'workflow_dispatch' - shell: bash -l {0} - run: python -m tox run-parallel - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v4 - with: - name: Unit test results ${{ matrix.os }} - path: tests_and_analysis/test/reports/junit_report*.xml - - name: Publish Codacy coverage - uses: codacy/codacy-coverage-reporter-action@v1 - if: startsWith(matrix.os, 'ubuntu') - with: - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: tests_and_analysis/test/reports/coverage*.xml - - uses: codecov/codecov-action@v3 - if: startsWith(matrix.os, 'ubuntu') - with: - files: tests_and_analysis/test/reports/coverage*.xml + uses: ./.github/workflows/test_checkout_one_os.yml + with: + if: ${{ matrix.config.if }} + os: ${{ matrix.config.os }} + python-versions: ${{ matrix.config.python-versions }} + tox-skip-env: ${{ matrix.config.tox-skip-env }} + coverage: ${{ matrix.config.converage }} test-docs: runs-on: ubuntu-latest diff --git a/.github/workflows/test_checkout_one_os.yml b/.github/workflows/test_checkout_one_os.yml new file mode 100644 index 000000000..d122f787e --- /dev/null +++ b/.github/workflows/test_checkout_one_os.yml @@ -0,0 +1,103 @@ +name: Run tests from source on one platform +# Logic based on https://stackoverflow.com/a/73953210 +on: + workflow_call: + inputs: + if: + description: 'Run this job' + required: false + default: true + type: boolean + os: + description: 'Target platform' + required: false + default: ubuntu-latest + type: string + python-versions: + description: 'Python versions' + required: false + default: ['3.10', '3.11', '3.12'] + tox-skip-env: + description: 'Regex for skipped tests' + required: false + # default: '.*?(py311).*?' + default: '' + type: string + coverage: + description: 'Publish coverage' + required: false + default: false + type: boolean + +jobs: + test: + if: ${{ inputs.if }} + runs-on: ${{ inputs.os }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensure tags are fetched for versioning + fetch-tags: true + - uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-versions }} + - name: Install llvm on MacOS + if: startsWith(${{ inputs.os }}, 'macos') + shell: bash -l {0} + env: + # Homebrew location is different on Intel Mac + LLVM_DIR: ${{ (${{ inputs.os }} == 'macos-13') && '/usr/local/opt/llvm' || '/opt/homebrew/opt/llvm' }} + run: | + brew install llvm + echo CC="${LLVM_DIR}/bin/clang" >> $GITHUB_ENV + echo LDFLAGS="-L${LLVM_DIR}/lib $LDFLAGS" >> $GITHUB_ENV + echo CPPFLAGS="-I${LLVM_DIR}/include $CPPFLAGS" >> $GITHUB_ENV + + - name: Windows - find MSVC and set environment variables + if: startsWith(${{ inputs.os }}, 'windows') + shell: bash -l {0} + env: + MSVC_PREFIX: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' + run: | + echo "Available MSVC installations:" + ls "$MSVC_PREFIX" + + MSVC_BIN=$(ls "$MSVC_PREFIX" | tail -n 1)\\bin\\HostX64\\x64 + CC="$MSVC_PREFIX\\$MSVC_BIN\\cl.exe" + echo "CC: $CC" + echo "CC=$CC" >> $GITHUB_ENV + + CC_LD="$MSVC_PREFIX\\$MSVC_BIN\\link.exe" + echo "CC_LD: $CC_LD" + echo "CC_LD=$CC_LD" >> $GITHUB_ENV + + - name: Update pip and install dependencies + shell: bash -l {0} + run: | + python -m pip install --upgrade pip + python -m pip install -r tests_and_analysis/ci_requirements.txt + + - name: Run tests + env: + TOX_SKIP_ENV: ${{ inputs.tox-skip-env }} + shell: bash -l {0} + run: python -m tox run-parallel + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Unit test results ${{ inputs.os }} + path: tests_and_analysis/test/reports/junit_report*.xml + + - name: Publish Codacy coverage + uses: codacy/codacy-coverage-reporter-action@v1 + if: ${{ inputs.coverage }} + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: tests_and_analysis/test/reports/coverage*.xml + + - uses: codecov/codecov-action@v3 + if: ${{ inputs.coverage }} + with: + files: tests_and_analysis/test/reports/coverage*.xml