Browse Source

build(feat): Report make develop errors to Sentry.io (#24532)

Move logic of `make develop` inside of `lib.sh` and call this logic via `do.sh` which initializes the `sentry-cli` logic to report errors to Sentry.io.
Armen Zambrano G 4 years ago
parent
commit
afd46356c7
5 changed files with 116 additions and 88 deletions
  1. 4 11
      .github/workflows/development-environment.yml
  2. 16 38
      Makefile
  3. 23 0
      scripts/do.sh
  4. 73 0
      scripts/lib.sh
  5. 0 39
      scripts/python.sh

+ 4 - 11
.github/workflows/development-environment.yml

@@ -81,19 +81,12 @@ jobs:
           restore-keys: |
             ${{ matrix.os }}-yarn-
 
-      - name: Set up development environment (as per docs)
+      # We cannot call make bootstrap directly since run-dependent-services requires some Docker magic.
+      # We have the magic in the getsentry/bootstrap-develop. We will handle this situation in the next pass of this.
+      # make init-config will *not* prompt about overwriting ~/.sentry/config.yml' since we're on a pristine state
+      - name: Set up development environment (mostly as per docs)
         run: |
           python -m venv .venv
           source .venv/bin/activate
-          make install-py-dev
-          make setup-git
           curl https://get.volta.sh | bash
-
-      - name: Set up Sentry and others
-        # We cannot call make bootstrap directly since run-dependent-services requires some Docker magic.
-        # We have the magic in the getsentry/bootstrap-develop. We will handle this situation in the next pass of this.
-        # make init-config will *not* prompt about overwriting ~/.sentry/config.yml' since we're on a pristine state
-        # We cannot test the git hooks until the `sentry.lint.engine` gets installed
-        run: |
-          source .venv/bin/activate
           make develop init-config

+ 16 - 38
Makefile

@@ -3,7 +3,8 @@ WEBPACK := yarn build-acceptance
 
 bootstrap: develop init-config run-dependent-services create-db apply-migrations build-platform-assets
 
-develop: ensure-pinned-pip setup-git install-js-dev install-py-dev
+develop:
+	@./scripts/do.sh develop
 
 clean:
 	@echo "--> Cleaning static cache"
@@ -16,11 +17,11 @@ clean:
 	rm -rf build/ dist/ src/sentry/assets.json
 	@echo ""
 
-init-config: ensure-venv
-	sentry init --dev
+init-config:
+	@./scripts/do.sh init-config
 
-run-dependent-services: ensure-venv
-	sentry devservices up
+run-dependent-services:
+	@./scripts/do.sh run-dependent-services
 
 DROPDB := $(shell command -v dropdb 2> /dev/null)
 ifndef DROPDB
@@ -39,35 +40,22 @@ create-db:
 	@echo "--> Creating 'sentry' database"
 	$(CREATEDB) -h 127.0.0.1 -U postgres -E utf-8 sentry || true
 
-apply-migrations: ensure-venv
-	@echo "--> Applying migrations"
-	sentry upgrade
+apply-migrations:
+	@./scripts/do.sh apply-migrations
 
 reset-db: drop-db create-db apply-migrations
 
 setup-pyenv:
-	./scripts/pyenv_setup.sh
-
-ensure-venv:
-	./scripts/ensure-venv.sh
-
-ensure-pinned-pip: ensure-venv upgrade-pip
+	@./scripts/pyenv_setup.sh
 
 upgrade-pip:
-	./scripts/python.sh upgrade-pip
+	@SENTRY_NO_VENV_CHECK=1 ./scripts/do.sh upgrade-pip
 
 setup-git-config:
-	@git config --local branch.autosetuprebase always
-	@git config --local core.ignorecase false
-	@git config --local blame.ignoreRevsFile .git-blame-ignore-revs
-
-setup-git: ensure-venv setup-git-config
-	@echo "--> Installing git hooks"
-	mkdir -p .git/hooks && cd .git/hooks && ln -sf ../../config/hooks/* ./
-	@python3 -c '' || (echo 'Please run `make setup-pyenv` to install the required Python 3 version.'; exit 1)
-	$(PIP) install -r requirements-pre-commit.txt
-	@pre-commit install --install-hooks
-	@echo ""
+	@SENTRY_NO_VENV_CHECK=1 ./scripts/do.sh setup-git-config
+
+setup-git:
+	@./scripts/do.sh setup-git
 
 node-version-check:
 	@# Checks to see if node's version matches the one specified in package.json for Volta.
@@ -75,17 +63,10 @@ node-version-check:
 	(echo 'Unexpected node version. Recommended to use https://github.com/volta-cli/volta'; exit 1)
 
 install-js-dev: node-version-check
-	@echo "--> Installing Yarn packages (for development)"
-	# Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
-	NODE_ENV=development yarn install --frozen-lockfile
-	# A common problem is with node packages not existing in `node_modules` even though `yarn install`
-	# says everything is up to date. Even though `yarn install` is run already, it doesn't take into
-	# account the state of the current filesystem (it only checks .yarn-integrity).
-	# Add an additional check against `node_modules`
-	yarn check --verify-tree || yarn install --check-files
+	@./scripts/do.sh install-js-dev
 
 install-py-dev:
-	./scripts/python.sh install-py-dev
+	@./scripts/do.sh install-py-dev
 
 build-js-po: node-version-check
 	mkdir -p build
@@ -228,9 +209,6 @@ lint-js:
         apply-migrations \
         reset-db \
         setup-pyenv \
-        ensure-venv \
-        ensure-pinned-pip \
-        upgrade-pip \
         setup-git-config \
         setup-git \
         node-version-check \

+ 23 - 0
scripts/do.sh

@@ -0,0 +1,23 @@
+#!/bin/bash
+# This script is an interface to any of the methods of lib.sh
+# Call this script as "do.sh method_from_lib" to execute any function from that library
+set -eu
+
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
+# shellcheck disable=SC1090
+source "${HERE}/lib.sh"
+
+# This block is to enable reporting issues to Sentry.io
+# SENTRY_DSN already defined in .envrc
+if [ -n "${SENTRY_DSN+x}" ] && [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ]; then
+    if ! require sentry-cli; then
+        curl -sL https://sentry.io/get-cli/ | bash
+    fi
+    eval "$(sentry-cli bash-hook)"
+fi
+
+# This guarantees that we're within a venv. A caller that is not within
+# a venv can avoid enabling this by setting SENTRY_NO_VENV_CHECK
+[ -z "${SENTRY_NO_VENV_CHECK+x}" ] && eval "${HERE}/ensure-venv.sh"
+# If you call this script
+"$@"

+ 73 - 0
scripts/lib.sh

@@ -1,5 +1,6 @@
 #!/bin/bash
 # Module containing code shared across various shell scripts
+# Execute functions from this module via the script do.sh
 
 # Check if a command is available
 require() {
@@ -12,3 +13,75 @@ query_big_sur() {
     fi
     return 1
 }
+
+upgrade-pip() {
+    # pip versions before 20.1 do not have `pip cache` as a command which is necessary for the CI
+    pip install --no-cache-dir --upgrade "pip>=20.1"
+    # The Python version installed via pyenv does not come with wheel pre-installed
+    # Installing wheel will speed up installation of Python dependencies
+    require wheel || pip install wheel
+}
+
+install-py-dev() {
+    upgrade-pip
+    # It places us within top src dir to be at the same path as setup.py
+    # This helps when getsentry calls into this script
+    cd "${HERE}/.." || exit
+    echo "--> Installing Sentry (for development)"
+    # In Big Sur, versions of pip before 20.3 require SYSTEM_VERSION_COMPAT set
+    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
+        SENTRY_LIGHT_BUILD=1 SYSTEM_VERSION_COMPAT=1 pip install -e '.[dev]'
+    else
+        # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
+        # Webpacked assets are only necessary for devserver (which does it lazily anyways)
+        # and acceptance tests, which webpack automatically if run.
+        SENTRY_LIGHT_BUILD=1 pip install -e '.[dev]'
+    fi
+}
+
+init-config() {
+    sentry init --dev
+}
+
+run-dependent-services() {
+    sentry devservices up
+}
+
+apply-migrations() {
+    echo "--> Applying migrations"
+    sentry upgrade
+}
+
+setup-git-config() {
+    git config --local branch.autosetuprebase always
+    git config --local core.ignorecase false
+    git config --local blame.ignoreRevsFile .git-blame-ignore-revs
+}
+
+setup-git() {
+    setup-git-config
+    echo "--> Installing git hooks"
+    mkdir -p .git/hooks && cd .git/hooks && ln -sf ../../config/hooks/* ./ && cd - || exit
+    # shellcheck disable=SC2016
+    python3 -c '' || (echo 'Please run `make setup-pyenv` to install the required Python 3 version.'; exit 1)
+    pip install -r requirements-pre-commit.txt
+    pre-commit install --install-hooks
+    echo ""
+}
+
+install-js-dev() {
+    echo "--> Installing Yarn packages (for development)"
+    # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
+    NODE_ENV=development yarn install --frozen-lockfile
+    # A common problem is with node packages not existing in `node_modules` even though `yarn install`
+    # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
+    # account the state of the current filesystem (it only checks .yarn-integrity).
+    # Add an additional check against `node_modules`
+    yarn check --verify-tree || yarn install --check-files
+}
+
+develop() {
+    setup-git
+    install-js-dev
+    install-py-dev
+}

+ 0 - 39
scripts/python.sh

@@ -1,39 +0,0 @@
-#!/bin/bash
-# This script correctly installs Python dependencies
-set -eu
-
-HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
-# shellcheck disable=SC1090
-source "${HERE}/lib.sh"
-
-ensure-venv() {
-    eval "${HERE}/ensure-venv.sh"
-}
-
-upgrade-pip() {
-    # pip versions before 20.1 do not have `pip cache` as a command which is necessary for the CI
-    pip install --no-cache-dir --upgrade "pip>=20.1"
-    # The Python version installed via pyenv does not come with wheel pre-installed
-    # Installing wheel will speed up installation of Python dependencies
-    require wheel || pip install wheel
-}
-
-install-py-dev() {
-    ensure-venv
-    upgrade-pip
-    # It places us within top src dir to be at the same path as setup.py
-    # This helps when getsentry calls into this script
-    cd "${HERE}/.."
-    echo "--> Installing Sentry (for development)"
-    # In Big Sur, versions of pip before 20.3 require SYSTEM_VERSION_COMPAT set
-    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
-        SENTRY_LIGHT_BUILD=1 SYSTEM_VERSION_COMPAT=1 pip install -e '.[dev]'
-    else
-        # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
-	    # Webpacked assets are only necessary for devserver (which does it lazily anyways)
-	    # and acceptance tests, which webpack automatically if run.
-        SENTRY_LIGHT_BUILD=1 pip install -e '.[dev]'
-    fi
-}
-
-"$@"