Makefile 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. PIP := python -m pip --disable-pip-version-check
  2. WEBPACK := yarn build-acceptance
  3. UNAME := $(shell command -v uname 2> /dev/null)
  4. ifdef UNAME
  5. ifeq ($(shell uname), Darwin)
  6. BIG_SUR := $(shell sw_vers -productVersion | egrep "11\.")
  7. endif
  8. endif
  9. bootstrap: develop init-config run-dependent-services create-db apply-migrations build-platform-assets
  10. develop: ensure-pinned-pip setup-git install-js-dev install-py-dev
  11. clean:
  12. @echo "--> Cleaning static cache"
  13. rm -rf dist/* static/dist/*
  14. @echo "--> Cleaning integration docs cache"
  15. rm -rf src/sentry/integration-docs
  16. @echo "--> Cleaning pyc files"
  17. find . -name "*.pyc" -delete
  18. @echo "--> Cleaning python build artifacts"
  19. rm -rf build/ dist/ src/sentry/assets.json
  20. @echo ""
  21. init-config: ensure-venv
  22. sentry init --dev
  23. run-dependent-services: ensure-venv
  24. sentry devservices up
  25. DROPDB := $(shell command -v dropdb 2> /dev/null)
  26. ifndef DROPDB
  27. DROPDB = docker exec sentry_postgres dropdb
  28. endif
  29. CREATEDB := $(shell command -v createdb 2> /dev/null)
  30. ifndef CREATEDB
  31. CREATEDB = docker exec sentry_postgres createdb
  32. endif
  33. drop-db:
  34. @echo "--> Dropping existing 'sentry' database"
  35. $(DROPDB) -h 127.0.0.1 -U postgres sentry || true
  36. create-db:
  37. @echo "--> Creating 'sentry' database"
  38. $(CREATEDB) -h 127.0.0.1 -U postgres -E utf-8 sentry || true
  39. apply-migrations: ensure-venv
  40. @echo "--> Applying migrations"
  41. sentry upgrade
  42. reset-db: drop-db create-db apply-migrations
  43. setup-pyenv:
  44. ifdef BIG_SUR
  45. # NOTE: Once we have a new release of pyenv and once a newer Python version we can remove these
  46. # https://github.com/pyenv/pyenv/pull/1711
  47. # cat is used since pyenv would finish to soon when the Python version is already installed
  48. curl -sSL https://github.com/python/cpython/commit/8ea6353.patch | cat | \
  49. LDFLAGS="-L$(shell xcrun --show-sdk-path)/usr/lib ${LDFLAGS}" \
  50. pyenv install --skip-existing --patch 3.6.10
  51. else
  52. @cat .python-version | xargs -n1 pyenv install --skip-existing
  53. endif
  54. ensure-venv:
  55. @./scripts/ensure-venv.sh
  56. ensure-pinned-pip: ensure-venv
  57. $(PIP) install --no-cache-dir --upgrade "pip>=20.0.2"
  58. setup-git-config:
  59. @git config --local branch.autosetuprebase always
  60. @git config --local core.ignorecase false
  61. @git config --local blame.ignoreRevsFile .git-blame-ignore-revs
  62. setup-git: ensure-venv setup-git-config
  63. @echo "--> Installing git hooks"
  64. mkdir -p .git/hooks && cd .git/hooks && ln -sf ../../config/hooks/* ./
  65. @python3 -c '' || (echo 'Please run `make setup-pyenv` to install the required Python 3 version.'; exit 1)
  66. $(PIP) install -r requirements-pre-commit.txt
  67. @pre-commit install --install-hooks
  68. @echo ""
  69. node-version-check:
  70. @# Checks to see if node's version matches the one specified in package.json for Volta.
  71. @node -pe "process.exit(Number(!(process.version == 'v' + require('./package.json').volta.node )))" || \
  72. (echo 'Unexpected node version. Recommended to use https://github.com/volta-cli/volta'; exit 1)
  73. install-js-dev: node-version-check
  74. @echo "--> Installing Yarn packages (for development)"
  75. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  76. NODE_ENV=development yarn install --frozen-lockfile
  77. # A common problem is with node packages not existing in `node_modules` even though `yarn install`
  78. # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
  79. # account the state of the current filesystem (it only checks .yarn-integrity).
  80. # Add an additional check against `node_modules`
  81. yarn check --verify-tree || yarn install --check-files
  82. install-py-dev: ensure-pinned-pip
  83. @echo "--> Installing Sentry (for development)"
  84. ifdef BIG_SUR
  85. # grpcio 1.35.0 is very painful to compile on Big Sur, and is not really surfaced in testing anyways.
  86. # So we set SYSTEM_VERSION_COMPAT=1 to get pip to download grpcio wheels for older MacOS.
  87. SYSTEM_VERSION_COMPAT=1 $(PIP) install 'grpcio==1.35.0'
  88. endif
  89. # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
  90. # Webpacked assets are only necessary for devserver (which does it lazily anyways)
  91. # and acceptance tests, which webpack automatically if run.
  92. SENTRY_LIGHT_BUILD=1 $(PIP) install -e ".[dev]"
  93. build-js-po: node-version-check
  94. mkdir -p build
  95. SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
  96. build: locale
  97. merge-locale-catalogs: build-js-po
  98. $(PIP) install Babel
  99. cd src/sentry && sentry django makemessages -i static -l en
  100. ./bin/merge-catalogs en
  101. compile-locale:
  102. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  103. cd src/sentry && sentry django compilemessages
  104. locale: merge-locale-catalogs compile-locale
  105. sync-transifex: merge-locale-catalogs
  106. $(PIP) install transifex-client
  107. tx push -s
  108. tx pull -a
  109. update-transifex: sync-transifex compile-locale
  110. build-platform-assets:
  111. @echo "--> Building platform assets"
  112. @echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
  113. fetch-release-registry:
  114. @echo "--> Fetching release registry"
  115. @echo "from sentry.utils.distutils import sync_registry; sync_registry()" | sentry exec
  116. run-acceptance:
  117. @echo "--> Running acceptance tests"
  118. py.test tests/acceptance --cov . --cov-report="xml:.artifacts/acceptance.coverage.xml" --junit-xml=".artifacts/acceptance.junit.xml" --html=".artifacts/acceptance.pytest.html" --self-contained-html
  119. @echo ""
  120. test-cli:
  121. @echo "--> Testing CLI"
  122. rm -rf test_cli
  123. mkdir test_cli
  124. cd test_cli && sentry init test_conf
  125. cd test_cli && sentry --config=test_conf help
  126. cd test_cli && sentry --config=test_conf upgrade --traceback --noinput
  127. cd test_cli && sentry --config=test_conf export
  128. rm -r test_cli
  129. @echo ""
  130. test-js-build: node-version-check
  131. @echo "--> Running type check"
  132. @yarn run tsc -p config/tsconfig.build.json
  133. @echo "--> Building static assets"
  134. @NODE_ENV=production yarn webpack-profile > .artifacts/webpack-stats.json
  135. test-js: node-version-check
  136. @echo "--> Running JavaScript tests"
  137. @yarn run test
  138. @echo ""
  139. test-js-ci: node-version-check
  140. @echo "--> Running CI JavaScript tests"
  141. @yarn run test-ci
  142. @echo ""
  143. test-python:
  144. @echo "--> Running Python tests"
  145. # This gets called by getsentry
  146. py.test tests/integration tests/sentry
  147. test-python-ci:
  148. make build-platform-assets
  149. @echo "--> Running CI Python tests"
  150. py.test tests/integration tests/sentry --cov . --cov-report="xml:.artifacts/python.coverage.xml" --junit-xml=".artifacts/python.junit.xml" || exit 1
  151. @echo ""
  152. test-snuba:
  153. @echo "--> Running snuba tests"
  154. py.test tests/snuba tests/sentry/eventstream/kafka tests/sentry/snuba/test_discover.py -vv --cov . --cov-report="xml:.artifacts/snuba.coverage.xml" --junit-xml=".artifacts/snuba.junit.xml"
  155. @echo ""
  156. test-symbolicator:
  157. @echo "--> Running symbolicator tests"
  158. py.test tests/symbolicator -vv --cov . --cov-report="xml:.artifacts/symbolicator.coverage.xml" --junit-xml=".artifacts/symbolicator.junit.xml"
  159. @echo ""
  160. test-acceptance: node-version-check
  161. @echo "--> Building static assets"
  162. @$(WEBPACK)
  163. make run-acceptance
  164. test-plugins:
  165. @echo "--> Running plugin tests"
  166. py.test tests/sentry_plugins -vv --cov . --cov-report="xml:.artifacts/plugins.coverage.xml" --junit-xml=".artifacts/plugins.junit.xml" || exit 1
  167. @echo ""
  168. test-relay-integration:
  169. @echo "--> Running Relay integration tests"
  170. pytest tests/relay_integration -vv
  171. @echo ""
  172. test-api-docs:
  173. @echo "--> Generating testing api doc schema"
  174. yarn run build-derefed-docs
  175. @echo "--> Validating endpoints' examples against schemas"
  176. yarn run validate-api-examples
  177. pytest tests/apidocs/endpoints
  178. @echo ""
  179. review-python-snapshots:
  180. @cargo insta --version &> /dev/null || cargo install cargo-insta
  181. @cargo insta review --workspace-root `pwd` -e pysnap
  182. accept-python-snapshots:
  183. @cargo insta --version &> /dev/null || cargo install cargo-insta
  184. @cargo insta accept --workspace-root `pwd` -e pysnap
  185. reject-python-snapshots:
  186. @cargo insta --version &> /dev/null || cargo install cargo-insta
  187. @cargo insta reject --workspace-root `pwd` -e pysnap
  188. lint-js:
  189. @echo "--> Linting javascript"
  190. bin/lint --js --parseable
  191. @echo ""
  192. .PHONY: develop build reset-db clean setup-git node-version-check install-js-dev install-py-dev build-js-po locale compile-locale merge-locale-catalogs sync-transifex update-transifex build-platform-assets test-cli test-js test-js-build test-styleguide test-python test-snuba test-symbolicator test-acceptance lint-js