Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better makefile #140

Merged
merged 41 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
47a2f32
proper alignment in `Makefile`
Dopplerian Aug 23, 2023
c3ae656
use diesel cli arguments in `Makefile`
Dopplerian Aug 23, 2023
bacca91
fix mistake with diesel cli
Dopplerian Aug 23, 2023
2407278
better organization
Dopplerian Aug 23, 2023
4d22be3
user/password consistency in `Makefile`
Dopplerian Aug 23, 2023
1ae01f7
add `.PHONY` target
Dopplerian Aug 23, 2023
75702dd
move `clippy` target
Dopplerian Aug 23, 2023
150fd44
remove unnecessary environment variables
Dopplerian Aug 23, 2023
eb6464c
fix problem from 4d22be3e5
Dopplerian Aug 23, 2023
dfac909
maybe this is better for users/passwords
Dopplerian Aug 23, 2023
e820335
fix fuck up again
Dopplerian Aug 24, 2023
b18b6f3
better organization and wait for MySQL
Dopplerian Aug 24, 2023
a464fff
format `README.md`
Dopplerian Aug 24, 2023
b475dd0
format `README.md` Rust code
Dopplerian Aug 24, 2023
b609210
update `README.md`
Dopplerian Aug 24, 2023
107bc5d
another probably better approach
Dopplerian Aug 24, 2023
4c43b93
better output
Dopplerian Aug 24, 2023
0b53531
bold echoes
Dopplerian Aug 24, 2023
408f1b6
update `make doc`
Dopplerian Aug 24, 2023
4d7ff7f
use variables in `Makefile`
Dopplerian Aug 24, 2023
0585ad5
use `--migration-dir` for Diesel
Dopplerian Aug 24, 2023
c829c1f
add variables for migrations
Dopplerian Aug 24, 2023
e6704a1
add `fang/mysql_migrations/diesel.toml` and use variables for Diesel …
Dopplerian Aug 24, 2023
94874d9
add default goal
Dopplerian Aug 24, 2023
65ea5d3
add `.env` recipe
Dopplerian Aug 24, 2023
2ed78ce
add variables for URLs of DBs
Dopplerian Aug 24, 2023
af58b65
format `Makefile`
Dopplerian Aug 24, 2023
ced7be2
fix fuck-up in last commit
Dopplerian Aug 24, 2023
18bccd7
setup `Makefile` for parallel execution
Dopplerian Aug 24, 2023
3580bb4
fix workflow
pxp9 Aug 25, 2023
f6d90c3
fix workflow var
pxp9 Aug 25, 2023
85e68cf
move `make` variables into `.env` file
Dopplerian Aug 28, 2023
715494c
add quotation marks for `Makefile` substitution
Dopplerian Aug 29, 2023
bd0faa4
solve race condition in `clean_sqlite`
Dopplerian Aug 29, 2023
078dafb
fix `README.md`
Dopplerian Aug 29, 2023
5051eeb
stupid problems require stupid solutions
Dopplerian Aug 29, 2023
7ad3b07
remove unnecessary clean
Dopplerian Aug 29, 2023
abfd17d
add `sleep`s
Dopplerian Aug 29, 2023
fc1b0c7
add docker image versions as a `.env` and `Makefile` variable
Dopplerian Aug 29, 2023
882dca8
latest databases but without latest
pxp9 Aug 30, 2023
200b9e8
small clarification in `README.md`
Dopplerian Aug 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
DATABASE_URL=postgres://postgres:postgres@localhost/fang
POSTGRES_CONTAINER=postgres
Dopplerian marked this conversation as resolved.
Show resolved Hide resolved
POSTGRES_VERSION=15.4
POSTGRES_DB=fang
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DIESEL_DIR=fang/postgres_migrations
POSTGRES_MIGRATIONS=${POSTGRES_DIESEL_DIR}/migrations
POSTGRES_CONFIG=${POSTGRES_DIESEL_DIR}/diesel.toml

