Makefile 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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)" pip
  9. WEBPACK = NODE_ENV=production ./bin/yarn webpack
  10. YARN = ./bin/yarn
  11. bootstrap: install-system-pkgs develop init-config run-dependent-services create-db apply-migrations
  12. develop: setup-git ensure-venv develop-only
  13. develop-only: update-submodules install-yarn-pkgs install-sentry-dev
  14. init-config:
  15. sentry init --dev
  16. run-dependent-services:
  17. sentry devservices up
  18. test: develop lint test-js test-python test-cli
  19. ensure-venv:
  20. @./scripts/ensure-venv.sh
  21. build: locale
  22. drop-db:
  23. @echo "--> Dropping existing 'sentry' database"
  24. dropdb -h 127.0.0.1 -U postgres sentry || true
  25. create-db:
  26. @echo "--> Creating 'sentry' database"
  27. createdb -h 127.0.0.1 -U postgres -E utf-8 sentry || true
  28. apply-migrations:
  29. @echo "--> Applying migrations"
  30. sentry upgrade
  31. reset-db: drop-db create-db apply-migrations
  32. clean:
  33. @echo "--> Cleaning static cache"
  34. rm -rf dist/* static/dist/*
  35. @echo "--> Cleaning integration docs cache"
  36. rm -rf src/sentry/integration-docs
  37. @echo "--> Cleaning pyc files"
  38. find . -name "*.pyc" -delete
  39. @echo "--> Cleaning python build artifacts"
  40. rm -rf build/ dist/ src/sentry/assets.json
  41. @echo ""
  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.10.1,<1.11.0"
  48. pre-commit install
  49. @echo ""
  50. update-submodules:
  51. @echo "--> Updating git submodules"
  52. git submodule init
  53. git submodule update
  54. @echo ""
  55. node-version-check:
  56. @test "$$(node -v)" = v"$$(cat .nvmrc)" || (echo 'node version does not match .nvmrc. Recommended to use https://github.com/creationix/nvm'; exit 1)
  57. install-system-pkgs: node-version-check
  58. @echo "--> Installing system packages (from Brewfile)"
  59. @command -v brew 2>&1 > /dev/null && brew bundle || (echo 'WARNING: homebrew not found or brew bundle failed - skipping system dependencies.')
  60. install-yarn-pkgs:
  61. @echo "--> Installing Yarn packages (for development)"
  62. @command -v $(YARN) 2>&1 > /dev/null || (echo 'yarn not found. Please install it before proceeding.'; exit 1)
  63. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  64. NODE_ENV=development $(YARN) install --pure-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-sentry-dev:
  71. @echo "--> Installing Sentry (for development)"
  72. $(PIP) install -e ".[dev,tests,optional]"
  73. build-js-po: node-version-check
  74. mkdir -p build
  75. SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
  76. locale: build-js-po
  77. cd src/sentry && sentry django makemessages -i static -l en
  78. ./bin/merge-catalogs en
  79. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  80. cd src/sentry && sentry django compilemessages
  81. update-transifex: build-js-po
  82. $(PIP) install transifex-client
  83. cd src/sentry && sentry django makemessages -i static -l en
  84. ./bin/merge-catalogs en
  85. tx push -s
  86. tx pull -a
  87. ./bin/find-good-catalogs src/sentry/locale/catalogs.json
  88. cd src/sentry && sentry django compilemessages
  89. build-platform-assets:
  90. @echo "--> Building platform assets"
  91. @echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
  92. fetch-release-registry:
  93. @echo "--> Fetching release registry"
  94. @echo "from sentry.utils.distutils import sync_registry; sync_registry()" | sentry exec
  95. test-cli:
  96. @echo "--> Testing CLI"
  97. rm -rf test_cli
  98. mkdir test_cli
  99. cd test_cli && sentry init test_conf > /dev/null
  100. cd test_cli && sentry --config=test_conf upgrade --traceback --noinput > /dev/null
  101. cd test_cli && sentry --config=test_conf help 2>&1 | grep start > /dev/null
  102. rm -r test_cli
  103. @echo ""
  104. test-js: node-version-check
  105. @echo "--> Building static assets"
  106. @$(WEBPACK) --profile --json > .artifacts/webpack-stats.json
  107. @echo "--> Running JavaScript tests"
  108. @$(YARN) run test-ci
  109. @echo ""
  110. # builds and creates percy snapshots
  111. test-styleguide:
  112. @echo "--> Building and snapshotting styleguide"
  113. @$(YARN) run snapshot
  114. @echo ""
  115. test-python:
  116. sentry init
  117. make build-platform-assets
  118. @echo "--> Running Python tests"
  119. ifndef TEST_GROUP
  120. py.test tests/integration tests/sentry --cov . --cov-report="xml:.artifacts/python.coverage.xml" --junit-xml=".artifacts/python.junit.xml" || exit 1
  121. else
  122. 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
  123. endif
  124. @echo ""
  125. test-riak:
  126. sentry init
  127. @echo "--> Running Riak tests"
  128. py.test tests/sentry/nodestore/riak/backend --cov . --cov-report="xml:.artifacts/riak.coverage.xml" --junit-xml=".artifacts/riak.junit.xml" || exit 1
  129. @echo ""
  130. test-snuba:
  131. @echo "--> Running snuba tests"
  132. py.test tests/snuba tests/sentry/eventstream/kafka -vv --cov . --cov-report="xml:.artifacts/snuba.coverage.xml" --junit-xml=".artifacts/snuba.junit.xml"
  133. @echo ""
  134. test-symbolicator:
  135. @echo "--> Running symbolicator tests"
  136. py.test tests/symbolicator -vv --cov . --cov-report="xml:.artifacts/symbolicator.coverage.xml" --junit-xml=".artifacts/symbolicator.junit.xml"
  137. @echo ""
  138. test-acceptance: node-version-check
  139. sentry init
  140. @echo "--> Building static assets"
  141. @$(WEBPACK) --display errors-only
  142. @echo "--> Running acceptance tests"
  143. ifndef TEST_GROUP
  144. py.test tests/acceptance --cov . --cov-report="xml:.artifacts/acceptance.coverage.xml" --junit-xml=".artifacts/acceptance.junit.xml" --html=".artifacts/acceptance.pytest.html"
  145. else
  146. 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"
  147. endif
  148. @echo ""
  149. lint: lint-python lint-js
  150. lint-python:
  151. @echo "--> Linting python"
  152. bash -eo pipefail -c "flake8 | tee .artifacts/flake8.pycodestyle.log"
  153. @echo ""
  154. review-python-snapshots:
  155. @cargo insta --version &> /dev/null || cargo install cargo-insta
  156. @cargo insta review --workspace-root `pwd` -e pysnap
  157. accept-python-snapshots:
  158. @cargo insta --version &> /dev/null || cargo install cargo-insta
  159. @cargo insta accept --workspace-root `pwd` -e pysnap
  160. reject-python-snapshots:
  161. @cargo insta --version &> /dev/null || cargo install cargo-insta
  162. @cargo insta reject --workspace-root `pwd` -e pysnap
  163. lint-js:
  164. @echo "--> Linting javascript"
  165. bin/lint --js --parseable
  166. @echo ""
  167. publish:
  168. python setup.py sdist bdist_wheel upload
  169. .PHONY: develop develop-only test build test reset-db clean setup-git update-submodules node-version-check install-system-pkgs 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
  170. ############################
  171. # Halt, Travis stuff below #
  172. ############################
  173. .PHONY: travis-noop
  174. travis-noop:
  175. @echo "nothing to do here."
  176. .PHONY: travis-test-lint
  177. travis-test-lint: lint-python lint-js
  178. .PHONY: travis-test-postgres travis-test-acceptance travis-test-snuba travis-test-symbolicator travis-test-js travis-test-cli travis-test-dist travis-test-riak
  179. travis-test-postgres: test-python
  180. travis-test-acceptance: test-acceptance
  181. travis-test-snuba: test-snuba
  182. travis-test-symbolicator: test-symbolicator
  183. travis-test-js: test-js
  184. travis-test-cli: test-cli
  185. travis-test-dist:
  186. # NOTE: We quiet down output here to workaround an issue in travis that
  187. # causes the build to fail with a EAGAIN when writing a large amount of
  188. # data to STDOUT.
  189. # See: https://github.com/travis-ci/travis-ci/issues/4704
  190. SENTRY_BUILD=$(TRAVIS_COMMIT) SENTRY_LIGHT_BUILD=0 python setup.py -q sdist bdist_wheel
  191. @ls -lh dist/
  192. travis-test-riak: test-riak
  193. .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 travis-scan-riak
  194. scan-python:
  195. @echo "--> Running Python vulnerability scanner"
  196. $(PIP) install safety
  197. bin/scan
  198. @echo ""
  199. travis-scan-postgres: travis-noop
  200. travis-scan-acceptance: travis-noop
  201. travis-scan-snuba: travis-noop
  202. travis-scan-symbolicator: travis-noop
  203. travis-scan-js: travis-noop
  204. travis-scan-cli: travis-noop
  205. travis-scan-dist: travis-noop
  206. travis-scan-lint: scan-python
  207. travis-scan-riak: travis-noop