Makefile 8.4 KB

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