Makefile 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. STATIC_DIR = src/sentry/static/sentry
  2. ifneq "$(wildcard /usr/local/opt/libxmlsec1/lib)" ""
  3. LDFLAGS += -L/usr/local/opt/libxmlsec1/lib
  4. endif
  5. ifneq "$(wildcard /usr/local/opt/openssl/lib)" ""
  6. LDFLAGS += -L/usr/local/opt/openssl/lib
  7. endif
  8. PIP := LDFLAGS="$(LDFLAGS)" python -m pip
  9. # Note: this has to be synced with the pip version in .travis.yml.
  10. PIP_VERSION := 19.2.3
  11. PIP_OPTS := --disable-pip-version-check
  12. WEBPACK := NODE_ENV=production ./bin/yarn webpack
  13. YARN := ./bin/yarn
  14. DROPDB := $(shell command -v dropdb 2> /dev/null)
  15. ifndef DROPDB
  16. DROPDB = docker exec sentry_postgres dropdb
  17. endif
  18. CREATEDB := $(shell command -v createdb 2> /dev/null)
  19. ifndef CREATEDB
  20. CREATEDB = docker exec sentry_postgres createdb
  21. endif
  22. bootstrap: develop init-config run-dependent-services create-db apply-migrations
  23. develop: ensure-venv setup-git develop-only
  24. develop-only: ensure-venv update-submodules install-yarn-pkgs install-sentry-dev
  25. init-config:
  26. sentry init --dev
  27. run-dependent-services:
  28. sentry devservices up
  29. test: develop lint test-js test-python test-cli
  30. build: locale
  31. drop-db:
  32. @echo "--> Dropping existing 'sentry' database"
  33. $(DROPDB) -h 127.0.0.1 -U postgres sentry || true
  34. create-db:
  35. @echo "--> Creating 'sentry' database"
  36. $(CREATEDB) -h 127.0.0.1 -U postgres -E utf-8 sentry || true
  37. apply-migrations:
  38. @echo "--> Applying migrations"
  39. sentry upgrade
  40. reset-db: drop-db create-db apply-migrations
  41. clean:
  42. @echo "--> Cleaning static cache"
  43. rm -rf dist/* static/dist/*
  44. @echo "--> Cleaning integration docs cache"
  45. rm -rf src/sentry/integration-docs
  46. @echo "--> Cleaning pyc files"
  47. find . -name "*.pyc" -delete
  48. @echo "--> Cleaning python build artifacts"
  49. rm -rf build/ dist/ src/sentry/assets.json
  50. @echo ""
  51. ensure-venv:
  52. @./scripts/ensure-venv.sh
  53. ensure-latest-pip:
  54. $(PIP) install "pip==$(PIP_VERSION)"
  55. setup-git: ensure-latest-pip
  56. @echo "--> Installing git hooks"
  57. git config branch.autosetuprebase always
  58. git config core.ignorecase false
  59. cd .git/hooks && ln -sf ../../config/hooks/* ./
  60. $(PIP) install "pre-commit==1.18.2" $(PIP_OPTS)
  61. pre-commit install --install-hooks
  62. @echo ""
  63. update-submodules:
  64. @echo "--> Updating git submodules"
  65. git submodule init
  66. git submodule update
  67. @echo ""
  68. node-version-check:
  69. @test "$$(node -v)" = v"$$(cat .nvmrc)" || (echo 'node version does not match .nvmrc. Recommended to use https://github.com/creationix/nvm'; exit 1)
  70. install-yarn-pkgs:
  71. @echo "--> Installing Yarn packages (for development)"
  72. @command -v $(YARN) 2>&1 > /dev/null || (echo 'yarn not found. Please install it before proceeding.'; exit 1)
  73. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  74. NODE_ENV=development $(YARN) install --pure-lockfile
  75. # A common problem is with node packages not existing in `node_modules` even though `yarn install`
  76. # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
  77. # account the state of the current filesystem (it only checks .yarn-integrity).
  78. # Add an additional check against `node_modules`
  79. $(YARN) check --verify-tree || $(YARN) install --check-files
  80. install-sentry-dev:
  81. @echo "--> Installing Sentry (for development)"
  82. $(PIP) install -e ".[dev]" $(PIP_OPTS)
  83. build-js-po: node-version-check
  84. mkdir -p build
  85. SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
  86. locale: build-js-po
  87. cd src/sentry && sentry django makemessages -i static -l en
  88. ./bin/merge-catalogs en
  89. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  90. cd src/sentry && sentry django compilemessages
  91. update-transifex: build-js-po
  92. $(PIP) install transifex-client $(PIP_OPTS)
  93. cd src/sentry && sentry django makemessages -i static -l en
  94. ./bin/merge-catalogs en
  95. tx push -s
  96. tx pull -a
  97. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  98. cd src/sentry && sentry django compilemessages
  99. build-platform-assets:
  100. @echo "--> Building platform assets"
  101. @echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
  102. fetch-release-registry:
  103. @echo "--> Fetching release registry"
  104. @echo "from sentry.utils.distutils import sync_registry; sync_registry()" | sentry exec
  105. test-cli:
  106. @echo "--> Testing CLI"
  107. rm -rf test_cli
  108. mkdir test_cli
  109. cd test_cli && sentry init test_conf > /dev/null
  110. cd test_cli && sentry --config=test_conf upgrade --traceback --noinput > /dev/null
  111. cd test_cli && sentry --config=test_conf help 2>&1 | grep start > /dev/null
  112. rm -r test_cli
  113. @echo ""
  114. test-js: node-version-check
  115. @echo "--> Building static assets"
  116. @$(WEBPACK) --profile --json > .artifacts/webpack-stats.json
  117. @echo "--> Running JavaScript tests"
  118. @$(YARN) run test-ci
  119. @echo ""
  120. # builds and creates percy snapshots
  121. test-styleguide:
  122. @echo "--> Building and snapshotting styleguide"
  123. @$(YARN) run snapshot
  124. @echo ""
  125. test-python:
  126. sentry init
  127. make build-platform-assets
  128. @echo "--> Running Python tests"
  129. ifndef TEST_GROUP
  130. py.test tests/integration tests/sentry --cov . --cov-report="xml:.artifacts/python.coverage.xml" --junit-xml=".artifacts/python.junit.xml" || exit 1
  131. else
  132. 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
  133. endif
  134. @echo ""
  135. test-snuba:
  136. @echo "--> Running snuba tests"
  137. py.test tests/snuba tests/sentry/eventstream/kafka -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. sentry init
  145. @echo "--> Building static assets"
  146. @$(WEBPACK) --display errors-only
  147. @echo "--> Running acceptance tests"
  148. ifndef TEST_GROUP
  149. py.test tests/acceptance --cov . --cov-report="xml:.artifacts/acceptance.coverage.xml" --junit-xml=".artifacts/acceptance.junit.xml" --html=".artifacts/acceptance.pytest.html"
  150. else
  151. 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"
  152. endif
  153. @echo ""
  154. test-plugins:
  155. @echo "--> Building static assets"
  156. @$(WEBPACK) --display errors-only
  157. @echo "--> Running plugin tests"
  158. py.test tests/sentry_plugins -vv --cov . --cov-report="xml:.artifacts/plugins.coverage.xml" --junit-xml=".artifacts/plugins.junit.xml"
  159. @echo ""
  160. lint: lint-python lint-js
  161. # configuration for flake8 can be found in setup.cfg
  162. lint-python:
  163. @echo "--> Linting python"
  164. bash -eo pipefail -c "flake8 | tee .artifacts/flake8.pycodestyle.log"
  165. @echo ""
  166. review-python-snapshots:
  167. @cargo insta --version &> /dev/null || cargo install cargo-insta
  168. @cargo insta review --workspace-root `pwd` -e pysnap
  169. accept-python-snapshots:
  170. @cargo insta --version &> /dev/null || cargo install cargo-insta
  171. @cargo insta accept --workspace-root `pwd` -e pysnap
  172. reject-python-snapshots:
  173. @cargo insta --version &> /dev/null || cargo install cargo-insta
  174. @cargo insta reject --workspace-root `pwd` -e pysnap
  175. lint-js:
  176. @echo "--> Linting javascript"
  177. bin/lint --js --parseable
  178. @echo ""
  179. publish:
  180. python setup.py sdist bdist_wheel upload
  181. .PHONY: develop develop-only test build test reset-db clean setup-git update-submodules 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
  182. ############################
  183. # Halt, Travis stuff below #
  184. ############################
  185. .PHONY: travis-noop
  186. travis-noop:
  187. @echo "nothing to do here."
  188. .PHONY: travis-test-lint
  189. travis-test-lint: lint-python lint-js
  190. .PHONY: travis-test-postgres travis-test-acceptance travis-test-snuba travis-test-symbolicator travis-test-js travis-test-cli travis-test-dist
  191. travis-test-postgres: test-python
  192. travis-test-acceptance: test-acceptance
  193. travis-test-snuba: test-snuba
  194. travis-test-symbolicator: test-symbolicator
  195. travis-test-js: test-js
  196. travis-test-cli: test-cli
  197. travis-test-plugins: test-plugins
  198. travis-test-dist:
  199. # NOTE: We quiet down output here to workaround an issue in travis that
  200. # causes the build to fail with a EAGAIN when writing a large amount of
  201. # data to STDOUT.
  202. # See: https://github.com/travis-ci/travis-ci/issues/4704
  203. SENTRY_BUILD=$(TRAVIS_COMMIT) SENTRY_LIGHT_BUILD=0 python setup.py -q sdist bdist_wheel
  204. @ls -lh dist/
  205. .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
  206. scan-python:
  207. @echo "--> Running Python vulnerability scanner"
  208. $(PIP) install safety $(PIP_OPTS)
  209. bin/scan
  210. @echo ""
  211. travis-scan-postgres: travis-noop
  212. travis-scan-acceptance: travis-noop
  213. travis-scan-snuba: travis-noop
  214. travis-scan-symbolicator: travis-noop
  215. travis-scan-js: travis-noop
  216. travis-scan-cli: travis-noop
  217. travis-scan-dist: travis-noop
  218. travis-scan-lint: scan-python
  219. travis-scan-plugins: travis-noop