action.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. python-version:
  31. description: 'python version to install'
  32. required: false
  33. default: '3.8.16'
  34. pg-version:
  35. description: 'PostgreSQL version to use'
  36. default: '14'
  37. required: false
  38. outputs:
  39. yarn-cache-dir:
  40. description: 'Path to yarn cache'
  41. value: ${{ steps.config.outputs.yarn-cache-dir }}
  42. matrix-instance-number:
  43. description: 'The matrix instance number (starting at 1)'
  44. value: ${{ steps.config.outputs.matrix-instance-number }}
  45. matrix-instance-total:
  46. description: 'Reexport of MATRIX_INSTANCE_TOTAL.'
  47. value: ${{ steps.config.outputs.matrix-instance-total }}
  48. runs:
  49. using: 'composite'
  50. steps:
  51. - name: Setup default environment variables
  52. # the default for "bash" is:
  53. # bash --noprofile --norc -eo pipefail {0}
  54. shell: bash --noprofile --norc -eo pipefail -ux {0}
  55. env:
  56. MATRIX_INSTANCE: ${{ matrix.instance }}
  57. # XXX: We should be using something like len(strategy.matrix.instance) (not possible atm)
  58. # If you have other things like python-version: [foo, bar, baz] then the sharding logic
  59. # isn't right because job-total will be 3x larger and you'd never run 2/3 of the tests.
  60. # MATRIX_INSTANCE_TOTAL: ${{ strategy.job-total }}
  61. run: |
  62. echo "PIP_DISABLE_PIP_VERSION_CHECK=on" >> $GITHUB_ENV
  63. echo "PIP_INDEX_URL=https://pypi.devinfra.sentry.io/simple" >> $GITHUB_ENV
  64. echo "SENTRY_SKIP_BACKEND_VALIDATION=1" >> $GITHUB_ENV
  65. ### node configuration ###
  66. echo "NODE_ENV=development" >> $GITHUB_ENV
  67. ### pytest configuration ###
  68. echo "PY_COLORS=1" >> "$GITHUB_ENV"
  69. echo "PYTEST_ADDOPTS=--reruns=5 --durations=10 --fail-slow=60s" >> $GITHUB_ENV
  70. ### pytest-sentry configuration ###
  71. if [ "$GITHUB_REPOSITORY" = "getsentry/sentry" ]; then
  72. echo "PYTEST_SENTRY_DSN=https://6fd5cfea2d4d46b182ad214ac7810508@sentry.io/2423079" >> $GITHUB_ENV
  73. echo "PYTEST_SENTRY_TRACES_SAMPLE_RATE=0" >> $GITHUB_ENV
  74. # This records failures on master to sentry in order to detect flakey tests, as it's
  75. # expected that people have failing tests on their PRs
  76. if [ "$GITHUB_REF" = "refs/heads/master" ]; then
  77. echo "PYTEST_SENTRY_ALWAYS_REPORT=1" >> $GITHUB_ENV
  78. fi
  79. fi
  80. # Configure a different release version, otherwise it defaults to the
  81. # commit sha which will conflict with our actual prod releases. This is a
  82. # confusing experience because it looks like these are "empty" releases
  83. # because no commits are attached and associates the release with our
  84. # javascript + sentry projects.
  85. echo "SENTRY_RELEASE=ci@$GITHUB_SHA" >> $GITHUB_ENV
  86. # this handles pytest test sharding
  87. if [ "$MATRIX_INSTANCE" ]; then
  88. if ! [ "${MATRIX_INSTANCE_TOTAL:-}" ]; then
  89. echo "MATRIX_INSTANCE_TOTAL is required."
  90. exit 1
  91. fi
  92. echo "TEST_GROUP=$MATRIX_INSTANCE" >> $GITHUB_ENV
  93. echo "TOTAL_TEST_GROUPS=$MATRIX_INSTANCE_TOTAL" >> $GITHUB_ENV
  94. fi
  95. - uses: getsentry/action-setup-venv@9e3bbae3836b1b6f129955bf55a19e1d99a61c67 # v1.0.5
  96. with:
  97. python-version: ${{ inputs.python-version }}
  98. cache-dependency-path: ${{ inputs.workdir }}/requirements-dev-frozen.txt
  99. install-cmd: pip install -r ${{ inputs.workdir }}/requirements-dev-frozen.txt
  100. - name: Set up outputs
  101. id: config
  102. env:
  103. MATRIX_INSTANCE: ${{ matrix.instance }}
  104. shell: bash --noprofile --norc -eo pipefail -ux {0}
  105. run: |
  106. echo "yarn-cache-dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
  107. echo "matrix-instance-number=$(($MATRIX_INSTANCE+1))" >> "$GITHUB_OUTPUT"
  108. echo "matrix-instance-total=$((${MATRIX_INSTANCE_TOTAL:-}))" >> "$GITHUB_OUTPUT"
  109. - name: Install python dependencies
  110. shell: bash --noprofile --norc -eo pipefail -ux {0}
  111. env:
  112. # This is necessary when other repositories (e.g. relay) want to take advantage of this workflow
  113. # without needing to fork it. The path needed is the one where setup.py is located
  114. WORKDIR: ${{ inputs.workdir }}
  115. run: |
  116. cd "$WORKDIR"
  117. # We need to install editable otherwise things like check migration will fail.
  118. SENTRY_LIGHT_BUILD=1 pip install --no-deps -e .
  119. - name: Start devservices
  120. shell: bash --noprofile --norc -eo pipefail -ux {0}
  121. env:
  122. NEED_KAFKA: ${{ inputs.kafka }}
  123. NEED_SNUBA: ${{ inputs.snuba }}
  124. NEED_CLICKHOUSE: ${{ inputs.clickhouse }}
  125. NEED_BIGTABLE: ${{ inputs.bigtable }}
  126. NEED_CHARTCUTERIE: ${{ inputs.chartcuterie }}
  127. WORKDIR: ${{ inputs.workdir }}
  128. PG_VERSION: ${{ inputs.pg-version }}
  129. ENABLE_AUTORUN_MIGRATION_SEARCH_ISSUES: '1'
  130. run: |
  131. sentry init
  132. # redis, postgres are needed for almost every code path.
  133. services='redis postgres'
  134. if [ "$NEED_CLICKHOUSE" = "true" ] || [ "$NEED_SNUBA" = "true" ]; then
  135. services="${services} clickhouse"
  136. fi
  137. if [ "$NEED_SNUBA" = "true" ]; then
  138. services="${services} snuba"
  139. fi
  140. if [ "$NEED_BIGTABLE" = "true" ]; then
  141. echo "BIGTABLE_EMULATOR_HOST=127.0.0.1:8086" >> $GITHUB_ENV
  142. services="${services} bigtable"
  143. fi
  144. if [ "$NEED_CHARTCUTERIE" = "true" ]; then
  145. services="${services} chartcuterie"
  146. fi
  147. sentry devservices up $services &
  148. # TODO: Use devservices kafka. See https://github.com/getsentry/sentry/pull/20986#issuecomment-704510570
  149. if [ "$NEED_KAFKA" = "true" ]; then
  150. # This is *not* the production version. Unclear reason as to why this was chosen
  151. # https://github.com/getsentry/ops/blob/c823e62f930ecc6c97bb08898c71e49edc7232f6/cookbooks/getsentry/attributes/default.rb#L631
  152. docker run \
  153. --name sentry_zookeeper \
  154. -d --network host \
  155. -e ZOOKEEPER_CLIENT_PORT=2181 \
  156. confluentinc/cp-zookeeper:4.1.0 \
  157. &
  158. # This is the production version; do not change w/o changing it there as well
  159. # https://github.com/getsentry/ops/blob/c823e62f930ecc6c97bb08898c71e49edc7232f6/cookbooks/getsentry/attributes/default.rb#L643
  160. docker run \
  161. --name sentry_kafka \
  162. -d --network host \
  163. -e KAFKA_ZOOKEEPER_CONNECT=127.0.0.1:2181 \
  164. -e KAFKA_LISTENERS=INTERNAL://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092 \
  165. -e KAFKA_ADVERTISED_LISTENERS=INTERNAL://127.0.0.1:9093,EXTERNAL://127.0.0.1:9092 \
  166. -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT \
  167. -e KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL \
  168. -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
  169. confluentinc/cp-kafka:5.1.2 \
  170. &
  171. fi
  172. wait
  173. docker ps -a
  174. # This is necessary when other repositories (e.g. relay) want to take advantage of this workflow
  175. # without needing to fork it. The path needed is the one where tools are located
  176. cd "$WORKDIR"
  177. python3 -u -S -m tools.devservices_healthcheck
  178. cd -