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