Makefile 8.7 KB

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