Skip to content

Commit

Permalink
Merge branch 'dev' into feat_search_bar
Browse files Browse the repository at this point in the history
  • Loading branch information
hartym authored Mar 29, 2024
2 parents b27819d + ed02873 commit 9057a1e
Show file tree
Hide file tree
Showing 32 changed files with 730 additions and 1,108 deletions.
165 changes: 107 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# package
NAME ?= harp-proxy
VERSION ?= $(shell git describe 2>/dev/null || git rev-parse --short HEAD)

# pre commit
PRE_COMMIT ?= $(shell which pre-commit || echo "pre-commit")
PYTEST ?= $(shell which pytest || echo "pytest")

# poetry
POETRY ?= $(shell which poetry || echo "poetry")
POETRY_INSTALL_OPTIONS ?=
RUN ?= $(if $(VIRTUAL_ENV),,$(POETRY) run)

# pytest
PYTEST ?= $(RUN) $(shell which pytest || echo "pytest")
PYTEST_TARGETS ?= harp harp_apps tests
PYTEST_COMMON_OPTIONS ?= -n auto
PYTEST_COVERAGE_OPTIONS ?= --cov=harp --cov=harp_apps --cov-report html:docs/_build/html/coverage
PYTEST_OPTIONS ?=


# docker
DOCKER ?= $(shell which docker || echo "docker")
DOCKER_IMAGE ?= $(NAME)
DOCKER_IMAGE_DEV ?= $(NAME)-dev
Expand All @@ -14,97 +29,109 @@ DOCKER_BUILD_TARGET ?= runtime
DOCKER_NETWORK ?= harp_default
DOCKER_RUN_COMMAND ?=

POETRY_INSTALL_OPTIONS ?=

# misc.
SED ?= $(shell which gsed || which sed || echo "sed")


########################################################################################################################
# Local development
# Dependencies
########################################################################################################################
.PHONY: install install-dev install-frontend install-backend install-ui reference frontend

install: install-frontend install-backend
.PHONY: install install-dev install-frontend install-backend install-backend-dev

install-dev:
POETRY_INSTALL_OPTIONS="-E dev" $(MAKE) install
install: install-frontend install-backend ## Installs harp dependencies (backend, dashboard) without development tools.

install-dev: ## Installs harp dependencies (backend, dashboard) with development tools.
POETRY_INSTALL_OPTIONS="-E dev" $(MAKE) install

install-frontend: install-ui
install-frontend: ## Installs harp dashboard dependencies (frontend).
cd harp_apps/dashboard/frontend; pnpm install

install-backend:
install-backend: ## Installs harp dependencides (backend).
poetry install $(POETRY_INSTALL_OPTIONS)

install-backend-dev: ## Installs harp dependencies (backend) with development tools.
POETRY_INSTALL_OPTIONS="-E dev" $(MAKE) install


reference: harp
########################################################################################################################
# Documentation
########################################################################################################################

.PHONY: reference

reference: harp ## Generates API reference documentation as ReST files (docs).
rm -rf docs/reference/core docs/reference/apps
mkdir -p docs/reference/core docs/reference/apps
bin/generate_apidoc
$(RUN) bin/generate_apidoc
git add docs/reference/

frontend:

########################################################################################################################
# Dashboard application
########################################################################################################################

.PHONY: frontend-build

frontend-build: ## Builds the harp dashboard frontend (compiles typescript and other sources into bundled version).
cd harp_apps/dashboard/frontend; pnpm build


########################################################################################################################
# QA, tests and other CI/CD related stuff
########################################################################################################################

.PHONY: clean preqa qa qa-full types format format-backend format-frontend test test-backend coverage test-frontend test-frontend-update lint-frontend test-ui test-ui-update test-ui-build
.PHONY: preqa qa qa-full types format format-backend format-frontend
.PHONY: test test-backend test-frontend test-frontend-update
.PHONY: lint-frontend coverage

clean:
(cd docs; $(MAKE) clean)
-rm -rf frontend/dist
-rm -f benchmark_*.svg
preqa: types format reference ## Runs pre-qa checks (types generation, formatting, api reference).

preqa: types format reference
qa: preqa test ## Runs all QA checks, with most common databases.

qa: preqa test test-ui
qa-full:
qa-full: ## Runs all QA checks, including all supported databases.
TEST_ALL_DATABASES=true $(MAKE) qa

types:
bin/generate_types
types: ## Generates frontend types from the python code.
$(RUN) bin/generate_types

format: format-backend format-frontend ## Formats the full codebase (backend and frontend).

