Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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-venv 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:
  17. sentry init --dev
  18. run-dependent-services:
  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:
  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:
  41. $(PIP) install --no-cache-dir "pip>=20.0.2"
  42. setup-git:
  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. $(PIP) install "pre-commit==1.18.2"
  48. pre-commit install --install-hooks
  49. @echo ""
  50. node-version-check:
  51. @test "$$(node -v)" = v"$$(cat .nvmrc)" || (echo 'node version does not match .nvmrc. Recommended to use https://github.com/creationix/nvm'; exit 1)
  52. install-yarn-pkgs: node-version-check
  53. @echo "--> Installing Yarn packages (for development)"
  54. @command -v $(YARN) 2>&1 > /dev/null || (echo 'yarn not found. Please install it before proceeding.'; exit 1)
  55. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  56. NODE_ENV=development $(YARN) install --pure-lockfile
  57. # A common problem is with node packages not existing in `node_modules` even though `yarn install`
  58. # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
  59. # account the state of the current filesystem (it only checks .yarn-integrity).
  60. # Add an additional check against `node_modules`
  61. $(YARN) check --verify-tree || $(YARN) install --check-files
  62. install-sentry-dev:
  63. @echo "--> Installing Sentry (for development)"
  64. $(PIP) install -e ".[dev]"
  65. build-js-po: node-version-check
  66. mkdir -p build
  67. SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
  68. build: locale
  69. locale: build-js-po
  70. cd src/sentry && sentry django makemessages -i static -l en
  71. ./bin/merge-catalogs en
  72. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  73. cd src/sentry && sentry django compilemessages
  74. update-transifex: build-js-po
  75. $(PIP) install transifex-client
  76. cd src/sentry && sentry django makemessages -i static -l en
  77. ./bin/merge-catalogs en
  78. tx push -s
  79. tx pull -a
  80. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  81. cd src/sentry && sentry django compilemessages
  82. build-platform-assets:
  83. @echo "--> Building platform assets"
  84. @echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
  85. fetch-release-registry:
  86. @echo "--> Fetching release registry"
  87. @echo "from sentry.utils.distutils import sync_registry; sync_registry()" | sentry exec
  88. test-cli:
  89. @echo "--> Testing CLI"
  90. rm -rf test_cli
  91. mkdir test_cli
  92. cd test_cli && sentry init test_conf
  93. cd test_cli && sentry --config=test_conf help
  94. cd test_cli && sentry --config=test_conf upgrade --traceback --noinput
  95. cd test_cli && sentry --config=test_conf export
  96. rm -r test_cli
  97. @echo ""
  98. test-js: node-version-check
  99. @echo "--> Building static assets"
  100. @$(WEBPACK) --profile --json > .artifacts/webpack-stats.json
  101. @echo "--> Running JavaScript tests"
  102. @$(YARN) run test-ci
  103. @echo ""
  104. # builds and creates percy snapshots
  105. test-styleguide:
  106. @echo "--> Building and snapshotting styleguide"
  107. @$(YARN) run snapshot
  108. @echo ""
  109. test-python:
  110. sentry init
  111. make build-platform-assets
  112. @echo "--> Running Python tests"
  113. ifndef TEST_GROUP
  114. py.test tests/integration tests/sentry --cov . --cov-report="xml:.artifacts/python.coverage.xml" --junit-xml=".artifacts/python.junit.xml" || exit 1
  115. else
  116. 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
  117. endif
  118. @echo ""
  119. test-snuba:
  120. @echo "--> Running snuba tests"
  121. py.test tests/snuba tests/sentry/eventstream/kafka -vv --cov . --cov-report="xml:.artifacts/snuba.coverage.xml" --junit-xml=".artifacts/snuba.junit.xml"
  122. @echo ""
  123. test-symbolicator:
  124. @echo "--> Running symbolicator tests"
  125. py.test tests/symbolicator -vv --cov . --cov-report="xml:.artifacts/symbolicator.coverage.xml" --junit-xml=".artifacts/symbolicator.junit.xml"
  126. @echo ""
  127. test-acceptance: node-version-check
  128. sentry init
  129. @echo "--> Building static assets"
  130. @$(WEBPACK) --display errors-only
  131. @echo "--> Running acceptance tests"
  132. ifndef TEST_GROUP
  133. 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
  134. else
  135. 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
  136. endif
  137. @echo ""
  138. test-plugins:
  139. @echo "--> Building static assets"
  140. @$(WEBPACK) --display errors-only
  141. @echo "--> Running plugin tests"
  142. py.test tests/sentry_plugins -vv --cov . --cov-report="xml:.artifacts/plugins.coverage.xml" --junit-xml=".artifacts/plugins.junit.xml"
  143. @echo ""
  144. lint: lint-python lint-js
  145. # configuration for flake8 can be found in setup.cfg
  146. lint-python:
  147. @echo "--> Linting python"
  148. bash -eo pipefail -c "flake8 | tee .artifacts/flake8.pycodestyle.log"
  149. @echo ""
  150. review-python-snapshots:
  151. @cargo insta --version &> /dev/null || cargo install cargo-insta
  152. @cargo insta review --workspace-root `pwd` -e pysnap
  153. accept-python-snapshots:
  154. @cargo insta --version &> /dev/null || cargo install cargo-insta
  155. @cargo insta accept --workspace-root `pwd` -e pysnap
  156. reject-python-snapshots:
  157. @cargo insta --version &> /dev/null || cargo install cargo-insta
  158. @cargo insta reject --workspace-root `pwd` -e pysnap
  159. lint-js:
  160. @echo "--> Linting javascript"
  161. bin/lint --js --parseable
  162. @echo ""
  163. publish:
  164. python setup.py sdist bdist_wheel upload
  165. .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
  166. ############################
  167. # Halt, Travis stuff below #
  168. ############################
  169. .PHONY: travis-noop
  170. travis-noop:
  171. @echo "nothing to do here."
  172. .PHONY: travis-test-lint
  173. travis-test-lint: lint-python lint-js
  174. .PHONY: travis-test-postgres travis-test-acceptance travis-test-snuba travis-test-symbolicator travis-test-js travis-test-cli travis-test-dist
  175. travis-test-postgres: test-python
  176. travis-test-acceptance: test-acceptance
  177. travis-test-snuba: test-snuba
  178. travis-test-symbolicator: test-symbolicator
  179. travis-test-js: test-js
  180. travis-test-cli: test-cli
  181. travis-test-plugins: test-plugins
  182. travis-test-dist:
  183. # NOTE: We quiet down output here to workaround an issue in travis that
  184. # causes the build to fail with a EAGAIN when writing a large amount of
  185. # data to STDOUT.
  186. # See: https://github.com/travis-ci/travis-ci/issues/4704
  187. SENTRY_BUILD=$(TRAVIS_COMMIT) SENTRY_LIGHT_BUILD=0 python setup.py -q sdist bdist_wheel
  188. @ls -lh dist/
  189. .PHONY: scan-python travis-scan-postgres travis-scan-acceptance travis-scan-snuba travis-scan-symbolicator travis-scan-js travis-scan-cli travis-scan-dist travis-scan-lint
  190. scan-python:
  191. @echo "--> Running Python vulnerability scanner"
  192. $(PIP) install safety
  193. bin/scan
  194. @echo ""
  195. travis-scan-postgres: travis-noop
  196. travis-scan-acceptance: travis-noop
  197. travis-scan-snuba: travis-noop
  198. travis-scan-symbolicator: travis-noop
  199. travis-scan-js: travis-noop
  200. travis-scan-cli: travis-noop
  201. travis-scan-dist: travis-noop
  202. travis-scan-lint: scan-python
  203. travis-scan-plugins: travis-noop