Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (155 loc) · 7.07 KB
/
Copy pathMakefile
File metadata and controls
198 lines (155 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
.PHONY: peers test test-race cover cover-html test-uncovered lint vuln fmt generate outdated db-up db-down db-reset \
seed dev dev-watch demo n8n n8n-down n8n-node n8n-node-local runbook s3-up s3-down test-s3 \
e2e e2e-build e2e-serve e2e-db-reset e2e-seed e2e-reset
COVERPKGS = $(shell go list ./... | grep -v -e /internal/postgres/db -e /internal/testdb -e /internal/graphroot -e '/alphone/graph$$' -e '/alphone/graph/model$$')
UNCOVEREDPKGS = $(filter-out $(COVERPKGS),$(shell go list ./...))
test:
go test ./...
test-race:
go test -race ./...
peers:
pnpm peers check
lint:
golangci-lint run
go run ./cmd/doclint
vuln:
GOWORK=off go tool govulncheck ./...
fmt:
golangci-lint fmt
generate:
go run ./cmd/pluginwire
GOWORK=off go tool sqlc generate
GOWORK=off go tool gqlgen generate
go run ./cmd/schemagen
pnpm exec graphql-codegen --config codegen.ts
pot:
pnpm --filter @alphone/frontend exec node scripts/write-pot.ts
catalogs:
pnpm --filter @alphone/frontend exec node scripts/write-catalogs.ts
translations: pot
cd frontend && node --env-file-if-exists=$(CURDIR)/.env scripts/sync-translations.ts
translations-push: pot
cd frontend && node --env-file-if-exists=$(CURDIR)/.env scripts/push-translations.ts
translations-retire: pot
cd frontend && node --env-file-if-exists=$(CURDIR)/.env scripts/retire-translations.ts
outdated:
@echo "=== direct Go modules with updates ==="
@go list -m -u -f '{{if and (not .Indirect) .Update}} {{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' all 2>/dev/null | grep . || echo " (all current)"
@echo "=== npm packages with updates (workspace) ==="
@pnpm -r outdated 2>/dev/null || true
@echo "=== go tool dependencies (versioned in go.mod) ==="
@go list -m -u -f '{{if .Update}} {{.Path}}: {{.Version}} -> {{.Update.Version}}{{else}} {{.Path}}: {{.Version}} (current){{end}}' \
$$(sed -n '/^tool (/,/^)/p' go.mod | grep -v '^tool\|^)' | tr -d '\t ' \
| xargs -r -n1 go list -f '{{.Module.Path}}' 2>/dev/null | sort -u) 2>/dev/null || true
@echo "=== pinned tools to review by hand ==="
@echo " go directive / installed: $$(sed -n 's/^go //p' go.mod) / $$(go env GOVERSION)"
@echo " also: golangci-lint-action + setup-go + pnpm packageManager,"
@echo " the postgres docker image, and @wordpress/* (curated vs CHANGELOG)"
db-up:
docker compose up -d --wait
db-down:
docker compose down
db-reset: db-up
printf '%s\n' \
"SELECT format('DROP SCHEMA %I CASCADE', nspname) FROM pg_namespace" \
"WHERE nspname IN ('core', 'auth', 'gonsole', 'storage') OR nspname LIKE 'plugin\_%' \gexec" \
"DROP TABLE IF EXISTS public.goose_db_version;" | \
docker compose exec -T postgres psql -U postgres -d postgres -v ON_ERROR_STOP=1
$(MAKE) seed
n8n:
docker compose --profile n8n up -d --wait n8n
@echo "n8n at http://localhost:5678"
n8n-down:
docker compose --profile n8n down n8n
S3_TEST_ENV = ALPHONE_TEST_S3_ENDPOINT=http://127.0.0.1:3900 ALPHONE_TEST_S3_REGION=garage \
ALPHONE_TEST_S3_BUCKET=test-files ALPHONE_TEST_S3_ACCESS_KEY_ID=GK0123456789abcdef01234567 \
ALPHONE_TEST_S3_SECRET_ACCESS_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
s3-up:
docker compose --profile s3 up -d garage
$(S3_TEST_ENV) bash test/s3/garage.sh "$$(docker compose --profile s3 ps -q garage)"
s3-down:
docker compose --profile s3 down garage
test-s3: s3-up
$(S3_TEST_ENV) go test -race -count=1 -short -timeout 5m -tags s3 ./internal/storage/...
N8N_NODE ?= n8n-nodes-alphone
n8n-node:
docker compose exec -T n8n sh -c 'cd /home/node/.n8n/nodes && npm uninstall $(N8N_NODE) || true'
docker compose exec -T n8n sh -c 'cd /home/node/.n8n/nodes && npm install $(N8N_NODE)@latest'
docker compose --profile n8n restart n8n
@docker compose exec -T n8n sh -c 'cd /home/node/.n8n/nodes && npm ls $(N8N_NODE)' || true
N8N_NODE_DIR ?= ../n8n-nodes-alphone
n8n-node-local:
cd $(N8N_NODE_DIR) && npx n8n-node build && npm pack
docker compose cp $(N8N_NODE_DIR)/$(N8N_NODE)-*.tgz n8n:/tmp/node.tgz
docker compose exec -T n8n sh -c 'cd /home/node/.n8n/nodes && npm install /tmp/node.tgz'
docker compose --profile n8n restart n8n
@docker compose exec -T n8n sh -c \
'grep -c "api/graphql" /home/node/.n8n/nodes/node_modules/$(N8N_NODE)/dist/nodes/AlphOne/graph.js' \
&& echo "the graph build is installed" || echo "the graph build is NOT installed"
runbook:
@test -n "$(ALPHONE_TOKEN)" || \
(echo "set ALPHONE_TOKEN, mint one with: ./alphone token:create -email you@example.com -name runbook" && false)
node test/runbook/run.ts
seed: db-up
go run ./cmd/alphone seed -yes
dev: db-up
go run ./cmd/alphone serve
dev-watch: db-up
GOWORK=off go tool air
demo: db-up e2e-build
ALPHONE_WEB_DIR=frontend/dist ./alphone serve
COVERDATA = .covdata
GOTESTFLAGS ?=
cover:
rm -rf $(COVERDATA)
mkdir -p $(COVERDATA)/bin $(COVERDATA)/counters
go build -cover -covermode=atomic -coverpkg=./cmd/... -o $(COVERDATA)/bin ./cmd/alphone ./cmd/doclint ./cmd/pluginwire ./cmd/schemagen
ALPHONE_COVER_BINDIR=$(CURDIR)/$(COVERDATA)/bin \
ALPHONE_COVER_GOCOVERDIR=$(CURDIR)/$(COVERDATA)/counters \
go test $(GOTESTFLAGS) -cover -covermode=atomic $(COVERPKGS) -args -test.gocoverdir=$(CURDIR)/$(COVERDATA)/counters
@echo "=== merged unit + binary coverage ==="
go tool covdata percent -i=$(COVERDATA)/counters
@go tool covdata textfmt -i=$(COVERDATA)/counters -o $(COVERDATA)/cover.out
@go tool cover -func=$(COVERDATA)/cover.out | tail -1
cover-html: cover
go tool cover -html=$(COVERDATA)/cover.out
test-uncovered:
go test $(GOTESTFLAGS) $(UNCOVEREDPKGS)
E2E_DB ?= alphone_e2e
E2E_DATABASE_URL ?= postgres://postgres:alphone@localhost:5433/$(E2E_DB)?sslmode=disable
E2E_EMAIL ?= e2e@example.com
E2E_NAME ?= Grace Hopper
E2E_PASSWORD ?= correct horse battery
E2E_ROLE ?= admin
E2E_TENANT_MACHINE_GRACE ?= 0s
E2E_SMTP_PORT ?= 4792
E2E_PUBLIC_URL ?= http://localhost:8080
E2E_WEBHOOK_ALLOWED_HOSTS ?= 127.0.0.1/32
E2E_ENCRYPTION_KEY ?= e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0e2e0
e2e-build:
pnpm --filter @alphone/frontend build
go build -o alphone ./cmd/alphone
e2e-serve: db-up e2e-build
set -a && $(foreach file,$(wildcard plugins/*/e2e.env enterprise/*/e2e.env),. ./$(file) && )set +a && \
ALPHONE_WEB_DIR=frontend/dist ALPHONE_DATABASE_URL="$(E2E_DATABASE_URL)" \
ALPHONE_TENANT_MACHINE_GRACE="$(E2E_TENANT_MACHINE_GRACE)" \
ALPHONE_SMTP_HOST=127.0.0.1 \
ALPHONE_SMTP_PORT="$(E2E_SMTP_PORT)" \
ALPHONE_SMTP_FROM=crm@example.com \
ALPHONE_SMTP_TLS=none \
ALPHONE_PUBLIC_URL="$(E2E_PUBLIC_URL)" \
ALPHONE_WEBHOOK_ALLOWED_HOSTS="$(E2E_WEBHOOK_ALLOWED_HOSTS)" \
ALPHONE_ENCRYPTION_KEY="$(E2E_ENCRYPTION_KEY)" \
./alphone serve
e2e-db-reset: db-up
docker compose exec -T postgres psql -U postgres -v ON_ERROR_STOP=1 \
-c "DROP DATABASE IF EXISTS $(E2E_DB) WITH (FORCE)" \
-c "CREATE DATABASE $(E2E_DB)"
e2e-seed: db-up e2e-build
printf '%s\n' "$(E2E_PASSWORD)" | \
ALPHONE_DATABASE_URL="$(E2E_DATABASE_URL)" ./alphone account:create-admin \
-email "$(E2E_EMAIL)" -name "$(E2E_NAME)" -role "$(E2E_ROLE)"
e2e-reset: e2e-db-reset e2e-seed
e2e: e2e-reset
ALPHONE_E2E_DATABASE_URL="$(E2E_DATABASE_URL)" \
pnpm --filter @alphone/e2e exec playwright test