lib.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # Module containing code shared across various shell scripts
  3. # Execute functions from this module via the script do.sh
  4. # Check if a command is available
  5. require() {
  6. command -v "$1" >/dev/null 2>&1
  7. }
  8. query_big_sur() {
  9. if require sw_vers && sw_vers -productVersion | grep -E "11\." > /dev/null; then
  10. return 0
  11. fi
  12. return 1
  13. }
  14. upgrade-pip() {
  15. # pip versions before 20.1 do not have `pip cache` as a command which is necessary for the CI
  16. pip install --no-cache-dir --upgrade "pip>=20.1"
  17. # The Python version installed via pyenv does not come with wheel pre-installed
  18. # Installing wheel will speed up installation of Python dependencies
  19. require wheel || pip install wheel
  20. }
  21. install-py-dev() {
  22. upgrade-pip
  23. # It places us within top src dir to be at the same path as setup.py
  24. # This helps when getsentry calls into this script
  25. cd "${HERE}/.." || exit
  26. echo "--> Installing Sentry (for development)"
  27. # In Big Sur, versions of pip before 20.3 require SYSTEM_VERSION_COMPAT set
  28. if query_big_sur && python -c 'from sys import exit; import pip; from pip._vendor.packaging.version import parse; exit(1 if parse(pip.__version__) < parse("20.3") else 0)'; then
  29. SENTRY_LIGHT_BUILD=1 SYSTEM_VERSION_COMPAT=1 pip install -e '.[dev]'
  30. else
  31. # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
  32. # Webpacked assets are only necessary for devserver (which does it lazily anyways)
  33. # and acceptance tests, which webpack automatically if run.
  34. SENTRY_LIGHT_BUILD=1 pip install -e '.[dev]'
  35. fi
  36. }
  37. init-config() {
  38. sentry init --dev
  39. }
  40. run-dependent-services() {
  41. sentry devservices up
  42. }
  43. apply-migrations() {
  44. echo "--> Applying migrations"
  45. sentry upgrade
  46. }
  47. setup-git-config() {
  48. git config --local branch.autosetuprebase always
  49. git config --local core.ignorecase false
  50. git config --local blame.ignoreRevsFile .git-blame-ignore-revs
  51. }
  52. setup-git() {
  53. setup-git-config
  54. echo "--> Installing git hooks"
  55. mkdir -p .git/hooks && cd .git/hooks && ln -sf ../../config/hooks/* ./ && cd - || exit
  56. # shellcheck disable=SC2016
  57. python3 -c '' || (echo 'Please run `make setup-pyenv` to install the required Python 3 version.'; exit 1)
  58. pip install -r requirements-pre-commit.txt
  59. pre-commit install --install-hooks
  60. echo ""
  61. }
  62. install-js-dev() {
  63. echo "--> Installing Yarn packages (for development)"
  64. # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
  65. NODE_ENV=development yarn install --frozen-lockfile
  66. # A common problem is with node packages not existing in `node_modules` even though `yarn install`
  67. # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
  68. # account the state of the current filesystem (it only checks .yarn-integrity).
  69. # Add an additional check against `node_modules`
  70. yarn check --verify-tree || yarn install --check-files
  71. }
  72. develop() {
  73. setup-git
  74. install-js-dev
  75. install-py-dev
  76. }