mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
c9b702d234
Architecture: - Move GetFromContext/SetToContext from plugins/domain/auth to pkg/util - Move auth context key constants to core/contracts (AuthUserObjKey, AuthTokenAuthKey, etc.) - Add AuthUserIDKey, AuthUserNameKey, GetCurrentUserID, RevokeToken to contracts.AuthService - All 4 domain plugin Apply() methods now resolve AuthService via core.Using IoC - Plugin route middleware uses authSvc.RequireAuthMiddleware() cast to gin.HandlerFunc - DisallowTokenAuth added to AuthService contract Migration: - Replace cmd/app.go SetMigrationRunner bridge with gooseEngine implementing core.MigrationEngine - Remove cmd/root.go PreRun migration hooks and runMigrations() function - Migrations now run via core.App.Start() → RunMigrations() Events: - Add complete domain event topic catalog and payload DTOs to core/contracts/events.go - 15 event topics across auth, user, admin, upload, message_gateway, risk_control Downstream: - Create downstream/ directory with README and custom_example plugin scaffold CI: - Update Makefile code-check architecture guards for Cordis layering - Enforce: core no gin/gorm/asynq, contracts no plugins/, pkg no plugins/, domain no cross-domain
178 lines
5.9 KiB
Makefile
178 lines
5.9 KiB
Makefile
.PHONY: swagger license license-check build-embedded build-test cross-build code-check format canary
|
||
|
||
VERSION ?= dev
|
||
BUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||
MODULE := $(shell go list -m)
|
||
|
||
swagger:
|
||
scripts/swagger.sh
|
||
|
||
license:
|
||
scripts/update_go_license.sh
|
||
|
||
license-check:
|
||
scripts/update_go_license.sh --check
|
||
|
||
format:
|
||
@echo "==> Formatting backend Go source..."
|
||
gofmt -w $$(find . -type f -name '*.go' -not -path './.git/*' -not -path './frontend/*')
|
||
@echo "==> Formatting frontend source..."
|
||
cd frontend && pnpm format
|
||
|
||
build-embedded:
|
||
@echo "==> Building embedded frontend version=$(VERSION) build_date=$(BUILD_DATE)..."
|
||
cd frontend && \
|
||
NEXT_PUBLIC_APP_VERSION="$(VERSION)" \
|
||
NEXT_PUBLIC_APP_BUILD_DATE="$(BUILD_DATE)" \
|
||
pnpm build:embed
|
||
rm -rf plugins/drivers/driver_http/dist
|
||
cp -R frontend/out plugins/drivers/driver_http/dist
|
||
go build \
|
||
-tags embed_frontend \
|
||
-ldflags "-s -w -X '$(MODULE)/pkg/buildinfo.Version=$(VERSION)' -X '$(MODULE)/pkg/buildinfo.BuildTime=$(BUILD_DATE)'" \
|
||
-o bin/wavelet \
|
||
main.go
|
||
|
||
code-check:
|
||
@echo "==> Architecture guards..."
|
||
@command -v rg >/dev/null 2>&1 || { echo 'error: rg (ripgrep) is required for architecture guards' >&2; exit 1; }
|
||
@echo " → core/ must not import gin, gorm, asynq..."
|
||
@if rg -n '"github.com/gin-gonic/gin|"gorm.io/gorm|"github.com/hibiken/asynq' core/ --glob '*.go' -g '!*_test.go' 2>/dev/null; then \
|
||
echo 'error: core/ must not import gin, gorm, or asynq' >&2; \
|
||
exit 1; \
|
||
fi
|
||
@echo " → core/contracts/ must not import plugins/..."
|
||
@if rg -n 'plugins/' core/contracts --glob '*.go' 2>/dev/null; then \
|
||
echo 'error: core/contracts/ must not import plugins/' >&2; \
|
||
exit 1; \
|
||
fi
|
||
@echo " → pkg/ must not import plugins/..."
|
||
@if rg -n 'plugins/' pkg --glob '*.go' -g '!*_test.go' 2>/dev/null; then \
|
||
echo 'error: pkg/ must not import plugins/' >&2; \
|
||
exit 1; \
|
||
fi
|
||
@echo " → plugins/domain/ must not import other plugins/domain/..."
|
||
@for d in plugins/domain/*/; do \
|
||
name=$$(basename $$d); \
|
||
imports=$$(rg -n '"github.com/Rain-kl/Wavelet/plugins/domain/' plugins/domain/"$$name" -g '*.go' 2>/dev/null | rg -v "plugins/domain/$$name/" | rg -v '_test.go' || true); \
|
||
if [ -n "$$imports" ]; then \
|
||
echo "error: plugins/domain/$$name must not import other domain plugins" >&2; \
|
||
echo "$$imports" >&2; \
|
||
exit 1; \
|
||
fi; \
|
||
done
|
||
@echo " → Architecture guards PASS"
|
||
golangci-lint run
|
||
cd frontend && pnpm tsc --noEmit --jsx preserve && npx eslint . --max-warnings 0
|
||
|
||
build-backend:
|
||
@echo "==> Building backend version=$(VERSION) build_date=$(BUILD_DATE)..."
|
||
go build \
|
||
-ldflags "-s -w -X '$(MODULE)/pkg/buildinfo.Version=$(VERSION)' -X '$(MODULE)/pkg/buildinfo.BuildTime=$(BUILD_DATE)'" \
|
||
-o bin/wavelet \
|
||
main.go
|
||
|
||
build-frontend:
|
||
@echo "==> Building frontend version=$(VERSION) build_date=$(BUILD_DATE)..."
|
||
cd frontend && \
|
||
NEXT_PUBLIC_APP_VERSION="$(VERSION)" \
|
||
NEXT_PUBLIC_APP_BUILD_DATE="$(BUILD_DATE)" \
|
||
pnpm build:embed
|
||
|
||
build-test:
|
||
@echo "==> Running frontend and backend build tests in parallel..."
|
||
@PIDS=""; \
|
||
STATUS=0; \
|
||
( cd frontend && pnpm build:embed 2>&1 | sed 's/^/[frontend] /' ) & PIDS="$$PIDS $$!"; \
|
||
( go test ./... && go build -o /dev/null ./... 2>&1 | sed 's/^/[backend] /' ) & PIDS="$$PIDS $$!"; \
|
||
for PID in $$PIDS; do \
|
||
wait $$PID || STATUS=1; \
|
||
done; \
|
||
if [ $$STATUS -eq 0 ]; then \
|
||
echo "==> All build tests passed."; \
|
||
else \
|
||
echo "==> Build test FAILED." >&2; \
|
||
exit 1; \
|
||
fi
|
||
|
||
cross-build:
|
||
@echo "==> Cross-compiling \
|
||
$(if $(GOOS),$(GOOS),linux/darwin/windows) × \
|
||
$(if $(GOARCH),$(GOARCH),amd64/arm64) \
|
||
(version=$(or $(VERSION),dev))..."
|
||
@mkdir -p bin
|
||
docker build \
|
||
--file docker/Dockerfile.cross \
|
||
--target export \
|
||
--build-arg VERSION=$(or $(VERSION),dev) \
|
||
--build-arg BUILD_DATE="$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
|
||
$(if $(GOOS),--build-arg TARGET_OS=$(GOOS)) \
|
||
$(if $(GOARCH),--build-arg TARGET_ARCH=$(GOARCH)) \
|
||
--output type=local,dest=./bin \
|
||
.
|
||
@echo "==> Done. Binaries written to ./bin/"
|
||
@ls -lh bin/
|
||
|
||
dev-f:
|
||
@echo "==> Starting frontend development server..."
|
||
cd frontend && pnpm dev
|
||
|
||
dev-b:
|
||
@echo "==> Starting backend development server..."
|
||
go run main.go all
|
||
|
||
dev:
|
||
@echo "==> Starting frontend and backend development servers in parallel..."
|
||
@PIDS=""; \
|
||
STATUS=0; \
|
||
( cd frontend && pnpm dev 2>&1 | sed 's/^/[frontend] /' ) & PIDS="$$PIDS $$!"; \
|
||
( go run main.go all 2>&1 | sed 's/^/[backend] /' ) & PIDS="$$PIDS $$!"; \
|
||
for PID in $$PIDS; do \
|
||
wait $$PID || STATUS=1; \
|
||
done; \
|
||
if [ $$STATUS -eq 0 ]; then \
|
||
echo "==> All development servers exited successfully."; \
|
||
else \
|
||
echo "==> Development servers exited with errors." >&2; \
|
||
exit 1; \
|
||
fi
|
||
|
||
|
||
# Merge the current local branch into canary, push canary, then restore it.
|
||
# Dirty worktrees are auto-stashed and restored after the operation.
|
||
canary:
|
||
@set -e; \
|
||
if ! git rev-parse --git-dir >/dev/null 2>&1; then \
|
||
echo "Error: not a git repository"; exit 1; \
|
||
fi; \
|
||
orig=$$(git rev-parse --abbrev-ref HEAD); \
|
||
if [ "$$orig" = "HEAD" ]; then \
|
||
echo "Error: detached HEAD; checkout a branch first"; exit 1; \
|
||
fi; \
|
||
if [ "$$orig" = "canary" ]; then \
|
||
echo "Error: already on canary; checkout a source branch first"; exit 1; \
|
||
fi; \
|
||
stashed=0; \
|
||
if [ -n "$$(git status --porcelain)" ]; then \
|
||
echo "Working tree is dirty; stashing local changes..."; \
|
||
git stash push -u -m "make canary auto-stash from $$orig"; \
|
||
stashed=1; \
|
||
fi; \
|
||
cleanup() { \
|
||
cur=$$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true); \
|
||
if [ "$$cur" != "$$orig" ]; then \
|
||
echo "Restoring branch $$orig..."; \
|
||
git checkout -q "$$orig"; \
|
||
fi; \
|
||
if [ "$$stashed" = "1" ]; then \
|
||
echo "Restoring stashed local changes..."; \
|
||
git stash pop; \
|
||
fi; \
|
||
}; \
|
||
trap cleanup EXIT; \
|
||
echo "Merging $$orig -> canary..."; \
|
||
git checkout canary; \
|
||
git merge --no-edit "$$orig"; \
|
||
git push -u origin canary; \
|
||
echo "Done: $$orig merged into canary and pushed."
|