MYSQL_CONTAINER=mysql
MYSQL_VERSION=8.1
MYSQL_DB=fang
MYSQL_USER=root
MYSQL_PASSWORD=mysql
MYSQL_DIESEL_DIR=fang/mysql_migrations
MYSQL_MIGRATIONS=${MYSQL_DIESEL_DIR}/migrations
MYSQL_CONFIG=${MYSQL_DIESEL_DIR}/diesel.toml

SQLITE_FILE=fang.db
SQLITE_DIESEL_DIR=fang/sqlite_migrations
SQLITE_MIGRATIONS=${SQLITE_DIESEL_DIR}/migrations
SQLITE_CONFIG=${SQLITE_DIESEL_DIR}/diesel.toml

HOST=127.0.0.1
POSTGRES_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${HOST}/${POSTGRES_DB}
MYSQL_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${HOST}/${MYSQL_DB}
DATABASE_URL=${POSTGRES_URL}
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
# Check if it works with current dependencies (weekly on Wednesday 2:32 UTC)
- cron: '32 2 * * 3'

env :
DATABASE_URL : postgres://postgres:postgres@localhost/fang
Dopplerian marked this conversation as resolved.
Show resolved Hide resolved

jobs:
test:
name: Test
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
**/target
Cargo.lock
src/schema.rs
docs/content/docs/CHANGELOG.md
docs/content/docs/README.md
fang.db
129 changes: 103 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,123 @@
include .env

BOLD='\033[1m'
END_BOLD='\033[0m'

DB_TARGETS=db_postgres db_mysql db_sqlite
WAIT_TARGETS=wait_for_postgres wait_for_mysql wait_for_sqlite
DIESEL_TARGETS=diesel_postgres diesel_mysql diesel_sqlite
CLEAN_TARGETS=clean_postgres clean_mysql clean_sqlite
STOP_TARGETS=stop_postgres stop_mysql stop_sqlite

.DEFAULT_GOAL=default

default: db tests ignored stop

.PHONY: db $(DB_TARGETS) \
$(WAIT_TARGETS) \
diesel $(DIESEL_TARGETS) \
clean $(CLEAN_TARGETS)
stop $(STOP_TARGETS) \
default clippy tests ignored doc .FORCE

.SILENT: $(DB_TARGETS) $(WAIT_TARGETS) $(DIESEL_TARGETS) $(CLEAN_TARGETS) $(STOP_TARGETS)

.NOTPARALLEL: default

db: $(DB_TARGETS)

db_postgres:
docker run --rm -d --name postgres -p 5432:5432 \
-e POSTGRES_DB=fang \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
postgres:latest
@echo -e $(BOLD)Setting up Postgres database...$(END_BOLD)
docker run --rm -d --name "$(POSTGRES_CONTAINER)" -p 5432:5432 \
-e POSTGRES_DB="$(POSTGRES_DB)" \
-e POSTGRES_USER="$(POSTGRES_USER)" \
-e POSTGRES_PASSWORD="$(POSTGRES_PASSWORD)" \
postgres:"$(POSTGRES_VERSION)"
$(MAKE) diesel_postgres

# login is root fang
db_mysql:
docker run --rm -d --name mysql -p 3306:3306 \
-e MYSQL_DATABASE=fang \
-e MYSQL_ROOT_PASSWORD=fang \
-e TZ=UTC \
mysql:latest
@echo -e $(BOLD)Setting up MySQL database...$(END_BOLD)
docker run --rm -d --name "$(MYSQL_CONTAINER)" -p 3306:3306 \
-e MYSQL_DATABASE="$(MYSQL_DB)" \
-e MYSQL_ROOT_PASSWORD="$(MYSQL_PASSWORD)" \
-e TZ=UTC \
mysql:"$(MYSQL_VERSION)"
$(MAKE) diesel_mysql

db_sqlite:
sqlite3 fang.db "VACUUM;"

clippy:
cargo clippy --verbose --all-targets --all-features -- -D warnings
@echo -e $(BOLD)Setting up SQLite database...$(END_BOLD)
sqlite3 "$(SQLITE_FILE)" "VACUUM;"
$(MAKE) diesel_sqlite

