From faa1798eb068ac4dd67f1d5e516bc7895be03bf0 Mon Sep 17 00:00:00 2001 From: dwrz Date: Fri, 13 Feb 2026 15:00:31 +0000 Subject: [PATCH] Add build configuration --- .gitignore | 1 + .ignore | 1 + Makefile | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++ biome.json | 47 +++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 .ignore create mode 100644 Makefile create mode 100644 biome.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..48b8bf9 --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +vendor/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9a83fb1 --- /dev/null +++ b/Makefile @@ -0,0 +1,144 @@ +MODULE := github.com/chimerical-llc/odidere +CMDS := $(notdir $(wildcard ./cmd/*)) +BINARIES := $(addprefix bin/,$(CMDS)) + +GO := go +GOFMT := go fmt +GOVET := go vet +GOIMPORTS := go tool goimports +DEADCODE := go tool deadcode +GOVULNCHECK := go tool govulncheck +BIOME := biome + +BUILDFLAGS := -buildvcs=true +PLATFORMS := linux/amd64 + +.PHONY: all build build-all buildinfo check clean deadcode deps fmt help \ + imports install lint run test tidy tools uninstall verify vet \ + vulncheck $(CMDS) + +## Build all binaries (default target) +all: build + +## Display this help screen +help: + @awk ' \ + /^##/ { doc = substr($$0, 4); next } \ + /^[a-zA-Z0-9_-]+:/ && doc { \ + split($$1, target, ":"); \ + printf "\033[36m%-20s\033[0m %s\n", target[1], doc; \ + doc = "" \ + } \ + ' $(MAKEFILE_LIST) + +## Build all binaries to bin/ +build: $(BINARIES) + +## Build binaries for all defined platforms +build-all: + @for cmd in $(CMDS); do \ + for platform in $(PLATFORMS); do \ + echo "Building $$cmd for $$platform..."; \ + out="bin/$$cmd-$${platform%/*}-$${platform#*/}"; \ + GOOS=$${platform%/*} GOARCH=$${platform#*/} \ + $(GO) build $(BUILDFLAGS) -o $$out ./cmd/$$cmd; \ + done; \ + done + +## Build specific binaries (pattern rule) +bin/%: ./cmd/% + $(GO) build $(BUILDFLAGS) -o $@ ./$< + +## Shortcut targets to build specific commands (e.g., 'make admin') +$(CMDS): + $(GO) build $(BUILDFLAGS) -o bin/$@ ./cmd/$@ + +## Show version info for built binaries +buildinfo: build + @for bin in $(BINARIES); do \ + if [ -x $$bin ]; then \ + echo "Info for $$bin:"; \ + $(GO) version -m $$bin || true; \ + fi; \ + done + +## Run tests with race detection and coverage +test: + $(GO) test -cover -race ./... + +## Run all linters (fmt, vet, imports, deadcode, vulncheck) +lint: fmt vet imports deadcode vulncheck biome + +## Format code using go fmt +fmt: + $(GOFMT) ./... + +## Fix imports and format using goimports +imports: + $(GOIMPORTS) -w -local "$(MODULE)" . + +## Run go vet +vet: + $(GOVET) ./... + +## Find dead code +deadcode: + $(DEADCODE) ./... + +## Check for vulnerabilities +vulncheck: + $(GOVULNCHECK) ./... + +## Run integration checks (alias for lint) +check: lint + +## Tidy go.mod dependencies +tidy: + $(GO) mod tidy + +## Download dependencies +deps: + $(GO) mod download + +## Verify dependencies +verify: + $(GO) mod verify + +## Install development tools +tools: + go get -tool golang.org/x/tools/cmd/deadcode@latest + go get -tool golang.org/x/tools/cmd/goimports@latest + go get -tool golang.org/x/vuln/cmd/govulncheck@latest + +## Run the specified CMD binary (use ARGS="..." to pass arguments) +# trap '' INT prevents colorize-logs from exiting immediately on Ctrl-C, +# allowing it to print remaining output before the application terminates. +run: clean bin/$(CMD) + ./bin/$(CMD) $(ARGS) 2>&1 | (trap '' INT; colorize-logs) + +## Clean build artifacts +clean: + $(GO) clean + rm -f bin/* + +## Install binaries to $GOBIN +install: + $(GO) install $(BUILDFLAGS) ./cmd/... + +## Uninstall binaries from $GOBIN +uninstall: + @for cmd in $(CMDS); do \ + path=$$( $(GO) env GOBIN )/$$cmd; \ + if [ -z "$$( $(GO) env GOBIN )" ]; \ + then path=$$( $(GO) env GOPATH )/bin/$$cmd; fi; \ + echo "Removing $$path"; \ + rm -f $$path; \ + done + +## Lint and format JS/CSS with Biome +biome: + $(BIOME) check --write internal/service/static/ + +## Check JS/CSS without writing (for CI) +biome-ci: + $(BIOME) ci internal/service/static/ diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..e8a65db --- /dev/null +++ b/biome.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.3.13/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "assist": { + "actions": { + "source": { + "organizeImports": "on" + } + } + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2, + "lineWidth": 80 + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + "semicolons": "always" + } + }, + "css": { + "formatter": { + "enabled": true + }, + "linter": { + "enabled": true + } + }, + "files": { + "includes": [ + "internal/service/static/**/*.js", + "internal/service/static/**/*.css" + ] + } +}