action.yml 7.9 KB

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