TTime/backend/Makefile

166 lines
3.8 KiB
Makefile
Raw Permalink Normal View History

2024-02-12 12:40:49 +01:00
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOTEST = $(GOCMD) test
GOGET = $(GOCMD) get
# SQLite database filename
DB_FILE = db.sqlite3
2024-03-21 02:26:30 +01:00
PROC_NAME = ttime_server
2024-02-12 12:40:49 +01:00
# Directory containing migration SQL scripts
2024-02-28 10:58:32 +01:00
MIGRATIONS_DIR = internal/database/migrations
SAMPLE_DATA_DIR = internal/database/sample_data
2024-02-12 12:40:49 +01:00
# Build target
build:
2024-03-21 02:26:30 +01:00
$(GOBUILD) -o bin/$(PROC_NAME) main.go
2024-02-12 12:40:49 +01:00
# Run target
run: build
2024-03-21 02:26:30 +01:00
./bin/$(PROC_NAME)
2024-02-12 12:40:49 +01:00
2024-02-20 15:42:45 +01:00
watch: build
2024-02-29 07:29:12 +01:00
watchexec -c -w . -r make run
2024-02-20 15:42:45 +01:00
2024-02-12 12:40:49 +01:00
# Clean target
clean:
$(GOCLEAN)
2024-02-12 13:11:25 +01:00
rm -rf bin
2024-02-12 12:40:49 +01:00
rm -f db.sqlite3
2024-03-14 18:14:28 +01:00
rm -f diagram*
rm -f plantuml.jar
rm -f erd.png
rm -f config.toml
2024-03-29 16:41:55 +01:00
rm -f database.txt
2024-02-12 12:40:49 +01:00
# Test target
test: db.sqlite3
2024-03-02 02:31:20 +01:00
$(GOTEST) ./... -count=1
2024-02-12 12:40:49 +01:00
2024-03-21 02:26:30 +01:00
# Integration test target
.PHONY: itest
itest:
pgrep $(PROC_NAME) && echo "Server already running" && exit 1 || true
make build
./bin/$(PROC_NAME) >/dev/null 2>&1 &
sleep 1 # Adjust if needed
python ../testing/testing.py || pkill $(PROC_NAME)
2024-03-21 02:26:30 +01:00
pkill $(PROC_NAME)
2024-02-12 12:40:49 +01:00
# Get dependencies target
deps:
$(GOGET) -v ./...
# Update dependencies target
update:
$(GOGET) -u -v ./...
$(GOCMD) mod tidy
# Migration target
migrate:
2024-03-08 07:34:26 +01:00
@echo "If this ever fails, run make clean and try again"
2024-02-12 12:40:49 +01:00
@echo "Migrating database $(DB_FILE) using SQL scripts in $(MIGRATIONS_DIR)"
@for file in $(wildcard $(MIGRATIONS_DIR)/*.sql); do \
echo "Applying migration: $$file"; \
sqlite3 $(DB_FILE) < $$file; \
done
sampledata:
@echo "If this ever fails, run make clean and try again"
@echo "Migrating database $(DB_FILE) using SQL scripts in $(SAMPLE_DATA_DIR)"
@for file in $(wildcard $(SAMPLE_DATA_DIR)/*.sql); do \
echo "Applying migration: $$file"; \
sqlite3 $(DB_FILE) < $$file; \
done
# Target added primarily for CI/CD to ensure that the database is created before running tests
db.sqlite3:
make migrate
dbdump:
sqlite3 $(DB_FILE) .dump > database.txt
2024-02-27 07:43:20 +01:00
backup:
2024-02-27 07:45:38 +01:00
mkdir -p backups
sqlite3 $(DB_FILE) .dump | gzip -9 > ./backups/BACKUP_$(DB_FILE)_$(shell date +"%Y-%m-%d_%H:%M:%S").sql.gz
2024-02-27 07:43:20 +01:00
# Restore with:
2024-02-27 07:45:38 +01:00
# gzip -cd BACKUP_FILE.sql.gz | sqlite3 $(DB_FILE)
2024-02-27 07:43:20 +01:00
2024-02-28 10:34:51 +01:00
# Format
fmt:
$(GOCMD) fmt ./...
# Lint
lint:
golangci-lint run ./...
2024-02-28 10:36:36 +01:00
2024-02-12 12:40:49 +01:00
# Default target
default: build
# Generate swagger docs
.PHONY: docs
docs:
swag init -outputTypes go
api: ./docs/swagger.json
rm ../frontend/src/API/GenApi.ts
npx swagger-typescript-api \
--api-class-name GenApi \
--path ./docs/swagger.json \
--output ../frontend/src/API \
--name GenApi.ts \
./docs/swagger.json:
swag init -outputTypes json
.PHONY: docfmt
docfmt:
swag fmt
# Generate ERD
# Requires eralchemy2
2024-03-08 11:25:31 +01:00
.PHONY: erd
erd:
eralchemy2 -i sqlite:///db.sqlite3 -o erd.png
install-swag:
@echo "Installing swag"
@go get -u github.com/swaggo/swag/cmd/swag
# Convenience target to install golangci-lint
install-lint:
@echo "Installing golangci-lint"
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.42.1
2024-03-14 18:14:28 +01:00
# Fetches the latest plantuml.jar and checks its SHA256 hash
plantuml.jar:
curl -sSfL https://github.com/plantuml/plantuml/releases/download/v1.2024.3/plantuml.jar -o plantuml.jar \
&& echo "519a4a7284c6a0357c369e4bb0caf72c4bfbbde851b8c6d6bbdb7af3c01fc82f plantuml.jar" | sha256sum -c
# Generate UML diagrams diagral.png & diagram.svg
.PHONY: uml
uml: plantuml.jar
goplantuml -recursive . > diagram.puml
java -jar plantuml.jar -tpng diagram.puml
java -jar plantuml.jar -tsvg diagram.puml
# Convenience target to install just (requires sudo privileges)
install-just:
@echo "Installing just"
@curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
.PHONY: types
types:
tygo generate
.PHONY: install-golds
install-golds:
go install go101.org/golds@latest
.PHONY: golds
golds:
golds -port 6060 -nouses -plainsrc -wdpkgs-listing=promoted ./...