format: format-backend format-frontend
format-backend: ## Formats the backend codebase.
$(RUN) isort harp harp_apps tests
$(RUN) black harp harp_apps tests
$(RUN) ruff check --fix harp harp_apps tests

format-frontend: install-frontend
format-frontend: install-frontend ## Formats the frontend codebase.
(cd harp_apps/dashboard/frontend; pnpm lint:fix)
(cd harp_apps/dashboard/frontend; pnpm prettier -w src)

format-backend:
isort harp harp_apps tests
black harp harp_apps tests
ruff check --fix harp harp_apps tests

test:
test: ## Runs all tests.
$(MAKE) test-backend
$(MAKE) test-frontend

test-backend:
$(PYTEST) harp harp_apps tests \
test-backend: install-backend-dev ## Runs backend tests.
$(PYTEST) $(PYTEST_TARGETS) \
--benchmark-disable \
-n auto \
$(PYTEST_OPTIONS)

coverage:
$(PYTEST) harp harp_apps tests \
-m 'not subprocess' \
--cov=harp \
--cov-report html:docs/_build/html/coverage \
-n auto \
$(PYTEST_COMMON_OPTIONS) \
$(PYTEST_OPTIONS)

test-frontend: install-frontend lint-frontend
test-frontend: install-frontend lint-frontend ## Runs frontend tests.
cd harp_apps/dashboard/frontend; pnpm test

test-frontend-update: install-frontend lint-frontend
test-frontend-update: install-frontend lint-frontend ## Runs frontend tests while updating snapshots.
cd harp_apps/dashboard/frontend; pnpm test:unit:update

lint-frontend: install-frontend
lint-frontend: install-frontend ## Lints the frontend codebase.
cd harp_apps/dashboard/frontend; pnpm build

coverage: ## Generates coverage report.
$(PYTEST) $(PYTEST_TARGETS) tests \
-m 'not subprocess' \
$(PYTEST_COVERAGE_OPTIONS) \
$(PYTEST_COMMON_OPTIONS) \
$(PYTEST_OPTIONS)


########################################################################################################################
# Benchmarks
Expand All @@ -115,8 +142,8 @@ lint-frontend: install-frontend
BENCHMARK_OPTIONS ?=
BENCHMARK_MIN_ROUNDS ?= 100

benchmark:
$(PYTEST) harp tests \
benchmark: ## Runs benchmarks.
$(PYTEST) tests/benchmarks \
$(BENCHMARK_OPTIONS) \
--benchmark-enable \
--benchmark-only \
Expand All @@ -127,7 +154,7 @@ benchmark:
--benchmark-histogram \
$(PYTEST_OPTIONS)

benchmark-save:
benchmark-save: ## Runs benchmarks and saves the results.
BENCHMARK_OPTIONS='--benchmark-warmup=on --benchmark-warmup-iterations=50 --benchmark-save="$(shell git describe --tags --always --dirty)"' \
BENCHMARK_MIN_ROUNDS=500 \
$(MAKE) benchmark
Expand All @@ -139,33 +166,55 @@ benchmark-save:

.PHONY: build build-dev push push-dev run run-shell run-example-repositories run-dev run-dev-shell

build:
build: ## Builds the docker image.
# TODO: rm in trap ?
# TODO: document --progress=plain ?
echo $(VERSION) > version.txt
$(DOCKER) build --progress=plain --target=$(DOCKER_BUILD_TARGET) $(DOCKER_BUILD_OPTIONS) -t $(DOCKER_IMAGE) $(foreach tag,$(VERSION) $(DOCKER_TAGS),-t $(DOCKER_IMAGE):$(tag)$(DOCKER_TAGS_SUFFIX)) .
$(DOCKER) build --target=$(DOCKER_BUILD_TARGET) $(DOCKER_BUILD_OPTIONS) -t $(DOCKER_IMAGE) $(foreach tag,$(VERSION) $(DOCKER_TAGS),-t $(DOCKER_IMAGE):$(tag)$(DOCKER_TAGS_SUFFIX)) .
-rm -f version.txt

build-dev:
build-dev: ## Builds the development docker image.
DOCKER_IMAGE=$(DOCKER_IMAGE_DEV) DOCKER_BUILD_TARGET=development $(MAKE) build

push:
push: ## Pushes the docker image to the registry.
for tag in $(VERSION) $(DOCKER_TAGS); do \
$(DOCKER) image push $(DOCKER_IMAGE):$$tag$(DOCKER_TAGS_SUFFIX); \
done

push-dev:
push-dev: ## Pushes the development docker image to the registry.
DOCKER_IMAGE=$(DOCKER_IMAGE_DEV) $(MAKE) push

