Makefile 8.7 KB

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