Makefile 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. PIP := python -m pip --disable-pip-version-check
  2. WEBPACK := NODE_ENV=production ./bin/yarn webpack
  3. YARN := ./bin/yarn
  4. bootstrap: develop init-config run-dependent-services create-db apply-migrations
  5. develop: ensure-pinned-pip setup-git install-yarn-pkgs install-sentry-dev
  6. clean:
  7. @echo "--> Cleaning static cache"
  8. rm -rf dist/* static/dist/*
  9. @echo "--> Cleaning integration docs cache"
  10. rm -rf src/sentry/integration-docs
  11. @echo "--> Cleaning pyc files"
  12. find . -name "*.pyc" -delete
  13. @echo "--> Cleaning python build artifacts"
  14. rm -rf build/ dist/ src/sentry/assets.json
  15. @echo ""
  16. init-config: ensure-venv
  17. sentry init --dev
  18. run-dependent-services: ensure-venv
  19. sentry devservices up
  20. DROPDB := $(shell command -v dropdb 2> /dev/null)
  21. ifndef DROPDB
  22. DROPDB = docker exec sentry_postgres dropdb
  23. endif
  24. CREATEDB := $(shell command -v createdb 2> /dev/null)
  25. ifndef CREATEDB
  26. CREATEDB = docker exec sentry_postgres createdb
  27. endif
  28. drop-db:
  29. @echo "--> Dropping existing 'sentry' database"
  30. $(DROPDB) -h 127.0.0.1 -U postgres sentry || true
  31. create-db:
  32. @echo "--> Creating 'sentry' database"
  33. $(CREATEDB) -h 127.0.0.1 -U postgres -E utf-8 sentry || true
  34. apply-migrations: ensure-venv
  35. @echo "--> Applying migrations"
  36. sentry upgrade
  37. reset-db: drop-db create-db apply-migrations
  38. ensure-venv:
  39. @./scripts/ensure-venv.sh
  40. ensure-pinned-pip: ensure-venv
  41. $(PIP) install --no-cache-dir --upgrade "pip>=20.0.2"
  42. setup-git: ensure-venv
  43. @echo "--> Installing git hooks"
  44. git config branch.autosetuprebase always
  45. git config core.ignorecase false
  46. cd .git/hooks && ln -sf ../../config/hooks/* ./
  47. @# XXX(joshuarli): virtualenv >= 20 doesn't work with the version of six we have pinned for sentry.
  48. @# Since pre-commit is installed in the venv, it will install virtualenv in the venv as well.
  49. @# We need to tell pre-commit to install an older virtualenv,
  50. @# And we need to tell virtualenv to install an older six, so that sentry installation
  51. @# won't complain about a newer six being present.
  52. @# So, this six pin here needs to be synced with requirements-base.txt.
  53. $(PIP) install "pre-commit==1.18.2" "virtualenv>=16.7,<20" "six>=1.10.0,<1.11.0"
  54. pre-commit install --install-hooks
  55. @echo ""
  56. node-version-check:
  57. @test "$$(node -v)" = v"$$(cat .nvmrc)" || (echo 'node version does not match .nvmrc. Recommended to use https://github.com/volta-cli/volta'; exit 1)
  58. install-yarn-pkgs: node-version-check
  59. @echo "--> Installing Yarn packages (for development)"
  60. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  61. NODE_ENV=development $(YARN) install --pure-lockfile
  62. # A common problem is with node packages not existing in `node_modules` even though `yarn install`
  63. # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
  64. # account the state of the current filesystem (it only checks .yarn-integrity).
  65. # Add an additional check against `node_modules`
  66. $(YARN) check --verify-tree || $(YARN) install --check-files
  67. install-sentry-dev: ensure-venv
  68. @echo "--> Installing Sentry (for development)"
  69. # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
  70. # Webpacked assets are only necessary for devserver (which does it lazily anyways)
  71. # and acceptance tests, which webpack automatically if run.
  72. SENTRY_LIGHT_BUILD=1 $(PIP) install -e ".[dev]"
  73. build-js-po: node-version-check
  74. mkdir -p build
  75. SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
  76. build: locale
  77. locale: build-js-po
  78. cd src/sentry && sentry django makemessages -i static -l en
  79. ./bin/merge-catalogs en
  80. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  81. cd src/sentry && sentry django compilemessages
  82. update-transifex: build-js-po
  83. $(PIP) install transifex-client
  84. cd src/sentry && sentry django makemessages -i static -l en
  85. ./bin/merge-catalogs en
  86. tx push -s
  87. tx pull -a
  88. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  89. cd src/sentry && sentry django compilemessages
  90. build-platform-assets:
  91. @echo "--> Building platform assets"
  92. @echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
  93. fetch-release-registry:
  94. @echo "--> Fetching release registry"
  95. @echo "from sentry.utils.distutils import sync_registry; sync_registry()" | sentry exec
  96. test-cli:
  97. @echo "--> Testing CLI"
  98. rm -rf test_cli
  99. mkdir test_cli
  100. cd test_cli && sentry init test_conf
  101. cd test_cli && sentry --config=test_conf help
  102. cd test_cli && sentry --config=test_conf upgrade --traceback --noinput
  103. cd test_cli && sentry --config=test_conf export
  104. rm -r test_cli
  105. @echo ""
  106. test-js: node-version-check
  107. @echo "--> Building static assets"
  108. @$(WEBPACK) --profile --json > .artifacts/webpack-stats.json
  109. @echo "--> Running JavaScript tests"
  110. @$(YARN) run test-ci
  111. @echo ""
  112. # builds and creates percy snapshots
  113. test-styleguide:
  114. @echo "--> Building and snapshotting styleguide"
  115. @$(YARN) run snapshot
  116. @echo ""
  117. test-python:
  118. sentry init
  119. make build-platform-assets
  120. @echo "--> Running Python tests"
  121. ifndef TEST_GROUP
  122. py.test tests/integration tests/sentry --cov . --cov-report="xml:.artifacts/python.coverage.xml" --junit-xml=".artifacts/python.junit.xml" || exit 1
  123. else
  124. 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
  125. endif
  126. @echo ""
  127. test-snuba:
  128. @echo "--> Running snuba tests"
  129. py.test tests/snuba tests/sentry/eventstream/kafka -vv --cov . --cov-report="xml:.artifacts/snuba.coverage.xml" --junit-xml=".artifacts/snuba.junit.xml"
  130. @echo ""
  131. test-symbolicator:
  132. @echo "--> Running symbolicator tests"
  133. py.test tests/symbolicator -vv --cov . --cov-report="xml:.artifacts/symbolicator.coverage.xml" --junit-xml=".artifacts/symbolicator.junit.xml"
  134. @echo ""
  135. test-acceptance: node-version-check
  136. sentry init
  137. @echo "--> Building static assets"
  138. @$(WEBPACK) --display errors-only
  139. @echo "--> Running acceptance tests"
  140. ifndef TEST_GROUP
  141. 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
  142. else
  143. 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
  144. endif
  145. @echo ""
  146. test-plugins:
  147. @echo "--> Building static assets"
  148. @$(WEBPACK) --display errors-only
  149. @echo "--> Running plugin tests"
  150. py.test tests/sentry_plugins -vv --cov . --cov-report="xml:.artifacts/plugins.coverage.xml" --junit-xml=".artifacts/plugins.junit.xml"
  151. @echo ""
  152. lint: lint-python lint-js
  153. # configuration for flake8 can be found in setup.cfg
  154. lint-python:
  155. @echo "--> Linting python"
  156. bash -eo pipefail -c "flake8 | tee .artifacts/flake8.pycodestyle.log"
  157. @echo ""
  158. review-python-snapshots:
  159. @cargo insta --version &> /dev/null || cargo install cargo-insta
  160. @cargo insta review --workspace-root `pwd` -e pysnap
  161. accept-python-snapshots:
  162. @cargo insta --version &> /dev/null || cargo install cargo-insta
  163. @cargo insta accept --workspace-root `pwd` -e pysnap
  164. reject-python-snapshots:
  165. @cargo insta --version &> /dev/null || cargo install cargo-insta
  166. @cargo insta reject --workspace-root `pwd` -e pysnap
  167. lint-js:
  168. @echo "--> Linting javascript"
  169. bin/lint --js --parseable
  170. @echo ""
  171. .PHONY: develop build reset-db clean setup-git node-version-check install-yarn-pkgs install-sentry-dev build-js-po locale update-transifex build-platform-assets test-cli test-js test-styleguide test-python test-snuba test-symbolicator test-acceptance lint lint-python lint-js publish
  172. ############################
  173. # Halt, Travis stuff below #
  174. ############################
  175. .PHONY: travis-noop
  176. travis-noop:
  177. @echo "nothing to do here."
  178. .PHONY: travis-test-lint
  179. travis-test-lint: lint-python lint-js
  180. .PHONY: travis-test-postgres travis-test-acceptance travis-test-snuba travis-test-symbolicator travis-test-js travis-test-cli
  181. travis-test-postgres: test-python
  182. travis-test-acceptance: test-acceptance
  183. travis-test-snuba: test-snuba
  184. travis-test-symbolicator: test-symbolicator
  185. travis-test-js: test-js
  186. travis-test-cli: test-cli
  187. travis-test-plugins: test-plugins
  188. .PHONY: scan-python travis-scan-postgres travis-scan-acceptance travis-scan-snuba travis-scan-symbolicator travis-scan-js travis-scan-cli travis-scan-lint
  189. scan-python:
  190. @echo "--> Running Python vulnerability scanner"
  191. $(PIP) install safety
  192. bin/scan
  193. @echo ""
  194. travis-scan-postgres: travis-noop
  195. travis-scan-acceptance: travis-noop
  196. travis-scan-snuba: travis-noop
  197. travis-scan-symbolicator: travis-noop
  198. travis-scan-js: travis-noop
  199. travis-scan-cli: travis-noop
  200. travis-scan-lint: scan-python
  201. travis-scan-plugins: travis-noop