codecov_per_test_coverage.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. name: Codecov - per test coverage
  2. # This workflow generates pytest coverage with the flag --cov-context=test
  3. # This coverage is used as input for Codecov Automated Test Selection (see .github/workflows/codecov_ats.yml)
  4. # However there's a performance toll in running tests with this flag.
  5. # So we will not be running the test suite on every commit
  6. on: [workflow_dispatch, workflow_call]
  7. jobs:
  8. # Same as 'backend' in .github/workflows/backed.yml
  9. # Except for run_backend_tests step (which includes the extra --cov-context=test flag)
  10. # And the coverage generation and handling
  11. backend-test-with-cov-context:
  12. if: github.ref == 'refs/heads/master'
  13. name: backend test
  14. runs-on: ubuntu-22.04
  15. timeout-minutes: 120
  16. strategy:
  17. # This helps not having to run multiple jobs because one fails, thus, reducing resource usage
  18. # and reducing the risk that one of many runs would turn red again (read: intermittent tests)
  19. fail-fast: false
  20. matrix:
  21. # XXX: When updating this, make sure you also update MATRIX_INSTANCE_TOTAL.
  22. instance: [0, 1, 2, 3, 4, 5, 6]
  23. pg-version: ['14']
  24. env:
  25. # XXX: `MATRIX_INSTANCE_TOTAL` must be hardcoded to the length of `strategy.matrix.instance`.
  26. # If this increases, make sure to also increase `flags.backend.after_n_builds` in `codecov.yml`.
  27. MATRIX_INSTANCE_TOTAL: 7
  28. steps:
  29. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  30. with:
  31. # Avoid codecov error message related to SHA resolution:
  32. # https://github.com/codecov/codecov-bash/blob/7100762afbc822b91806a6574658129fe0d23a7d/codecov#L891
  33. fetch-depth: '2'
  34. - name: Setup sentry env
  35. uses: ./.github/actions/setup-sentry
  36. id: setup
  37. with:
  38. kafka: true
  39. snuba: true
  40. symbolicator: true
  41. # Right now, we run so few bigtable related tests that the
  42. # overhead of running bigtable in all backend tests
  43. # is way smaller than the time it would take to run in its own job.
  44. bigtable: true
  45. pg-version: ${{ matrix.pg-version }}
  46. - name: Run backend test (${{ steps.setup.outputs.matrix-instance-number }} of ${{ steps.setup.outputs.matrix-instance-total }}) with --cov-context=test
  47. id: run_backend_tests
  48. run: |
  49. make test-python-ci COV_ARGS=--cov-context=test
  50. # Separate from the testing step above so that we always create the report
  51. # Even if some tests fail
  52. - name: Create coverage report in JSON format
  53. if: ${{ always() }}
  54. run: |
  55. coverage json --show-contexts -o .artifacts/python.coverage.json
  56. # Upload coverage data even if running the tests step fails since
  57. # it reduces large coverage fluctuations
  58. - name: Upload coverage - special case to test Codecov ATS
  59. if: ${{ always() }}
  60. uses: codecov/codecov-action@v4-beta
  61. env:
  62. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  63. with:
  64. files: .artifacts/python.coverage.codecov.json
  65. flags: smart-tests
  66. plugins: compress-pycoverage
  67. continue-on-error: true