2023-06-26 08:29:03 +00:00
|
|
|
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2021-12-02 08:55:29 +00:00
|
|
|
BUNDLE = static/cache/bundle
|
|
|
|
OPENAPI = docs/openapi
|
|
|
|
CLEAN_UP = $(BUNDLE) src/cache_buster_data.json assets
|
|
|
|
|
2023-06-27 09:44:08 +00:00
|
|
|
define deploy_dependencies ## deploy dependencies
|
2023-06-28 06:29:26 +00:00
|
|
|
@-docker create --name ${db} \
|
2023-06-27 09:44:08 +00:00
|
|
|
-e POSTGRES_PASSWORD=password \
|
|
|
|
-p 5432:5432 \
|
|
|
|
postgres
|
2023-06-28 06:29:26 +00:00
|
|
|
@-docker create \
|
2023-06-27 09:44:08 +00:00
|
|
|
-p 3306:3306 \
|
|
|
|
--name ${mdb} \
|
|
|
|
--env MARIADB_USER=maria \
|
|
|
|
--env MARIADB_PASSWORD=password \
|
|
|
|
--env MARIADB_ROOT_PASSWORD=password \
|
|
|
|
--env MARIADB_DATABASE=maria \
|
|
|
|
mariadb:latest
|
2023-06-28 06:29:26 +00:00
|
|
|
@-docker create \
|
2023-06-27 09:44:08 +00:00
|
|
|
-p 6379:6379 \
|
|
|
|
--name mcaptcha-cache \
|
|
|
|
mcaptcha/cache:latest
|
|
|
|
docker start ${db}
|
|
|
|
docker start ${mdb}
|
|
|
|
docker start mcaptcha-cache
|
|
|
|
endef
|
|
|
|
|
|
|
|
define run_migrations ## run database migrations
|
|
|
|
cd db/db-migrations/ && cargo run
|
|
|
|
endef
|
|
|
|
|
2023-06-27 14:16:54 +00:00
|
|
|
define run_dev_migrations ## run database migrations
|
|
|
|
cd db/db-sqlx-maria/ && \
|
2023-10-14 21:06:07 +00:00
|
|
|
DATABASE_URL=${MARIA_DATABASE_URL} sqlx migrate run cd db/db-sqlx-postgres/ && \
|
2023-06-27 14:16:54 +00:00
|
|
|
DATABASE_URL=${POSTGRES_DATABASE_URL} sqlx migrate run
|
|
|
|
endef
|
|
|
|
|
2021-12-16 10:25:46 +00:00
|
|
|
define frontend_env ## install frontend deps
|
|
|
|
yarn install
|
|
|
|
cd docs/openapi && yarn install
|
|
|
|
endef
|
|
|
|
|
2022-05-14 10:30:22 +00:00
|
|
|
define cache_bust ## run cache_busting program
|
|
|
|
cd utils/cache-bust && cargo run
|
|
|
|
endef
|
|
|
|
|
2023-06-30 01:58:13 +00:00
|
|
|
|
|
|
|
define test_frontend ## run frontend tests
|
|
|
|
yarn test
|
2023-07-03 14:00:55 +00:00
|
|
|
# cd $(OPENAPI)&& yarn test
|
2023-06-30 01:58:13 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
define test_db_sqlx_postgres
|
|
|
|
cd db/db-sqlx-postgres &&\
|
|
|
|
DATABASE_URL=${POSTGRES_DATABASE_URL}\
|
|
|
|
cargo test --no-fail-fast
|
|
|
|
endef
|
|
|
|
|
|
|
|
define test_db_sqlx_maria
|
|
|
|
cd db/db-sqlx-maria &&\
|
|
|
|
DATABASE_URL=${MARIA_DATABASE_URL}\
|
|
|
|
cargo test --no-fail-fast
|
|
|
|
endef
|
|
|
|
|
|
|
|
define test_core
|
2023-10-14 21:06:07 +00:00
|
|
|
cargo test --no-fail-fast --jobs=4
|
2023-06-30 01:58:13 +00:00
|
|
|
endef
|
|
|
|
|
2021-11-29 12:02:33 +00:00
|
|
|
default: frontend ## Build app in debug mode
|
2022-05-27 13:22:41 +00:00
|
|
|
$(call cache_bust)
|
2021-11-29 12:02:33 +00:00
|
|
|
cargo build
|
2021-04-08 10:19:55 +00:00
|
|
|
|
2022-05-08 14:32:48 +00:00
|
|
|
check: ## Check for syntax errors on all workspaces
|
|
|
|
cargo check --workspace --tests --all-features
|
2022-05-14 10:30:22 +00:00
|
|
|
cd utils/cache-bust && cargo check --tests --all-features
|
2022-05-08 14:32:48 +00:00
|
|
|
cd db/db-migrations && cargo check --tests --all-features
|
|
|
|
cd db/db-sqlx-postgres &&\
|
|
|
|
DATABASE_URL=${POSTGRES_DATABASE_URL}\
|
|
|
|
cargo check
|
2022-07-20 12:12:12 +00:00
|
|
|
cd db/db-sqlx-maria &&\
|
|
|
|
DATABASE_URL=${MARIA_DATABASE_URL}\
|
|
|
|
cargo check
|
2022-05-08 14:32:48 +00:00
|
|
|
cd db/db-core/ && cargo check
|
|
|
|
|
2022-05-14 10:30:22 +00:00
|
|
|
cache-bust: ## Run cache buster on static assets
|
|
|
|
$(call cache_bust)
|
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
clean: ## Delete build artifacts
|
2021-07-15 09:57:01 +00:00
|
|
|
@cargo clean
|
|
|
|
@yarn cache clean
|
2021-12-02 08:55:29 +00:00
|
|
|
@-rm $(CLEAN_UP)
|
2021-07-07 15:40:15 +00:00
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
doc: ## Generate documentation
|
2021-07-06 18:58:32 +00:00
|
|
|
#yarn doc
|
2021-04-08 10:19:55 +00:00
|
|
|
cargo doc --no-deps --workspace --all-features
|
2021-04-09 09:33:50 +00:00
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
docker: ## Build Docker image
|
2021-07-07 15:40:15 +00:00
|
|
|
docker build -t mcaptcha/mcaptcha:master -t mcaptcha/mcaptcha:latest .
|
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
docker-publish: docker ## Build and publish Docker image
|
2021-07-07 15:40:15 +00:00
|
|
|
docker push mcaptcha/mcaptcha:master
|
|
|
|
docker push mcaptcha/mcaptcha:latest
|
|
|
|
|
2021-10-08 13:24:10 +00:00
|
|
|
env: ## Setup development environtment
|
|
|
|
cargo fetch
|
2021-12-16 10:25:46 +00:00
|
|
|
$(call frontend_env)
|
|
|
|
|
2023-06-27 09:44:08 +00:00
|
|
|
env.db: ## Deploy dependencies
|
|
|
|
$(call deploy_dependencies)
|
|
|
|
sleep 5
|
|
|
|
$(call run_migrations)
|
|
|
|
|
|
|
|
env.db.recreate: ## Deploy dependencies from scratch
|
|
|
|
@-docker rm -f ${db}
|
|
|
|
@-docker rm -f ${mdb}
|
|
|
|
@-docker rm -f mcaptcha-cache
|
|
|
|
$(call deploy_dependencies)
|
|
|
|
sleep 5
|
|
|
|
$(call run_migrations)
|
|
|
|
|
2021-12-16 10:25:46 +00:00
|
|
|
frontend-env: ## Install frontend deps
|
|
|
|
$(call frontend_env)
|
2021-10-08 13:24:10 +00:00
|
|
|
|
2021-12-16 10:25:46 +00:00
|
|
|
frontend: ## Build frontend
|
|
|
|
$(call frontend_env)
|
2021-12-02 08:55:29 +00:00
|
|
|
cd $(OPENAPI) && yarn build
|
2021-07-06 18:58:32 +00:00
|
|
|
yarn install
|
2021-12-02 08:55:29 +00:00
|
|
|
@-rm -rf $(BUNDLE)
|
|
|
|
@-mkdir $(BUNDLE)
|
2021-04-09 08:51:43 +00:00
|
|
|
yarn build
|
2022-05-07 14:12:49 +00:00
|
|
|
@yarn run sass -s \
|
2021-12-10 00:46:03 +00:00
|
|
|
compressed templates/main.scss \
|
|
|
|
./static/cache/bundle/css/main.css
|
2022-05-07 14:12:49 +00:00
|
|
|
@yarn run sass -s \
|
2021-12-10 00:46:03 +00:00
|
|
|
compressed templates/mobile.scss \
|
|
|
|
./static/cache/bundle/css/mobile.css
|
2022-05-07 14:12:49 +00:00
|
|
|
@yarn run sass -s \
|
2021-12-10 00:46:03 +00:00
|
|
|
compressed templates/widget/main.scss \
|
|
|
|
./static/cache/bundle/css/widget.css
|
2021-11-30 13:15:02 +00:00
|
|
|
@./scripts/librejs.sh
|
2021-12-02 08:55:29 +00:00
|
|
|
@./scripts/cachebust.sh
|
2021-04-08 10:19:55 +00:00
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
lint: ## Lint codebase
|
2021-10-08 10:25:53 +00:00
|
|
|
cargo fmt -v --all -- --emit files
|
|
|
|
cargo clippy --workspace --tests --all-features
|
|
|
|
yarn lint
|
2023-07-03 14:00:55 +00:00
|
|
|
#cd $(OPENAPI)&& yarn test
|
2021-10-08 10:25:53 +00:00
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
migrate: ## Run database migrations
|
2023-06-27 09:44:08 +00:00
|
|
|
$(call run_migrations)
|
2021-04-08 10:19:55 +00:00
|
|
|
|
2023-06-27 14:16:54 +00:00
|
|
|
migrate.dev: ## Run database migrations during development
|
|
|
|
$(call run_dev_migrations)
|
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
release: frontend ## Build app with release optimizations
|
2022-05-14 10:30:22 +00:00
|
|
|
$(call cache_bust)
|
2021-04-08 10:19:55 +00:00
|
|
|
cargo build --release
|
|
|
|
|
2021-11-29 12:02:33 +00:00
|
|
|
run: frontend ## Run app in debug mode
|
2022-07-22 19:18:05 +00:00
|
|
|
$(call cache_bust)
|
2021-11-29 12:02:33 +00:00
|
|
|
cargo run
|
|
|
|
|
2022-05-11 07:57:42 +00:00
|
|
|
|
2023-06-30 01:58:13 +00:00
|
|
|
db.sqlx.offline: ## prepare sqlx offline data
|
2022-05-27 13:22:41 +00:00
|
|
|
cd db/db-sqlx-postgres && cargo sqlx prepare \
|
|
|
|
--database-url=${POSTGRES_DATABASE_URL} -- \
|
|
|
|
--all-features
|
2022-07-20 12:12:12 +00:00
|
|
|
cd db/db-sqlx-maria && cargo sqlx prepare \
|
|
|
|
--database-url=${MARIA_DATABASE_URL} -- \
|
|
|
|
--all-features
|
2022-05-11 07:57:42 +00:00
|
|
|
|
2023-06-30 01:58:13 +00:00
|
|
|
test: frontend ## Run all available tests
|
|
|
|
$(call test_frontend)
|
2022-05-14 10:30:22 +00:00
|
|
|
$(call cache_bust)
|
2023-06-30 01:58:13 +00:00
|
|
|
$(call test_db_sqlx_postgres)
|
|
|
|
$(call test_db_sqlx_maria)
|
|
|
|
$(call test_core)
|
2022-05-14 07:25:56 +00:00
|
|
|
# ./scripts/tests.sh
|
2021-07-04 20:52:02 +00:00
|
|
|
|
2023-06-30 02:25:53 +00:00
|
|
|
test.cov.html: migrate ## Generate code coverage report in HTML format
|
|
|
|
$(call cache_bust)
|
|
|
|
cargo tarpaulin -t 1200 --out Html
|
|
|
|
|
|
|
|
test.cov.xml: migrate ## Generate code coverage report in XML format
|
|
|
|
$(call cache_bust)
|
|
|
|
cargo tarpaulin -t 1200 --out Xml
|
|
|
|
|
|
|
|
|
2023-06-30 01:58:13 +00:00
|
|
|
test.core: ## Run all core tests
|
|
|
|
$(call test_core)
|
|
|
|
|
|
|
|
test.db: ## Run all database driver tests
|
|
|
|
$(call test_db_sqlx_postgres)
|
|
|
|
$(call test_db_sqlx_maria)
|
|
|
|
|
|
|
|
test.db.pg: ## Run Postgres database driver tests
|
|
|
|
$(call test_db_sqlx_postgres)
|
|
|
|
|
|
|
|
test.db.maria: ## Run Maria database driver tests
|
|
|
|
$(call test_db_sqlx_maria)
|
|
|
|
|
2023-06-30 02:25:53 +00:00
|
|
|
test.frontend: ## Run frontend tests
|
|
|
|
$(call test_frontend)
|
2023-06-30 01:58:13 +00:00
|
|
|
|
2023-04-30 14:47:51 +00:00
|
|
|
test.integration: ## run integration tests with nightwatch.js
|
|
|
|
./scripts/integration.sh
|
|
|
|
|
2021-10-08 10:32:35 +00:00
|
|
|
help: ## Prints help for targets with comments
|
2023-06-30 01:58:13 +00:00
|
|
|
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-].+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|