-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (192 loc) · 7 KB
/
Copy pathMakefile
File metadata and controls
238 lines (192 loc) · 7 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
GIT_REF ?= $(shell git symbolic-ref HEAD)
GIT_REF_NAME ?= $(shell git branch --show-current)
GIT_REF_TYPE ?= branch
GIT_COMMIT ?= $(shell git rev-parse HEAD)
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
WT_OUTPUT_FILE ?= tmp/workout-tracker
WT_DEBUG_OUTPUT_FILE ?= tmp/wt-debug
THEME_SCREENSHOT_WIDTH ?= 1200
THEME_SCREENSHOT_HEIGHT ?= 900
TEMPL_PROXY_PORT = 8090
TEMPL_APP_PORT = 8080
TEMPL_COMMAND ?= go tool templ
GO_TEST = go test -short -count 1 -mod vendor -covermode=atomic
BRANCH_NAME_DEPS ?= update-deps
.PHONY: all clean test build screenshots meta install-deps
all: clean install-deps test build
release-patch release-minor release-major:
$(MAKE) release VERSION=$(shell go tool git-semver -target $(subst release-,,$@))
release:
git tag -s -a $(VERSION) -m "Release $(VERSION)"
@echo "Now run:"
@echo "- git push --tags"
@echo "- gh release create --generate-notes $(VERSION)"
install-deps:
cd frontend && npm install
clean:
rm -fv ./assets/output.css ./workout-tracker
rm -rf ./tmp/ ./node_modules/ ./assets/dist/
watch/templ:
$(TEMPL_COMMAND) generate --watch \
--include-version=false \
--open-browser=false \
--proxy="http://localhost:$(TEMPL_APP_PORT)" \
--proxyport="$(TEMPL_PROXY_PORT)" \
--proxybind="0.0.0.0"
watch/server:
go tool air \
--build.full_bin "APP_ENV=development WT_COMPRESS=0 $(WT_OUTPUT_FILE)" \
--build.cmd "make build-server notify-proxy" \
--build.delay 1000 \
--build.exclude_dir "assets,docs,testdata,tmp,vendor" \
--build.exclude_regex "_test.go" \
--build.exclude_unchanged false \
--build.include_ext "go,html,json,yaml" \
--build.stop_on_error true \
--screen.clear_on_rebuild false
watch/tailwind:
cd frontend && npm run watch:tw
notify-proxy:
$(TEMPL_COMMAND) generate \
--include-version=false \
--notify-proxy --proxyport=$(TEMPL_PROXY_PORT)
dev-backend:
$(MAKE) watch/templ &
$(MAKE) watch/server
dev:
echo "DEPRECATED: Use 'make dev-docker' instead"
$(MAKE) watch/templ &
$(MAKE) watch/server &
$(MAKE) watch/tailwind &
sleep infinity
dev-docker: dev-docker-postgres
dev-docker-postgres: go-vendor
docker compose \
--project-directory ./docker/ \
--profile dev-postgres \
up --build
dev-docker-sqlite: go-vendor
docker compose \
--project-directory ./docker/ \
--profile dev-sqlite \
up --build
dev-docker-clean:
docker compose --project-directory ./docker/ \
--profile dev-sqlite \
--profile dev-postgres \
down --remove-orphans --volumes
build: build-frontend build-templates build-server build-docker screenshots
meta: swagger screenshots changelog
build-cli:
go build \
-ldflags "-X 'main.buildTime=$(BUILD_TIME)' -X 'main.gitCommit=$(GIT_COMMIT)' -X 'main.gitRef=$(GIT_REF)' -X 'main.gitRefName=$(GIT_REF_NAME)' -X 'main.gitRefType=$(GIT_REF_TYPE)'" \
-o $(WT_DEBUG_OUTPUT_FILE) ./cmd/wt-debug/
build-server:
go build \
-ldflags "-X 'main.buildTime=$(BUILD_TIME)' -X 'main.gitCommit=$(GIT_COMMIT)' -X 'main.gitRef=$(GIT_REF)' -X 'main.gitRefName=$(GIT_REF_NAME)' -X 'main.gitRefType=$(GIT_REF_TYPE)'" \
-o $(WT_OUTPUT_FILE) ./cmd/workout-tracker/
build-docker:
docker build \
--tag workout-tracker --pull \
--build-arg BUILD_TIME="$(BUILD_TIME)" \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
--build-arg GIT_REF="$(GIT_REF)" \
--build-arg GIT_REF_NAME="$(GIT_REF_NAME)" \
--build-arg GIT_REF_TYPE="$(GIT_REF_TYPE)" \
--file ./docker/Dockerfile \
.
swagger:
go tool swag init \
--parseDependency \
--dir ./pkg/app/,./pkg/database/,./vendor/gorm.io/gorm/,./vendor/github.com/codingsince1985/geo-golang/ \
--generalInfo api_handlers.go
git commit docs/ -m "Update swagger" -m "changelog: ignore" || echo "No changes to commit"
build-frontend: install-deps
cd frontend && npm run build
build-templates:
$(TEMPL_COMMAND) generate \
--include-version=false
test-packages:
$(GO_TEST) ./pkg/...
test-templates:
$(GO_TEST) ./views/...
test-commands:
$(GO_TEST) ./cmd/...
verify-templates:
$(TEMPL_COMMAND) fmt --fail -v .
format-templates:
$(TEMPL_COMMAND) fmt -v .
serve:
$(WT_OUTPUT_FILE)
test: test-go test-assets
test-assets:
prettier --check .
test-go: test-commands test-templates test-packages
golangci-lint run --allow-parallel-runners
screenshots: generate-screenshots screenshots-theme screenshots-responsive screenshots-i18n track-gif
generate-screenshots: build-server
export WT_BIND=[::]:8180 WT_DSN=./tmp/screenshots.db; \
$(WT_OUTPUT_FILE) & \
export SERVER_PID=$$!; \
sleep 3; \
K6_BROWSER_ARGS="force-dark-mode" k6 run screenshots.js; \
kill $${SERVER_PID}
generate-track-frames: build-server
mkdir -p tmp/
export WT_BIND=[::]:8180 WT_DSN=./tmp/screenshots.db; \
$(WT_OUTPUT_FILE) & \
export SERVER_PID=$$!; \
sleep 3; \
K6_BROWSER_ARGS="force-dark-mode" k6 run track.js; \
kill $${SERVER_PID}
track-gif: generate-track-frames
magick convert -delay 50 -loop 0 tmp/track-frame-*.png docs/track.gif
rm tmp/track-frame-*.png
screenshots-i18n:
magick convert -delay 400 docs/profile-*.png docs/profile.gif
screenshots-theme:
mkdir -p tmp/
convert docs/single_workout-dark.png \
-resize $(THEME_SCREENSHOT_WIDTH)x$(THEME_SCREENSHOT_HEIGHT)\! \
tmp/dark_resized.jpg
convert docs/single_workout-light.png \
-resize $(THEME_SCREENSHOT_WIDTH)x$(THEME_SCREENSHOT_HEIGHT)\! \
tmp/light_resized.jpg
convert -size $(THEME_SCREENSHOT_WIDTH)x$(THEME_SCREENSHOT_HEIGHT) \
xc:white -draw "polygon 0,0 $(THEME_SCREENSHOT_WIDTH),0 $(THEME_SCREENSHOT_WIDTH),$(THEME_SCREENSHOT_HEIGHT)" \
tmp/mask.png
convert tmp/dark_resized.jpg tmp/light_resized.jpg tmp/mask.png \
-composite docs/single_workout-theme.jpg
rm -f tmp/dark_resized.jpg tmp/light_resized.jpg tmp/mask.png
screenshots-responsive:
montage \
-font Liberation-Sans \
-density 300 \
-tile 3x0 \
-geometry +5+5 \
-background none \
docs/dashboard-responsive.png docs/single_workout-responsive.png docs/statistics-responsive.png docs/responsive.png
go-vendor:
go mod vendor
go-cover:
go test -short -count 1 -mod vendor -covermode=atomic -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
rm -vf coverage.out
update-deps:
# Check no changes
@if [[ "$$(git status --porcelain | wc -l)" -gt 0 ]]; then echo "There are changes; please commit or stash them first"; exit 1; fi
# Check if branch exists locally or remotely
@if git show-ref --verify --quiet refs/heads/$(BRANCH_NAME_DEPS); then echo "Branch $(BRANCH_NAME_DEPS) already exists locally. Aborting."; exit 1; fi
@if git ls-remote --exit-code --heads origin $(BRANCH_NAME_DEPS); then echo "Branch $(BRANCH_NAME_DEPS) already exists remotely. Aborting."; exit 1; fi
git switch --create $(BRANCH_NAME_DEPS)
cd frontend && npm update
go get -u -t ./...
go mod tidy
go mod vendor
git add .
git commit -m "build(deps): Update Go and frontend dependencies"
git push origin $(BRANCH_NAME_DEPS)
changelog:
git cliff -o CHANGELOG.md
prettier --write CHANGELOG.md
git commit CHANGELOG.md -m "Update changelog" -m "changelog: ignore"