diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1a1d7a50fc..733d1def01 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,13 @@ on: # A pre-commit hook (scripts/check_all_tests_are_covered.py) # enforces that test run just once per OS / floatX setting. +# Cancels all previous workflow runs for pull requests that have not completed. +concurrency: + # The concurrency group contains the workflow name and the branch name for pull requests + # or the commit hash for any other events. + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + jobs: changes: @@ -166,14 +173,12 @@ jobs: - name: Run tests run: | conda activate pymc-test - python -m pytest -vv --cov=pymc --cov-report=xml --no-cov-on-fail --cov-report term --durations=50 $TEST_SUBSET - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + python -m pytest -vv --cov=pymc --cov-report=xml:coverage/coverage-${{ matrix.os }}-${{ matrix.python-version }}.xml --no-cov-on-fail --cov-report term --durations=50 $TEST_SUBSET + - name: Upload coverage file + uses: actions/upload-artifact@v3 with: - token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads - env_vars: TEST_SUBSET - name: ${{ matrix.os }} ${{ matrix.floatx }} - fail_ci_if_error: false + name: coverage + path: coverage/coverage-${{ matrix.id }}.xml windows: needs: changes @@ -242,14 +247,12 @@ jobs: # The ">-" in the next line replaces newlines with spaces (see https://stackoverflow.com/a/66809682). run: >- conda activate pymc-test && - python -m pytest -vv --cov=pymc --cov-report=xml --no-cov-on-fail --cov-report term --durations=50 %TEST_SUBSET% - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + python -m pytest -vv --cov=pymc --cov-report=xml:coverage/coverage-${{ matrix.os }}-${{ matrix.python-version }}.xml --no-cov-on-fail --cov-report term --durations=50 %TEST_SUBSET% + - name: Upload coverage file + uses: actions/upload-artifact@v3 with: - token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads - env_vars: TEST_SUBSET - name: ${{ matrix.os }} ${{ matrix.floatx }} - fail_ci_if_error: false + name: coverage + path: coverage/coverage-${{ matrix.id }}.xml macos: needs: changes @@ -321,14 +324,12 @@ jobs: python --version - name: Run tests run: | - python -m pytest -vv --cov=pymc --cov-report=xml --no-cov-on-fail --cov-report term --durations=50 $TEST_SUBSET - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + python -m pytest -vv --cov=pymc --cov-report=xml:coverage/coverage-${{ matrix.os }}-${{ matrix.python-version }}.xml --no-cov-on-fail --cov-report term --durations=50 $TEST_SUBSET + - name: Upload coverage file + uses: actions/upload-artifact@v3 with: - token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads - env_vars: TEST_SUBSET - name: ${{ matrix.os }} ${{ matrix.floatx }} - fail_ci_if_error: false + name: coverage + path: coverage/coverage-${{ matrix.id }}.xml external_samplers: needs: changes @@ -394,14 +395,12 @@ jobs: pip install git+https://github.com/blackjax-devs/blackjax.git@0.7.0 - name: Run tests run: | - python -m pytest -vv --cov=pymc --cov-report=xml --no-cov-on-fail --cov-report term --durations=50 $TEST_SUBSET - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + python -m pytest -vv --cov=pymc --cov-report=xml:coverage/coverage-${{ matrix.os }}-${{ matrix.python-version }}.xml --no-cov-on-fail --cov-report term --durations=50 $TEST_SUBSET + - name: Upload coverage file + uses: actions/upload-artifact@v3 with: - token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads - env_vars: TEST_SUBSET - name: JAX tests - ${{ matrix.os }} ${{ matrix.floatx }} - fail_ci_if_error: false + name: coverage + path: coverage/coverage-${{ matrix.id }}.xml float32: needs: changes @@ -466,14 +465,12 @@ jobs: # The ">-" in the next line replaces newlines with spaces (see https://stackoverflow.com/a/66809682). run: >- conda activate pymc-test && - python -m pytest -vv --cov=pymc --cov-report=xml --no-cov-on-fail --cov-report term --durations=50 %TEST_SUBSET% - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + python -m pytest -vv --cov=pymc --cov-report=xml:coverage/coverage-${steps.matrix-id.outputs.id}.xml --no-cov-on-fail --cov-report term --durations=50 %TEST_SUBSET% + - name: Upload coverage file + uses: actions/upload-artifact@v3 with: - token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads - env_vars: TEST_SUBSET - name: ${{ matrix.os }} ${{ matrix.floatx }} - fail_ci_if_error: false + name: coverage + path: coverage/coverage-${{ matrix.id }}.xml all_tests: if: ${{ always() }} @@ -488,3 +485,33 @@ jobs: needs.external_samplers.result != 'success' || needs.float32.result != 'success' ) }} run: exit 1 + + + upload-coverage: + runs-on: ubuntu-latest + needs: [all_tests, changes] + if: ${{ needs.all_tests.result == 'success' && needs.changes.outputs.changes == 'true'}} + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install -U coverage>=5.1 coveralls + - name: Download coverage files + uses: actions/download-artifact@v3 + with: + name: coverage + path: coverage + - name: Merge coverage reports + run: | + # Find all coverage reports and merge them into a single file + python -m coverage combine --append coverage/*.xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads + directory: ./coverage/ + fail_ci_if_error: true