Makefile 8.3 KB

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