Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. @# pre-commit loosely pins virtualenv, which has caused problems in the past.
  67. $(PIP) install "pre-commit==1.18.2" "virtualenv==20.0.32"
  68. @pre-commit install --install-hooks
  69. @echo ""
  70. node-version-check:
  71. @# Checks to see if node's version matches the one specified in package.json for Volta.
  72. @node -pe "process.exit(Number(!(process.version == 'v' + require('./package.json').volta.node )))" || \
  73. (echo 'Unexpected node version. Recommended to use https://github.com/volta-cli/volta'; exit 1)
  74. install-js-dev: node-version-check
  75. @echo "--> Installing Yarn packages (for development)"
  76. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  77. NODE_ENV=development yarn install --frozen-lockfile
  78. # A common problem is with node packages not existing in `node_modules` even though `yarn install`
  79. # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
  80. # account the state of the current filesystem (it only checks .yarn-integrity).
  81. # Add an additional check against `node_modules`
  82. yarn check --verify-tree || yarn install --check-files
  83. install-py-dev: ensure-pinned-pip
  84. @echo "--> Installing Sentry (for development)"
  85. # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
  86. # Webpacked assets are only necessary for devserver (which does it lazily anyways)
  87. # and acceptance tests, which webpack automatically if run.
  88. SENTRY_LIGHT_BUILD=1 $(PIP) install -e ".[dev]"
  89. build-js-po: node-version-check
  90. mkdir -p build
  91. SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
  92. build: locale
  93. merge-locale-catalogs: build-js-po
  94. $(PIP) install Babel
  95. cd src/sentry && sentry django makemessages -i static -l en
  96. ./bin/merge-catalogs en
  97. compile-locale:
  98. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  99. cd src/sentry && sentry django compilemessages
  100. locale: merge-locale-catalogs compile-locale
  101. sync-transifex: merge-locale-catalogs
  102. $(PIP) install transifex-client
  103. tx push -s
  104. tx pull -a
  105. update-transifex: sync-transifex compile-locale
  106. build-platform-assets:
  107. @echo "--> Building platform assets"
  108. @echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
  109. fetch-release-registry:
  110. @echo "--> Fetching release registry"
  111. @echo "from sentry.utils.distutils import sync_registry; sync_registry()" | sentry exec
  112. run-acceptance:
  113. @echo "--> Running acceptance tests"
  114. 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
  115. @echo ""
  116. test-cli:
  117. @echo "--> Testing CLI"
  118. rm -rf test_cli
  119. mkdir test_cli
  120. cd test_cli && sentry init test_conf
  121. cd test_cli && sentry --config=test_conf help
  122. cd test_cli && sentry --config=test_conf upgrade --traceback --noinput
  123. cd test_cli && sentry --config=test_conf export
  124. rm -r test_cli
  125. @echo ""
  126. test-js-build: node-version-check
  127. @echo "--> Running type check"
  128. @yarn run tsc -p config/tsconfig.build.json
  129. @echo "--> Building static assets"
  130. @NODE_ENV=production yarn webpack-profile > .artifacts/webpack-stats.json
  131. test-js: node-version-check
  132. @echo "--> Running JavaScript tests"
  133. @yarn run test
  134. @echo ""
  135. test-js-ci: node-version-check
  136. @echo "--> Running CI JavaScript tests"
  137. @yarn run test-ci
  138. @echo ""
  139. test-python:
  140. @echo "--> Running Python tests"
  141. # This gets called by getsentry
  142. py.test tests/integration tests/sentry
  143. test-python-ci:
  144. make build-platform-assets
  145. @echo "--> Running CI Python tests"
  146. py.test tests/integration tests/sentry --cov . --cov-report="xml:.artifacts/python.coverage.xml" --junit-xml=".artifacts/python.junit.xml" || exit 1
  147. @echo ""
  148. test-snuba:
  149. @echo "--> Running snuba tests"
  150. 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"
  151. @echo ""
  152. test-symbolicator:
  153. @echo "--> Running symbolicator tests"
  154. py.test tests/symbolicator -vv --cov . --cov-report="xml:.artifacts/symbolicator.coverage.xml" --junit-xml=".artifacts/symbolicator.junit.xml"
  155. @echo ""
  156. test-acceptance: node-version-check
  157. @echo "--> Building static assets"
  158. @$(WEBPACK)
  159. make run-acceptance
  160. test-plugins:
  161. @echo "--> Running plugin tests"
  162. py.test tests/sentry_plugins -vv --cov . --cov-report="xml:.artifacts/plugins.coverage.xml" --junit-xml=".artifacts/plugins.junit.xml" || exit 1
  163. @echo ""
  164. test-relay-integration:
  165. @echo "--> Running Relay integration tests"
  166. pytest tests/relay_integration -vv
  167. @echo ""
  168. test-api-docs:
  169. @echo "--> Generating testing api doc schema"
  170. yarn run build-derefed-docs
  171. @echo "--> Validating endpoints' examples against schemas"
  172. yarn run validate-api-examples
  173. pytest tests/apidocs/endpoints
  174. @echo ""
  175. review-python-snapshots:
  176. @cargo insta --version &> /dev/null || cargo install cargo-insta
  177. @cargo insta review --workspace-root `pwd` -e pysnap
  178. accept-python-snapshots:
  179. @cargo insta --version &> /dev/null || cargo install cargo-insta
  180. @cargo insta accept --workspace-root `pwd` -e pysnap
  181. reject-python-snapshots:
  182. @cargo insta --version &> /dev/null || cargo install cargo-insta
  183. @cargo insta reject --workspace-root `pwd` -e pysnap
  184. lint-js:
  185. @echo "--> Linting javascript"
  186. bin/lint --js --parseable
  187. @echo ""
  188. .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