run:
run: ## Runs the docker image.
$(DOCKER) run -it --network $(DOCKER_NETWORK) -p 4000-4999:4000-4999 --rm $(DOCKER_IMAGE) $(DOCKER_RUN_COMMAND)

run-shell:
run-shell: ## Runs a shell within the docker image.
$(DOCKER) run -it --network $(DOCKER_NETWORK) -p 4080:4080 --rm --entrypoint=/bin/ash $(DOCKER_IMAGE) -l

run-example-repositories:
run-example-repositories: ## Runs harp with the "repositories" example within the docker image.
$(DOCKER) run -it --network $(DOCKER_NETWORK) -p 4080:4080 -p 9001-9012:9001-9012 --rm $(DOCKER_IMAGE) --file examples/repositories.yml --set storage.url postgresql+asyncpg://harp:harp@harp-postgres-1/repositories

run-dev:
run-dev: ## Runs the development docker image.
DOCKER_IMAGE=$(DOCKER_IMAGE_DEV) $(MAKE) run

run-dev-shell:
run-dev-shell: ## Runs a shell within the development docker image.
DOCKER_IMAGE=$(DOCKER_IMAGE_DEV) $(MAKE) run-shell


########################################################################################################################
# Misc. utilities
########################################################################################################################

.PHONY: help clean

help: ## Shows available commands.
@echo "Available commands:"
@echo
@grep -E '^[a-zA-Z_-]+:.*?##[\s]?.*$$' --no-filename $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?##"}; {printf " make \033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo


clean: ## Cleans up the project directory.
(cd docs; $(MAKE) clean)
-rm -rf harp_apps/dashboard/frontend/dist
-rm -f benchmark_*.svg

38 changes: 18 additions & 20 deletions harp_apps/dashboard/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",

"ui:build": "ladle build",
"ui:preview": "ladle build && pnpm ui:serve:prod",
"ui:serve:prod": "ladle preview -p 61110",
Expand All @@ -15,7 +14,6 @@
"test:ui:dev": "cross-env TYPE=dev pnpm exec playwright test -c src/ui/playwright.config.ts",
"test:ui:prod": "cross-env TYPE=prod pnpm exec playwright test -c src/ui/playwright.config.ts",
"test:ui:update": "cross-env TYPE=update pnpm exec playwright test -c src/ui/playwright.config.ts -u",

"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
"preview": "vite preview",
Expand All @@ -32,14 +30,14 @@
},
"dependencies": {
"@bramus/pagination-sequence": "^1.2.1",
"@emotion/react": "^11.11.3",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@headlessui/react": "1.7.17",
"@heroicons/react": "^2.1.1",
"@headlessui/react": "1.7.18",
"@heroicons/react": "^2.1.3",
"@ladle/react": "^4.0.3",
"@sentry/browser": "^7.107.0",
"@sentry/browser": "^7.108.0",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
"@tailwindcss/typography": "^0.5.12",
"date-fns": "^3.6.0",
"http-status-codes": "^2.3.0",
"localforage": "^1.10.0",
Expand All @@ -62,19 +60,19 @@
"@emotion/babel-plugin-jsx-pragmatic": "^0.2.1",
"@playwright/test": "^1.42.1",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/react": "^14.2.2",
"@types/bramus__pagination-sequence": "^1.2.2",
"@types/node": "^20.11.30",
"@types/prismjs": "^1.26.3",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.22",
"@types/react-syntax-highlighter": "^15.5.11",
"@types/sync-fetch": "^0.4.3",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.2.2",
"autoprefixer": "^10.4.16",
"@vitest/coverage-v8": "^1.4.0",
"autoprefixer": "^10.4.19",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-prismjs": "^2.1.0",
"cross-env": "^7.0.3",
Expand All @@ -90,18 +88,18 @@
"eslint-plugin-react-refresh": "^0.4.6",
"jsdom": "^24.0.0",
"json-schema-to-typescript": "^13.1.2",
"msw": "^2.2.9",
"postcss": "^8.4.32",
"msw": "^2.2.13",
"postcss": "^8.4.38",
"prettier": "^3.1.1",
"react-test-renderer": "^18.2.0",
"resize-observer-polyfill": "^1.5.1",
"rollup-plugin-visualizer": "^5.12.0",
"sync-fetch": "^0.5.2",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.3",
"twin.macro": "^3.4.1",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"typescript": "5.4.3",
"vite": "^5.2.6",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.2.2"
"vitest": "^1.4.0"
}
}
1 change: 1 addition & 0 deletions harp_apps/dashboard/frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
timeout: 10000,
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
Expand Down
Loading

0 comments on commit 9057a1e

Please sign in to comment.