action.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. cache-files-hash:
  27. description: 'A single hash for a set of files. Used for caching.'
  28. required: false
  29. default: ${{ hashFiles('requirements-*.txt', '!requirements-pre-commit.txt') }}
  30. python-version:
  31. description: 'python version to install'
  32. required: false
  33. pip-cache-version:
  34. description: 'pip cache version in order to bust cache'
  35. required: false
  36. default: '1630355466247'
  37. outputs:
  38. yarn-cache-dir:
  39. description: 'Path to yarn cache'
  40. value: ${{ steps.config.outputs.yarn-cache-dir }}
  41. pip-cache-dir:
  42. description: 'Path to pip cache'
  43. value: ${{ steps.setup-python.outputs.pip-cache-dir }}
  44. pip-version:
  45. description: 'pip version'
  46. value: ${{ steps.setup-python.outputs.pip-version }}
  47. python-version:
  48. description: 'python version'
  49. value: ${{ steps.setup-python.outputs.python-version }}
  50. acceptance-dir:
  51. description: 'Path to acceptance visual snapshot artifacts'
  52. value: ${{ steps.config.outputs.acceptance-dir }}
  53. matrix-instance-number:
  54. description: 'The matrix instance number (starting at 1)'
  55. value: ${{ steps.config.outputs.matrix-instance-number }}
  56. matrix-instance-total:
  57. description: 'Reexport of MATRIX_INSTANCE_TOTAL.'
  58. value: ${{ steps.config.outputs.matrix-instance-total }}
  59. runs:
  60. using: 'composite'
  61. steps:
  62. - name: Setup default environment variables
  63. shell: bash
  64. env:
  65. NEED_KAFKA: ${{ inputs.kafka }}
  66. MATRIX_INSTANCE: ${{ matrix.instance }}
  67. # XXX: We should be using something like len(strategy.matrix.instance) (not possible atm)
  68. # If you have other things like python-version: [foo, bar, baz] then the sharding logic
  69. # isn't right because job-total will be 3x larger and you'd never run 2/3 of the tests.
  70. # MATRIX_INSTANCE_TOTAL: ${{ strategy.job-total }}
  71. run: |
  72. # Only set `MIGRATIONS_TEST_MIGRATE` if it is not already set (or if it's an empty string)
  73. if [ -z $MIGRATIONS_TEST_MIGRATE ]; then
  74. echo "MIGRATIONS_TEST_MIGRATE=0" >> $GITHUB_ENV
  75. fi
  76. echo "PIP_DISABLE_PIP_VERSION_CHECK=on" >> $GITHUB_ENV
  77. echo "SENTRY_LIGHT_BUILD=1" >> $GITHUB_ENV
  78. echo "SENTRY_SKIP_BACKEND_VALIDATION=1" >> $GITHUB_ENV
  79. ### node configuration ###
  80. echo "NODE_ENV=development" >> $GITHUB_ENV
  81. echo "NODE_OPTIONS=--max-old-space-size=4096" >> $GITHUB_ENV
  82. ### pytest-sentry configuration ###
  83. echo "PYTEST_SENTRY_DSN=https://6fd5cfea2d4d46b182ad214ac7810508@sentry.io/2423079" >> $GITHUB_ENV
  84. echo "PYTEST_ADDOPTS=--reruns 5" >> $GITHUB_ENV
  85. # this handles pytest test sharding
  86. if [ "$MATRIX_INSTANCE" ]; then
  87. if ! [ "$MATRIX_INSTANCE_TOTAL" ]; then
  88. echo "MATRIX_INSTANCE_TOTAL is required."
  89. exit 1
  90. fi
  91. echo "TEST_GROUP=$MATRIX_INSTANCE" >> $GITHUB_ENV
  92. echo "TOTAL_TEST_GROUPS=$MATRIX_INSTANCE_TOTAL" >> $GITHUB_ENV
  93. fi
  94. # This records failures on master to sentry in order to detect flakey tests, as it's
  95. # expected that people have failing tests on their PRs
  96. [ "$GITHUB_REF" = "refs/heads/master" ] && echo "PYTEST_SENTRY_ALWAYS_REPORT=1" >> $GITHUB_ENV || true
  97. ### services configuration ###
  98. echo "BIGTABLE_EMULATOR_HOST=localhost:8086" >> $GITHUB_ENV
  99. # Note: some backend tests (e.g. tests/sentry/eventstream/kafka/test_consumer.py) will behave
  100. # differently if these are set.
  101. if [ "$NEED_KAFKA" = "true" ]; then
  102. echo "SENTRY_KAFKA_HOSTS=127.0.0.1:9092" >> $GITHUB_ENV
  103. echo "SENTRY_ZOOKEEPER_HOSTS=127.0.0.1:2181" >> $GITHUB_ENV
  104. fi
  105. - name: Setup python
  106. id: setup-python
  107. uses: ./.github/actions/setup-python
  108. with:
  109. python-version: ${{ inputs.python-version }}
  110. cache-files-hash: ${{ inputs.cache-files-hash }}
  111. pip-cache-version: ${{ inputs.pip-cache-version }}
  112. workdir: ${{ inputs.workdir }}
  113. - name: Install system dependencies
  114. shell: bash
  115. run: |
  116. sudo apt-get update
  117. sudo apt-get install -y --no-install-recommends \
  118. libxmlsec1-dev \
  119. libmaxminddb-dev
  120. - name: Set up outputs
  121. id: config
  122. env:
  123. MATRIX_INSTANCE: ${{ matrix.instance }}
  124. shell: bash
  125. run: |
  126. echo "::set-output name=yarn-cache-dir::$(yarn cache dir)"
  127. echo "::set-output name=matrix-instance-number::$(($MATRIX_INSTANCE+1))"
  128. echo "::set-output name=matrix-instance-total::$(($MATRIX_INSTANCE_TOTAL))"
  129. echo "::set-output name=acceptance-dir::.artifacts/visual-snapshots/acceptance"
  130. - name: Install python dependencies
  131. shell: bash
  132. env:
  133. # This is necessary when other repositories (e.g. relay) want to take advantage of this workflow
  134. # without needing to fork it. The path needed is the one where setup.py is located
  135. WORKDIR: ${{ inputs.workdir }}
  136. run: |
  137. cd "$WORKDIR"
  138. python setup.py install_egg_info
  139. pip install wheel # GitHub Actions does not have `wheel` installed by default
  140. pip install -U -e ".[dev]"
  141. cd -
  142. - name: Start devservices
  143. shell: bash
  144. env:
  145. NEED_KAFKA: ${{ inputs.kafka }}
  146. NEED_SNUBA: ${{ inputs.snuba }}
  147. NEED_CLICKHOUSE: ${{ inputs.clickhouse }}
  148. NEED_CHARTCUTERIE: ${{ inputs.chartcuterie }}
  149. WORKDIR: ${{ inputs.workdir }}
  150. run: |
  151. sentry init
  152. # redis, postgres are needed for almost every code path.
  153. sentry devservices up redis postgres
  154. if [ "$BIGTABLE_EMULATOR_HOST" ]; then
  155. sentry devservices up --skip-only-if bigtable
  156. fi
  157. # TODO: Use devservices kafka. See https://github.com/getsentry/sentry/pull/20986#issuecomment-704510570
  158. if [ "$NEED_KAFKA" = "true" ]; then
  159. # This is *not* the production version. Unclear reason as to why this was chosen
  160. # https://github.com/getsentry/ops/blob/c823e62f930ecc6c97bb08898c71e49edc7232f6/cookbooks/getsentry/attributes/default.rb#L631
  161. docker run \
  162. --name sentry_zookeeper \
  163. -d --network host \
  164. -e ZOOKEEPER_CLIENT_PORT=2181 \
  165. confluentinc/cp-zookeeper:4.1.0
  166. # This is the production version; do not change w/o changing it there as well
  167. # https://github.com/getsentry/ops/blob/c823e62f930ecc6c97bb08898c71e49edc7232f6/cookbooks/getsentry/attributes/default.rb#L643
  168. docker run \
  169. --name sentry_kafka \
  170. -d --network host \
  171. -e KAFKA_ZOOKEEPER_CONNECT=127.0.0.1:2181 \
  172. -e KAFKA_LISTENERS=INTERNAL://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092 \
  173. -e KAFKA_ADVERTISED_LISTENERS=INTERNAL://127.0.0.1:9093,EXTERNAL://127.0.0.1:9092 \
  174. -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT \
  175. -e KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL \
  176. -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
  177. confluentinc/cp-kafka:5.1.2
  178. fi
  179. if [ "$NEED_SNUBA" = "true" ]; then
  180. sentry devservices up clickhouse snuba
  181. fi
  182. if [ "$NEED_CLICKHOUSE" = "true" ]; then
  183. sentry devservices up clickhouse
  184. fi
  185. if [ "$NEED_CHARTCUTERIE" = "true" ]; then
  186. sentry devservices up --skip-only-if chartcuterie
  187. fi
  188. docker ps -a
  189. ./$WORKDIR/scripts/devservices-healthcheck.sh