Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
286 lines (178 loc) Β· 8.47 KB
/
Copy pathMakefile
File metadata and controls
286 lines (178 loc) Β· 8.47 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# CherryPi: A multi-agent-multi-human self-hosted agency
# Copyright (C) 2026 CherryPi authors <cherrypi.dev>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
build: build_frontend build_docs copy_frontend copy_docs build_backend build_agency
# The flavor is the distribution line, not the branch name:
CHERRYPI_FLAVOR ?=
ifneq ($(strip $(CHERRYPI_FLAVOR)),)
VERSION_FLAVOR := $(strip $(CHERRYPI_FLAVOR))
else ifneq ($(filter $(GITHUB_REF),refs/heads/main refs/tags/v%),)
VERSION_FLAVOR := main
else ifeq ($(GITHUB_REF),refs/heads/dev)
VERSION_FLAVOR := dev
else
VERSION_FLAVOR := $(if $(filter main,$(shell git symbolic-ref --short HEAD 2>/dev/null)),main,dev)
endif
VERSION_TAG := $(shell git describe --tags --exact-match 2>/dev/null)
VERSION_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
VERSION_DIRTY := $(shell git diff --quiet --ignore-submodules 2>/dev/null || echo +dirty)
VERSION ?= $(if $(VERSION_TAG),$(VERSION_TAG)-$(VERSION_FLAVOR),$(VERSION_FLAVOR)) ($(VERSION_SHA)$(VERSION_DIRTY))
AGENCY_LDFLAGS := -X 'cherrypi.vladfaust.com/agency/cmd/agency/buildinfo.Version=$(VERSION)'
AGENT_LDFLAGS := -X 'cherrypi.vladfaust.com/agent/internal/buildinfo.Version=$(VERSION)'
version:
@echo '$(VERSION)'
build_frontend:
cd agency/frontend && make
build_docs:
cd docs-site && npm ci
cd docs-site && npm run build
install_docs:
cd docs-site && npm install
docs: install_docs
cd docs-site && npm run build
docs_dev:
cd docs-site && npm run dev
build_backend:
cd agent && make
build_agency:
cd agency/server && make
codegen:
@set -e; \
(cd shared && buf generate) & buf_pid=$$!; \
(cd agent && sqlc generate) & agent_pid=$$!; \
(cd agency/server && sqlc generate) & server_pid=$$!; \
wait $$buf_pid; wait $$agent_pid; wait $$server_pid; \
(cd agency/server && go run ./internal/store/gen)
copy_frontend:
rm -rf agency/server/cmd/agency/frontenddist/*
touch agency/server/cmd/agency/frontenddist/.gitkeep
cp -r agency/frontend/dist/* agency/server/cmd/agency/frontenddist/
copy_docs:
rm -rf agency/server/cmd/agency/docsdist/*
touch agency/server/cmd/agency/docsdist/.gitkeep
cp -r docs-site/.vitepress/dist/* agency/server/cmd/agency/docsdist/
test: test_backend test_agency test_frontend test_sdk test_docs
test_backend:
cd agent && make test
test_agency:
cd agency/server && make test
test_frontend:
cd agency/frontend && make test
test_sdk:
cd agency/sdk/js && make test
test_docs:
cd docs-site && npm ci
cd docs-site && npm run build
PRETTIER := PRETTIER_EXPERIMENTAL_CLI=1 npx prettier
PRETTIER_CACHE_DIR := $(CURDIR)/.prettier-cache
format_root:
$(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/root.json" --write "*"
format_frontend:
cd agency/frontend && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/frontend.json" --write .
format_backend:
cd agent && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/agent.json" --write . && go fmt ./...
format_agency:
cd agency/server && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/agency.json" --write . && go fmt ./...
format_sdk:
cd agency/sdk/js && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/sdk.json" --write .
format_docs:
$(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/docs.json" --write docs-site
format_dev:
@if [ -d dev ]; then $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/dev.json" --write dev; fi
format_shared:
cd shared && go fmt ./...
format_golines:
@if command -v golangci-lint > /dev/null; then \
cd $(CURDIR)/agent && golangci-lint fmt --config $(CURDIR)/.golangci.yaml; \
cd $(CURDIR)/agency/server && golangci-lint fmt --config $(CURDIR)/.golangci.yaml; \
cd $(CURDIR)/shared && golangci-lint fmt --config $(CURDIR)/.golangci.yaml; \
else \
echo "golangci-lint not found; skipping golines (see TESTING.md#linting)"; \
fi
format: format_root format_frontend format_docs format_dev format_backend format_agency format_sdk format_shared format_golines
format_check: format_check_root format_check_frontend format_check_docs format_check_dev format_check_backend format_check_agency format_check_sdk format_check_shared
format_check_root:
$(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/root.json" --check "*"
format_check_frontend:
cd agency/frontend && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/frontend.json" --check .
format_check_backend:
cd agent && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/agent.json" --check .
@unformatted="$$(cd agent && gofmt -l .)"; \
if [ -n "$$unformatted" ]; then \
echo "gofmt required for:"; echo "$$unformatted"; exit 1; \
fi
format_check_agency:
cd agency/server && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/agency.json" --check .
@unformatted="$$(cd agency/server && gofmt -l .)"; \
if [ -n "$$unformatted" ]; then \
echo "gofmt required for:"; echo "$$unformatted"; exit 1; \
fi
format_check_sdk:
cd agency/sdk/js && $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/sdk.json" --check .
format_check_docs:
$(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/docs.json" --check docs-site
format_check_dev:
@if [ -d dev ]; then $(PRETTIER) --cache-location "$(PRETTIER_CACHE_DIR)/dev.json" --check dev; fi
format_check_shared:
@unformatted="$$(cd shared && gofmt -l .)"; \
if [ -n "$$unformatted" ]; then \
echo "gofmt required for:"; echo "$$unformatted"; exit 1; \
fi
lint: lint_actions lint_shell lint_go
# actionlint also runs shellcheck on inline `run:` blocks when it is on PATH.
lint_actions:
@command -v actionlint > /dev/null || { echo "actionlint not found; see TESTING.md#linting"; exit 1; }
actionlint .gitea/workflows/*.yaml public-overlay/.github/workflows/*.yml
lint_shell:
@command -v shellcheck > /dev/null || { echo "shellcheck not found; see TESTING.md#linting"; exit 1; }
shellcheck .gitea/scripts/*.sh
lint_go:
@command -v golangci-lint > /dev/null || { echo "golangci-lint not found; see TESTING.md#linting"; exit 1; }
cd agent && golangci-lint run --config $(CURDIR)/.golangci.yaml ./...
cd agency/server && golangci-lint run --build-tags dev --config $(CURDIR)/.golangci.yaml ./...
cd shared && golangci-lint run --config $(CURDIR)/.golangci.yaml ./...
docker:
docker buildx build --platform linux/amd64,linux/arm64 --build-arg VERSION='$(VERSION)' -f agency/server/Dockerfile . -t gitea.vladfaust.com/cherrypi/agency
docker buildx build --platform linux/amd64,linux/arm64 --build-arg VERSION='$(VERSION)' -f agent/Dockerfile . -t gitea.vladfaust.com/cherrypi/agent
docker_push: docker
docker push gitea.vladfaust.com/cherrypi/agency
docker push gitea.vladfaust.com/cherrypi/agent
compose:
docker compose up --build
DIST ?= dist
TARGETS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
binaries: build_frontend build_docs copy_frontend copy_docs binaries_build
# docs-site/.vitepress/dist between jobs).
binaries_build:
rm -rf $(DIST) && mkdir -p $(DIST)
@for target in $(TARGETS); do \
os=$${target%/*}; arch=$${target#*/}; \
echo "Building $$os/$$arch"; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -C agency/server -ldflags "$(AGENCY_LDFLAGS)" -o $(abspath $(DIST))/cherrypi-agency-$$os-$$arch ./cmd/agency || exit 1; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -C agent -ldflags "$(AGENT_LDFLAGS)" -o $(abspath $(DIST))/cherrypi-agent-$$os-$$arch ./cmd/agent || exit 1; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -C agency/server -ldflags "$(AGENCY_LDFLAGS)" -o $(abspath $(DIST))/cherrypi-plugin-$$os-$$arch ./cmd/cherrypi-plugin || exit 1; \
done
binaries_zip:
@sha=$$(git rev-parse --short HEAD 2>/dev/null || echo unknown); \
for file in $(DIST)/cherrypi-agency-* $(DIST)/cherrypi-agent-* $(DIST)/cherrypi-plugin-*; do \
[ -f "$$file" ] || continue; \
zip="$$file-$$sha.zip"; \
echo "Packaging $$zip"; \
if command -v zip > /dev/null; then \
zip -q -j -X "$$zip" "$$file" || exit 1; \
else \
python3 -m zipfile -c "$$zip" "$$file" || exit 1; \
fi; \
done