action.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # NOTE: Do not rely on `make` commands here as this action is used across different repos
  2. # where the Makefile will not be available
  3. name: 'Sentry Setup'
  4. description: 'Sets up a Sentry test environment'
  5. inputs:
  6. workdir:
  7. description: 'Directory where the sentry source is located'
  8. required: false
  9. default: '.'
  10. snuba:
  11. description: 'Is snuba required?'
  12. required: false
  13. default: 'false'
  14. clickhouse:
  15. description: 'Is clickhouse required?'
  16. required: false
  17. default: 'false'
  18. kafka:
  19. description: 'Is kafka required?'
  20. required: false
  21. default: 'false'
  22. chartcuterie:
  23. description: 'Is chartcuterie required?'
  24. required: false
  25. default: 'false'
  26. bigtable:
  27. description: 'Is bigtable required?'
  28. required: false
  29. default: 'false'
  30. symbolicator:
  31. description: 'Is symbolicator required?'
  32. required: false
  33. default: 'false'
  34. python-version:
  35. description: 'python version to install'
  36. required: false
  37. default: '3.8.16'
  38. pg-version:
  39. description: 'PostgreSQL version to use'
  40. default: '14'
  41. required: false
  42. outputs:
  43. yarn-cache-dir:
  44. description: 'Path to yarn cache'
  45. value: ${{ steps.config.outputs.yarn-cache-dir }}
  46. matrix-instance-number:
  47. description: 'The matrix instance number (starting at 1)'
  48. value: ${{ steps.config.outputs.matrix-instance-number }}
  49. matrix-instance-total:
  50. description: 'Reexport of MATRIX_INSTANCE_TOTAL.'
  51. value: ${{ steps.config.outputs.matrix-instance-total }}
  52. runs:
  53. using: 'composite'
  54. steps:
  55. - name: Setup default environment variables
  56. # the default for "bash" is:
  57. # bash --noprofile --norc -eo pipefail {0}
  58. shell: bash --noprofile --norc -eo pipefail -ux {0}
  59. env:
  60. MATRIX_INSTANCE: ${{ matrix.instance }}
  61. # XXX: We should be using something like len(strategy.matrix.instance) (not possible atm)
  62. # If you have other things like python-version: [foo, bar, baz] then the sharding logic
  63. # isn't right because job-total will be 3x larger and you'd never run 2/3 of the tests.
  64. # MATRIX_INSTANCE_TOTAL: ${{ strategy.job-total }}
  65. run: |
  66. echo "PIP_DISABLE_PIP_VERSION_CHECK=on" >> $GITHUB_ENV
  67. echo "PIP_INDEX_URL=https://pypi.devinfra.sentry.io/simple" >> $GITHUB_ENV
  68. echo "SENTRY_SKIP_BACKEND_VALIDATION=1" >> $GITHUB_ENV
  69. ### node configuration ###
  70. echo "NODE_ENV=development" >> $GITHUB_ENV
  71. ### pytest configuration ###
  72. echo "PY_COLORS=1" >> "$GITHUB_ENV"
  73. echo "PYTEST_ADDOPTS=--reruns=5 --durations=10 --fail-slow=60s" >> $GITHUB_ENV
  74. ### pytest-sentry configuration ###
  75. if [ "$GITHUB_REPOSITORY" = "getsentry/sentry" ]; then
  76. echo "PYTEST_SENTRY_DSN=https://6fd5cfea2d4d46b182ad214ac7810508@sentry.io/2423079" >> $GITHUB_ENV
  77. echo "PYTEST_SENTRY_TRACES_SAMPLE_RATE=0" >> $GITHUB_ENV
  78. # This records failures on master to sentry in order to detect flakey tests, as it's
  79. # expected that people have failing tests on their PRs
  80. if [ "$GITHUB_REF" = "refs/heads/master" ]; then
  81. echo "PYTEST_SENTRY_ALWAYS_REPORT=1" >> $GITHUB_ENV
  82. fi
  83. fi
  84. # Configure a different release version, otherwise it defaults to the
  85. # commit sha which will conflict with our actual prod releases. This is a
  86. # confusing experience because it looks like these are "empty" releases
  87. # because no commits are attached and associates the release with our
  88. # javascript + sentry projects.
  89. echo "SENTRY_RELEASE=ci@$GITHUB_SHA" >> $GITHUB_ENV
  90. # this handles pytest test sharding
  91. if [ "$MATRIX_INSTANCE" ]; then
  92. if ! [ "${MATRIX_INSTANCE_TOTAL:-}" ]; then
  93. echo "MATRIX_INSTANCE_TOTAL is required."
  94. exit 1
  95. fi
  96. echo "TEST_GROUP=$MATRIX_INSTANCE" >> $GITHUB_ENV
  97. echo "TOTAL_TEST_GROUPS=$MATRIX_INSTANCE_TOTAL" >> $GITHUB_ENV
  98. fi
  99. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  100. with:
  101. python-version: ${{ inputs.python-version }}
  102. cache-dependency-path: ${{ inputs.workdir }}/requirements-dev-frozen.txt
  103. install-cmd: pip install -r ${{ inputs.workdir }}/requirements-dev-frozen.txt
  104. - name: Set up outputs
  105. id: config
  106. env:
  107. MATRIX_INSTANCE: ${{ matrix.instance }}
  108. shell: bash --noprofile --norc -eo pipefail -ux {0}
  109. run: |
  110. echo "yarn-cache-dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
  111. echo "matrix-instance-number=$(($MATRIX_INSTANCE+1))" >> "$GITHUB_OUTPUT"
  112. echo "matrix-instance-total=$((${MATRIX_INSTANCE_TOTAL:-}))" >> "$GITHUB_OUTPUT"
  113. - name: Install python dependencies
  114. shell: bash --noprofile --norc -eo pipefail -ux {0}
  115. env:
  116. # This is necessary when other repositories (e.g. relay) want to take advantage of this workflow
  117. # without needing to fork it. The path needed is the one where setup.py is located
  118. WORKDIR: ${{ inputs.workdir }}
  119. run: |
  120. cd "$WORKDIR"
  121. # We need to install editable otherwise things like check migration will fail.
  122. SENTRY_LIGHT_BUILD=1 pip install --no-deps -e .
  123. - name: Start devservices
  124. shell: bash --noprofile --norc -eo pipefail -ux {0}
  125. env:
  126. NEED_KAFKA: ${{ inputs.kafka }}
  127. NEED_SNUBA: ${{ inputs.snuba }}
  128. NEED_CLICKHOUSE: ${{ inputs.clickhouse }}
  129. NEED_BIGTABLE: ${{ inputs.bigtable }}
  130. NEED_CHARTCUTERIE: ${{ inputs.chartcuterie }}
  131. NEED_SYMBOLICATOR: ${{ inputs.symbolicator }}
  132. WORKDIR: ${{ inputs.workdir }}
  133. PG_VERSION: ${{ inputs.pg-version }}
  134. ENABLE_AUTORUN_MIGRATION_SEARCH_ISSUES: '1'
  135. run: |
  136. sentry init
  137. # redis, postgres are needed for almost every code path.
  138. services=(redis postgres)
  139. if [ "$NEED_CLICKHOUSE" = "true" ] || [ "$NEED_SNUBA" = "true" ]; then
  140. services+=(clickhouse)
  141. fi
  142. if [ "$NEED_SNUBA" = "true" ]; then
  143. services+=(snuba)
  144. fi
  145. if [ "$NEED_BIGTABLE" = "true" ]; then
  146. echo "BIGTABLE_EMULATOR_HOST=127.0.0.1:8086" >> $GITHUB_ENV
  147. services+=(bigtable)
  148. fi
  149. if [ "$NEED_CHARTCUTERIE" = "true" ]; then
  150. services+=(chartcuterie)
  151. fi
  152. if [ "$NEED_SYMBOLICATOR" = "true" ]; then
  153. services+=(symbolicator)
  154. fi
  155. if [ "$NEED_KAFKA" = "true" ]; then
  156. services+=(kafka)
  157. fi
  158. sentry devservices up "${services[@]}"
  159. # have tests listen on the docker gateway ip so loopback can occur
  160. echo "DJANGO_LIVE_TEST_SERVER_ADDRESS=$(docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}')" >> "$GITHUB_ENV"
  161. docker ps -a
  162. # This is necessary when other repositories (e.g. relay) want to take advantage of this workflow
  163. # without needing to fork it. The path needed is the one where tools are located
  164. cd "$WORKDIR"