codecov_ats.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. name: IGNORE ME codecov-ats
  2. on:
  3. pull_request:
  4. env:
  5. CLI_VERSION: v0.1.5
  6. # Cancel in progress workflows on pull_requests.
  7. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
  8. concurrency:
  9. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  10. cancel-in-progress: true
  11. defaults:
  12. run:
  13. # the default default is:
  14. # bash --noprofile --norc -eo pipefail {0}
  15. shell: bash --noprofile --norc -eo pipefail -ux {0}
  16. jobs:
  17. files-changed:
  18. name: detect what files changed
  19. runs-on: ubuntu-20.04
  20. timeout-minutes: 3
  21. # Map a step output to a job output
  22. outputs:
  23. api_docs: ${{ steps.changes.outputs.api_docs }}
  24. backend: ${{ steps.changes.outputs.backend_all }}
  25. backend_dependencies: ${{ steps.changes.outputs.backend_dependencies }}
  26. backend_any_type: ${{ steps.changes.outputs.backend_any_type }}
  27. migration_lockfile: ${{ steps.changes.outputs.migration_lockfile }}
  28. steps:
  29. - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
  30. - name: Check for backend file changes
  31. uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
  32. id: changes
  33. with:
  34. token: ${{ github.token }}
  35. filters: .github/file-filters.yml
  36. coverage-ats:
  37. if: needs.files-changed.outputs.backend == 'true'
  38. needs: files-changed
  39. runs-on: ubuntu-latest
  40. # Map a step output to a job output
  41. outputs:
  42. ATS_TESTS_TO_RUN: ${{ steps.codecov_automated_test_selection.outputs.ATS_TESTS_TO_RUN }}
  43. ATS_TESTS_TO_SKIP: ${{ steps.codecov_automated_test_selection.outputs.ATS_TESTS_TO_SKIP }}
  44. steps:
  45. - uses: actions/checkout@v3
  46. with:
  47. # fetch-depth: 0 - Use if the BASE_COMMIT on codecov_automated_test_selection is at unknown depth
  48. # (i.e. git merge-base ${{ github.sha }}^ origin/main)
  49. # fetch-depth: 2 - Use if the BASE_COMMIT on codecov_automated_test_selection is at known depth
  50. # (i.e. git rev-parse ${{ github.sha }}^)
  51. fetch-depth: 0
  52. - name: Set up Python 3.10.10
  53. uses: actions/setup-python@v4
  54. with:
  55. python-version: "3.10.10"
  56. # We need the setup to collect the list of tests properly
  57. - name: Setup sentry env
  58. uses: ./.github/actions/setup-sentry
  59. id: setup
  60. with:
  61. snuba: true
  62. # Right now, we run so few bigtable related tests that the
  63. # overhead of running bigtable in all backend tests
  64. # is way smaller than the time it would take to run in its own job.
  65. bigtable: true
  66. pg-version: 14
  67. - name: Download Codecov CLI
  68. run: |
  69. pip install --extra-index-url https://pypi.org/simple --no-cache-dir codecov-cli>=0.4.0
  70. # Creates the commit and report objects in codecov
  71. - name: Codecov startup
  72. run: |
  73. codecovcli create-commit
  74. codecovcli create-report
  75. env:
  76. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  77. # Sends static analysis information to codecov
  78. - name: Static Analysis
  79. run: |
  80. codecovcli static-analysis --token=${CODECOV_STATIC_TOKEN} \
  81. --folders-to-exclude .artifacts \
  82. --folders-to-exclude .github \
  83. --folders-to-exclude .venv \
  84. --folders-to-exclude static \
  85. --folders-to-exclude bin
  86. env:
  87. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  88. CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
  89. # Run Automated Test Selection in dry mode to get the list of tests to run
  90. # The base commit will be the parent commit (apparently commits on master don't exist in codecov)
  91. - name: Codecov Automated Test Selection
  92. id: codecov_automated_test_selection
  93. run: |
  94. BASE_COMMIT=$(git merge-base ${{ github.sha }}^ origin/master)
  95. echo $BASE_COMMIT
  96. output=$(codecovcli --codecov-yml-path=codecov.yml label-analysis --dry-run --token=${CODECOV_STATIC_TOKEN} --base-sha=${BASE_COMMIT}) || true
  97. if [ -n "${output}" ];
  98. then
  99. echo ATS_TESTS_TO_RUN=$(jq <<< $output '.runner_options + .ats_tests_to_run | @json | @sh' --raw-output) >> "$GITHUB_OUTPUT"
  100. echo ATS_TESTS_TO_SKIP=$(jq <<< $output '.runner_options + .ats_tests_to_skip | @json | @sh' --raw-output) >> "$GITHUB_OUTPUT"
  101. testcount() { jq <<< $output ".$1 | length"; }
  102. run_count=$(testcount ats_tests_to_run)
  103. skip_count=$(testcount ats_tests_to_skip)
  104. tee <<< "Selected $run_count / $(($run_count + $skip_count)) tests to run" "$GITHUB_STEP_SUMMARY"
  105. else
  106. tee <<< "ATS failed. Can't get list of tests to run. Fallback to all tests" "$GITHUB_STEP_SUMMARY"
  107. # We need not forget to add the search options in the fallback command, otherwise pytest might run more tests than expected
  108. # These search options match what's defined in codecov.yml:105
  109. echo 'ATS_TESTS_TO_RUN<<EOF' >> $GITHUB_OUTPUT
  110. jq -c @json <<< '[
  111. "--cov-context=test",
  112. "tests/sentry",
  113. "tests/integration",
  114. "--ignore=tests/sentry/eventstream/kafka",
  115. "--ignore=tests/sentry/post_process_forwarder",
  116. "--ignore=tests/sentry/snuba",
  117. "--ignore=tests/sentry/search/events",
  118. "--ignore=tests/sentry/ingest/ingest_consumer/test_ingest_consumer_kafka.py",
  119. "--ignore=tests/sentry/region_to_control/test_region_to_control_kafka.py"
  120. ]' >> $GITHUB_OUTPUT
  121. echo 'EOF' >> $GITHUB_OUTPUT
  122. echo ATS_TESTS_TO_SKIP="'[]'" >> "$GITHUB_OUTPUT"
  123. echo "::error ATS failed"
  124. exit 1
  125. fi
  126. env:
  127. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  128. CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
  129. # The actual running of tests would come here, after the labels are available
  130. # Something like pytest <options> $ATS_TESTS_TO_RUN
  131. debug:
  132. runs-on: ubuntu-latest
  133. needs: coverage-ats
  134. if: ${{ always() }}
  135. steps:
  136. - name: Debug ATS_TESTS_TO_RUN
  137. run: |
  138. : ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }}
  139. length_of_tests=$(jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }} 'length')
  140. # The 1st value doesn't count, it's '--cov-context=test' (hence -gt 1)
  141. if [ $length_of_tests -gt 1 ]; then
  142. echo "Running $length_of_tests tests"
  143. # --raw-output0 doesn't work.
  144. jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }} 'join("\u0000")' --raw-output | tr -d '\n' | xargs -r0 echo
  145. else
  146. echo "No tests to run"
  147. fi
  148. - name: Debug ATS_TESTS_TO_SKIP
  149. run: |
  150. : ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }}
  151. ATS_TESTS_TO_SKIP='${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }}'
  152. length_of_tests=$(jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }} 'length')
  153. # The 1st value doesn't count, it's '--cov-context=test'
  154. if [ $length_of_tests -gt 1 ]; then
  155. echo "Running $length_of_tests tests"
  156. # --raw-output0 doesn't work.
  157. jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }} 'join("\u0000")' --raw-output | tr -d '\n' | xargs -r0 echo
  158. else
  159. echo "No tests to run"
  160. fi