2016-08-12 11:23:50 +01:00
|
|
|
.DEFAULT_GOAL := help
|
|
|
|
|
SHELL := /bin/bash
|
2018-08-09 13:46:43 +01:00
|
|
|
DATE = $(shell date +%Y-%m-%dT%H:%M:%S)
|
2016-08-12 11:23:50 +01:00
|
|
|
|
|
|
|
|
APP_VERSION_FILE = app/version.py
|
|
|
|
|
|
2016-08-26 16:18:13 +01:00
|
|
|
GIT_BRANCH ?= $(shell git symbolic-ref --short HEAD 2> /dev/null || echo "detached")
|
2017-02-01 15:44:10 +00:00
|
|
|
GIT_COMMIT ?= $(shell git rev-parse HEAD 2> /dev/null || echo "")
|
2025-04-14 15:47:12 -04:00
|
|
|
GIT_HOOKS_PATH ?= $(shell git config --global core.hooksPath || echo "")
|
2016-08-12 11:23:50 +01:00
|
|
|
|
2020-12-29 13:21:13 +00:00
|
|
|
VIRTUALENV_ROOT := $(shell [ -z $$VIRTUAL_ENV ] && echo $$(pwd)/venv || echo $$VIRTUAL_ENV)
|
|
|
|
|
|
2022-08-08 14:43:05 -04:00
|
|
|
NVMSH := $(shell [ -f "$(HOME)/.nvm/nvm.sh" ] && echo "$(HOME)/.nvm/nvm.sh" || echo "/usr/local/share/nvm/nvm.sh")
|
2020-03-03 12:05:56 +00:00
|
|
|
|
|
|
|
|
## DEVELOPMENT
|
|
|
|
|
|
2021-02-22 16:53:54 +00:00
|
|
|
.PHONY: bootstrap
|
2025-07-29 11:21:24 -07:00
|
|
|
bootstrap: ## Set up everything to run the application
|
2025-04-14 16:17:35 -04:00
|
|
|
make generate-version-file
|
2025-05-29 11:19:22 -07:00
|
|
|
poetry sync --no-root
|
2025-04-14 16:17:35 -04:00
|
|
|
poetry run playwright install --with-deps
|
|
|
|
|
poetry run pre-commit install
|
|
|
|
|
source $(NVMSH) --no-use && nvm install && npm install
|
|
|
|
|
source $(NVMSH) && npm ci --no-audit
|
|
|
|
|
source $(NVMSH) && npm run build
|
|
|
|
|
|
|
|
|
|
.PHONY: bootstrap-with-git-hooks
|
|
|
|
|
bootstrap-with-git-hooks: ## Sets everything up and accounts for pre-existing git hooks
|
|
|
|
|
make generate-version-file
|
2025-05-30 11:06:45 -04:00
|
|
|
poetry sync --no-root
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry run playwright install --with-deps
|
2025-04-14 15:47:12 -04:00
|
|
|
git config --global --unset-all core.hooksPath
|
2023-11-22 10:28:18 -05:00
|
|
|
poetry run pre-commit install
|
2025-04-14 15:47:12 -04:00
|
|
|
git config --global core.hookspath "${GIT_HOOKS_PATH}"
|
2024-06-18 10:21:23 -04:00
|
|
|
source $(NVMSH) --no-use && nvm install && npm install
|
|
|
|
|
source $(NVMSH) && npm ci --no-audit
|
2022-08-08 14:43:05 -04:00
|
|
|
source $(NVMSH) && npm run build
|
2022-06-13 14:26:46 -07:00
|
|
|
|
2021-11-02 15:22:57 +00:00
|
|
|
.PHONY: watch-frontend
|
|
|
|
|
watch-frontend: ## Build frontend and watch for changes
|
2023-03-07 17:15:31 -05:00
|
|
|
source $(NVMSH) && npm run watch
|
2021-11-02 15:22:57 +00:00
|
|
|
|
2021-02-22 16:41:30 +00:00
|
|
|
.PHONY: run-flask
|
2021-05-25 11:21:39 +01:00
|
|
|
run-flask: ## Run flask
|
2025-07-29 16:32:52 -04:00
|
|
|
poetry run newrelic-admin run-program flask run -p 6012 --host=0.0.0.0
|
2021-02-22 16:41:30 +00:00
|
|
|
|
2025-08-07 15:52:56 -04:00
|
|
|
.PHONY: wait-for-flask
|
|
|
|
|
wait-for-flask:
|
|
|
|
|
@echo "Waiting for Flask to start..."
|
|
|
|
|
@timeout 30 bash -c 'until curl -sf http://localhost:6012 > /dev/null 2>&1; do sleep 1; done'
|
|
|
|
|
@echo "Flask is ready!"
|
|
|
|
|
|
2025-08-07 11:55:26 -04:00
|
|
|
.PHONY: run-flask-and-wait
|
|
|
|
|
run-flask-and-wait:
|
|
|
|
|
@make run-flask &
|
|
|
|
|
@echo "Waiting for Flask to start..."
|
|
|
|
|
@timeout 30 bash -c 'until curl -sf http://localhost:6012 > /dev/null 2>&1; do sleep 1; done'
|
|
|
|
|
@echo "Flask is ready!"
|
|
|
|
|
|
2023-03-08 09:57:21 -05:00
|
|
|
.PHONY: run-flask-bare
|
2023-09-01 07:56:02 -07:00
|
|
|
run-flask-bare: ## Run flask without invoking poetry so we can override ENV variables in .env
|
2023-03-08 09:57:21 -05:00
|
|
|
flask run -p 6012 --host=0.0.0.0
|
|
|
|
|
|
2022-05-06 15:34:54 +01:00
|
|
|
.PHONY: npm-audit
|
|
|
|
|
npm-audit: ## Check for vulnerabilities in NPM packages
|
2022-08-08 14:43:05 -04:00
|
|
|
source $(NVMSH) && npm run audit
|
2022-05-06 15:34:54 +01:00
|
|
|
|
2024-06-17 23:46:59 -04:00
|
|
|
.PHONY: npm-audit-fix
|
|
|
|
|
npm-audit-fix: ## Fix vulnerabilities that do not require attentino (according to npm)
|
|
|
|
|
source $(NVMSH) && npm audit fix
|
|
|
|
|
|
2016-08-12 11:23:50 +01:00
|
|
|
.PHONY: help
|
|
|
|
|
help:
|
|
|
|
|
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|
|
|
|
|
|
|
|
.PHONY: generate-version-file
|
|
|
|
|
generate-version-file: ## Generates the app version file
|
2020-04-21 17:00:38 +01:00
|
|
|
@echo -e "__git_commit__ = \"${GIT_COMMIT}\"\n__time__ = \"${DATE}\"" > ${APP_VERSION_FILE}
|
2016-08-12 11:23:50 +01:00
|
|
|
|
|
|
|
|
.PHONY: test
|
2025-04-16 17:45:32 -04:00
|
|
|
test: py-lint py-test js-test ## Run tests
|
2022-10-27 11:10:13 -04:00
|
|
|
|
2025-08-15 15:02:54 -04:00
|
|
|
.PHONY: test-fast
|
|
|
|
|
test-fast: py-lint py-test-fast js-test ## Run tests quickly in parallel (testing locally first)
|
|
|
|
|
|
2022-10-27 11:10:13 -04:00
|
|
|
.PHONY: py-lint
|
2023-08-25 12:58:53 -07:00
|
|
|
py-lint: ## Run python linting scanners and black
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry self add poetry-dotenv-plugin
|
|
|
|
|
poetry run black .
|
|
|
|
|
poetry run flake8 .
|
|
|
|
|
poetry run isort --check-only ./app ./tests
|
2022-10-27 11:10:13 -04:00
|
|
|
|
2025-01-29 13:22:22 -08:00
|
|
|
.PHONY: tada
|
|
|
|
|
tada: ## Run python linting scanners and black
|
|
|
|
|
poetry run isort ./app ./tests
|
|
|
|
|
poetry run black .
|
|
|
|
|
poetry run flake8 .
|
|
|
|
|
|
|
|
|
|
|
2023-08-07 10:41:07 -07:00
|
|
|
.PHONY: avg-complexity
|
|
|
|
|
avg-complexity:
|
|
|
|
|
echo "*** Shows average complexity in radon of all code ***"
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry run radon cc ./app -a -na
|
2023-08-07 10:41:07 -07:00
|
|
|
|
|
|
|
|
.PHONY: too-complex
|
|
|
|
|
too-complex:
|
2023-08-07 10:58:32 -07:00
|
|
|
echo "*** Shows code that got a rating of C, D or F in radon ***"
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry run radon cc ./app -a -nc
|
2023-08-07 10:41:07 -07:00
|
|
|
|
2022-10-27 11:10:13 -04:00
|
|
|
.PHONY: py-test
|
2023-01-23 10:00:03 -05:00
|
|
|
py-test: export NEW_RELIC_ENVIRONMENT=test
|
2022-10-27 11:10:13 -04:00
|
|
|
py-test: ## Run python unit tests
|
2024-05-16 10:37:37 -04:00
|
|
|
poetry run coverage run -m pytest --maxfail=10 --ignore=tests/end_to_end tests/
|
2025-04-16 17:45:32 -04:00
|
|
|
poetry run coverage report --fail-under=93
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry run coverage html -d .coverage_cache
|
2016-08-12 11:23:50 +01:00
|
|
|
|
2025-08-15 15:02:54 -04:00
|
|
|
.PHONY: py-test-fast
|
|
|
|
|
py-test-fast: export NEW_RELIC_ENVIRONMENT=test
|
|
|
|
|
py-test-fast: ## Run python unit tests in parallel (testing locally first)
|
|
|
|
|
poetry run pytest --maxfail=10 --ignore=tests/end_to_end tests/ -n auto
|
|
|
|
|
|
2023-08-08 13:16:20 -07:00
|
|
|
.PHONY: dead-code
|
2024-05-20 11:18:31 -07:00
|
|
|
dead-code: ## 60% is our aspirational goal, but currently breaks the build
|
|
|
|
|
poetry run vulture ./app ./notifications_utils --min-confidence=100
|
|
|
|
|
|
2023-07-28 09:31:45 -04:00
|
|
|
.PHONY: e2e-test
|
|
|
|
|
e2e-test: export NEW_RELIC_ENVIRONMENT=test
|
2024-01-25 17:52:32 -05:00
|
|
|
e2e-test: ## Run end-to-end integration tests; note that --browser webkit isn't currently working
|
2025-05-02 10:43:07 -04:00
|
|
|
@echo "Running E2E tests in path: $${TESTPATH:-tests/end_to_end}"
|
|
|
|
|
@bash -c 'DEBUG=pw:api,pw:browser poetry run pytest -vv --browser chromium --browser firefox "$${TESTPATH:-tests/end_to_end}"'
|
2023-07-28 09:31:45 -04:00
|
|
|
|
2022-10-27 11:10:13 -04:00
|
|
|
.PHONY: js-lint
|
|
|
|
|
js-lint: ## Run javascript linting scanners
|
|
|
|
|
source $(NVMSH) && npm run lint
|
|
|
|
|
|
|
|
|
|
.PHONY: js-test
|
|
|
|
|
js-test: ## Run javascript unit tests
|
|
|
|
|
source $(NVMSH) && npm test
|
|
|
|
|
|
2020-01-13 10:26:11 +00:00
|
|
|
.PHONY: fix-imports
|
2021-05-25 11:21:39 +01:00
|
|
|
fix-imports: ## Fix imports using isort
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry run isort ./app ./tests
|
2020-01-13 10:26:11 +00:00
|
|
|
|
2023-10-30 16:01:21 -04:00
|
|
|
.PHONY: py-lock
|
|
|
|
|
py-lock: ## Syncs dependencies and updates lock file without performing recursive internal updates
|
|
|
|
|
poetry lock --no-update
|
2023-11-01 12:16:35 -04:00
|
|
|
poetry install --sync
|
|
|
|
|
|
2018-07-10 15:16:14 +01:00
|
|
|
.PHONY: freeze-requirements
|
2021-01-08 16:40:51 +00:00
|
|
|
freeze-requirements: ## create static requirements.txt
|
2025-05-27 12:00:46 -07:00
|
|
|
poetry export --output requirements.txt
|
2018-07-10 15:16:14 +01:00
|
|
|
|
2022-08-25 20:36:13 +00:00
|
|
|
.PHONY: pip-audit
|
|
|
|
|
pip-audit:
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry requirements > requirements.txt
|
|
|
|
|
poetry requirements --dev > requirements_for_test.txt
|
|
|
|
|
poetry run pip-audit -r requirements.txt
|
2023-11-01 12:16:35 -04:00
|
|
|
poetry run pip-audit -r requirements_for_test.txt
|
2022-08-25 20:36:13 +00:00
|
|
|
|
|
|
|
|
.PHONY: audit
|
|
|
|
|
audit: npm-audit pip-audit
|
|
|
|
|
|
2022-08-26 14:12:26 +00:00
|
|
|
.PHONY: static-scan
|
|
|
|
|
static-scan:
|
2023-09-01 07:56:02 -07:00
|
|
|
poetry run bandit -r app/
|
2022-08-26 14:12:26 +00:00
|
|
|
|
2022-08-30 10:31:48 -04:00
|
|
|
.PHONY: a11y-scan
|
|
|
|
|
a11y-scan:
|
2022-09-02 13:29:56 -04:00
|
|
|
source $(NVMSH) && npm install -g pa11y-ci
|
|
|
|
|
source $(NVMSH) && pa11y-ci
|
2022-08-30 10:31:48 -04:00
|
|
|
|
2016-12-08 16:50:37 +00:00
|
|
|
.PHONY: clean
|
2016-08-12 11:23:50 +01:00
|
|
|
clean:
|
2020-12-08 17:15:47 +00:00
|
|
|
rm -rf node_modules cache target ${CF_MANIFEST_PATH}
|
2016-12-08 16:50:37 +00:00
|
|
|
|
2020-03-03 12:05:56 +00:00
|
|
|
|
|
|
|
|
## DEPLOYMENT
|
|
|
|
|
|
2020-03-03 12:05:15 +00:00
|
|
|
.PHONY: upload-static ## Upload the static files to be served from S3
|
|
|
|
|
upload-static:
|
2022-06-23 14:08:29 -07:00
|
|
|
aws s3 cp --region us-west-2 --recursive --cache-control max-age=315360000,immutable ./app/static s3://${DNS_NAME}-static
|
2020-03-03 12:05:15 +00:00
|
|
|
|
2025-02-26 11:11:47 -05:00
|
|
|
.PHONY: test-single
|
|
|
|
|
test-single: export NEW_RELIC_ENVIRONMENT=test
|
|
|
|
|
test-single: ## Run a single test file
|
|
|
|
|
poetry run pytest $(TEST_FILE)
|