Skip to content

Commit

Permalink
build: added makefile
Browse files Browse the repository at this point in the history
build: added makefile
  • Loading branch information
sebajax committed Feb 23, 2024
1 parent 7c29430 commit 0e3cc13
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 15 deletions.
74 changes: 74 additions & 0 deletions Makefile
@@ -0,0 +1,74 @@
.PHONY: build-server start-server stop-server live-reload test test-coverage clean-deps format clean-imports lint vet check-shadow lint-format migrate-create migrate-up

# Define variable for migration directory and PostgreSQL URL
MIGRATION_DIR = /migration
POSTGRESQL_URL = your_postgresql_connection_string # Replace with your actual connection string

# Docker tasks
build-server:
docker-compose -p go-vertical-slice-architecture build

start-server:
docker-compose up -d

stop-server:
docker-compose down

# Standalone usage for live reloading
live-reload:
air

# Testing
test:
go test ./...

test-coverage:
go test -cover ./...

# Cleaning, Formatting, Linting, and Vetting
clean-deps:
go mod tidy

format:
go fmt ./...

clean-imports:
goimports -l -w .

lint:
golangci-lint run ./...

vet:
go vet ./...

check-shadow:
shadow ./...

lint-format:
go fmt ./...
go vet ./...
golangci-lint run ./...

# Database Migration
migrate-create:
migrate create -ext sql -dir $(MIGRATIONS_DIR) -seq $(name)

migrate-up:
migrate -database $(POSTGRESQL_URL) -path $(MIGRATIONS_DIR) up

# Usage instructions:
# - To build the server: make build-server
# - To start the server: make start-server
# - To stop the server: make stop-server
# - For live reloading during development: make live-reload
# - To run tests: make test
# - To check test coverage: make test-coverage
# - To clean dependencies: make clean-deps
# - To format code: make format
# - To clean unused imports: make clean-imports
# - To lint code: make lint
# - To vet code: make vet
# - To check for shadowed variables: make check-shadow
# - To lint, format and vet your once: make lint-format
# - To create a migration script (replace your_script_name with the actual name): make migrate-create name=your_script_name
# - To run migration scripts: make migrate-up
33 changes: 18 additions & 15 deletions README.md
Expand Up @@ -258,64 +258,67 @@ https://github.com/sebajax/go-vertical-slice-architecture/blob/eb79ccae805d23b6f

```bash
# Build server
docker-compose -p go-vertical-slice-architecture build
make build-server

# Start server
docker-compose up -d
make start-server

# Stop server
docker-compose down
make stop-server
```

### Standalone usage

```bash
# Live reload
air
make live-reload
```

### Testing

```bash
# To run unit testing
go test
make test

# To run unit testing coverage
go test -cover ./...
make test-coverage
```

### Formatting, Linting and Vetting

```bash
# Clean dependencies
go mod tidy
make clean-deps

# Run formating
go fmt ./...
make format

# Remove unused imports
goimports -l -w .
make clean-imports

# Run linting
golangci-lint run ./...
make lint

# Run vetting
go vet ./...
make vet

# Run shadow to check shadowed variables
# Install shadow
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
# Run shadow
shadow ./...
make check-shadow

# Run vetting to lint, format and vet your once
make lint-format
```

### Database migration script

```bash
# Create the script
migrate create -ext sql -dir /migrations -seq [script_name]
# Create the script (replace your_script_name with the actual name)
make migrate-create name=your_script_name
# Run the script
migrate -database ${POSTGRESQL_URL} -path /migrations up
make migrate-up

# It will run automatically when the database initializes
```
Expand Down

0 comments on commit 0e3cc13

Please sign in to comment.