diesel_sqlite:
cd fang/sqlite_migrations && DATABASE_URL=sqlite://../../fang.db diesel migration run
diesel: $(DIESEL_TARGETS)

diesel_postgres:
cd fang/postgres_migrations && DATABASE_URL=postgres://postgres:postgres@localhost/fang diesel migration run
@echo -e $(BOLD)Running Diesel migrations on Postgres database...$(END_BOLD)
while ! diesel migration run --database-url "$(POSTGRES_URL)" --migration-dir "$(POSTGRES_MIGRATIONS)" --config-file "$(POSTGRES_CONFIG)" 2> /dev/null; \
do \
sleep 1; \
done

diesel_mysql:
cd fang/mysql_migrations && DATABASE_URL=mysql://root:fang@127.0.0.1/fang diesel migration run
@echo -e $(BOLD)Running Diesel migrations on MySQL database...$(END_BOLD)
while ! diesel migration run --database-url "$(MYSQL_URL)" --migration-dir "$(MYSQL_MIGRATIONS)" --config-file "$(MYSQL_CONFIG)" 2> /dev/null; \
do \
sleep 1; \
done

diesel_sqlite:
@echo -e $(BOLD)Running Diesel migrations on SQLite database...$(END_BOLD)
while ! diesel migration run --database-url sqlite://"$(SQLITE_FILE)" --migration-dir "$(SQLITE_MIGRATIONS)" --config-file "$(SQLITE_CONFIG)" 2> /dev/null; \
do \
sleep 1; \
done

clean: $(CLEAN_TARGETS)

clean_postgres:
@echo -e $(BOLD)Cleaning Postgres database...$(END_BOLD)
docker exec "$(POSTGRES_CONTAINER)" dropdb -U "$(POSTGRES_USER)" "$(POSTGRES_DB)"
docker exec "$(POSTGRES_CONTAINER)" psql -U "$(POSTGRES_USER)" --command="CREATE DATABASE $(POSTGRES_DB);"
$(MAKE) diesel_postgres

clean_mysql:
@echo -e $(BOLD)Cleaning MySQL database...$(END_BOLD)
docker exec "$(MYSQL_CONTAINER)" mysql \
--user="$(MYSQL_USER)" \
--password="$(MYSQL_PASSWORD)" \
--execute="DROP DATABASE $(MYSQL_DB); CREATE DATABASE $(MYSQL_DB);"
$(MAKE) diesel_mysql

stop_mysql:
docker kill mysql
clean_sqlite:
@echo -e $(BOLD)Cleaning SQLite database...$(END_BOLD)
$(MAKE) stop_sqlite
$(MAKE) db_sqlite

stop: $(STOP_TARGETS)

stop_postgres:
docker kill postgres
@echo -e $(BOLD)Stopping Postgres database...$(END_BOLD)
docker kill "$(POSTGRES_CONTAINER)"

stop_mysql:
@echo -e $(BOLD)Stopping MySQL database...$(END_BOLD)
docker kill "$(MYSQL_CONTAINER)"

stop_sqlite:
rm fang.db
@echo -e $(BOLD)Stopping SQLite database...$(END_BOLD)
rm "$(SQLITE_FILE)"

clippy:
cargo clippy --verbose --all-targets --all-features -- -D warnings

tests:
DATABASE_URL=postgres://postgres:postgres@localhost/fang cargo test --all-features -- --color always --nocapture
@echo -e $(BOLD)Running tests...$(END_BOLD)
cargo test --all-features -- --color always --nocapture

ignored:
DATABASE_URL=postgres://postgres:postgres@localhost/fang cargo test --all-features -- --color always --nocapture --ignored
@echo -e $(BOLD)Running ignored tests...$(END_BOLD)
cargo test --all-features -- --color always --nocapture --ignored
$(MAKE) clean

doc:
cargo doc --open
cargo doc --package fang --open
Loading