6119
My
mysis / files
mysis / Makefile
1.7 KB
1.PHONY: fmt build run test lint install clean backup-credentials 2 3VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") 4LDFLAGS := -ldflags "-X main.Version=$(VERSION)" 5DB_PATH ?= $(HOME)/.config/mysis/mysis.db 6CREDENTIALS_BACKUP ?= credentials-backup-$(shell date +%Y%m%d-%H%M%S).sql 7 8fmt: 9 go fmt ./... 10 11build: 12 go build $(LDFLAGS) -o bin/mysis ./cmd/mysis 13 14run: build 15 ./bin/mysis 16 17install: build 18 mkdir -p $(HOME)/.mysis/bin 19 cp bin/mysis $(HOME)/.mysis/bin/mysis 20 21test: 22 go test -race -timeout=60s -coverprofile=coverage.out ./internal/** 23 go tool cover -func=coverage.out 24 @echo "" 25 @echo "package coverage:" 26 @go tool cover -func=coverage.out | grep "^total:" 27 28lint: 29 @if ! command -v golangci-lint >/dev/null 2>&1; then \ 30 echo "Installing golangci-lint..."; \ 31 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest; \ 32 fi 33 $$(go env GOPATH)/bin/golangci-lint run ./... 34 35clean: 36 rm -rf bin/ coverage.out 37 38backup-credentials: 39 @echo "Backing up credentials from $(DB_PATH)..." 40 @if [ ! -f "$(DB_PATH)" ]; then \ 41 echo "Error: Database not found at $(DB_PATH)"; \ 42 exit 1; \ 43 fi 44 @sqlite3 "$(DB_PATH)" "SELECT 'INSERT INTO session_credentials VALUES(' || quote(session_id) || ',' || quote(username) || ',' || quote(password) || ',' || quote(created_at) || ',' || quote(updated_at) || ');' FROM session_credentials;" > "$(CREDENTIALS_BACKUP)" 45 @echo "Credentials backed up to $(CREDENTIALS_BACKUP)" 46 @echo "" 47 @echo "Backup contains $(shell wc -l < $(CREDENTIALS_BACKUP)) credential(s)" 48 @echo "" 49 @echo "To restore (merge into existing table):" 50 @echo " sqlite3 $(DB_PATH) < $(CREDENTIALS_BACKUP)"