Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
208 lines (186 loc) · 6.17 KB
/
Copy pathTaskfile.yml
File metadata and controls
208 lines (186 loc) · 6.17 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
version: "3"
vars:
TAILWIND_VERSION: 4.3.3
TAILWIND: ./bin/tailwindcss
GOLANGCI_VERSION: 2.13.2
GOLANGCI: ./bin/golangci-lint
HTML_VALIDATE_VERSION: 10
SQLC_VERSION: 1.31.1
SQLC: ./bin/sqlc
DATABASE_URL: '{{.DATABASE_URL | default "postgres://chat:chat@localhost:5432/chat?sslmode=disable"}}'
ORIGIN: '{{.ORIGIN | default "http://localhost:8080"}}'
CSS_IN: assets/css/globals.css
CSS_OUT: assets/dist/styles.css
tasks:
default:
desc: List the tasks
cmds:
- task --list
silent: true
tools:
desc: Download every pinned tool binary into ./bin
deps: [tools:tailwind, tools:golangci, tools:sqlc]
tools:tailwind:
desc: Download the Tailwind binary into ./bin
status:
- test -x {{.TAILWIND}}
cmds:
- mkdir -p bin
- |
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) asset=tailwindcss-linux-x64 ;;
Linux-aarch64) asset=tailwindcss-linux-arm64 ;;
Darwin-x86_64) asset=tailwindcss-macos-x64 ;;
Darwin-arm64) asset=tailwindcss-macos-arm64 ;;
*) echo "No Tailwind binary for $(uname -s) $(uname -m)." >&2; exit 1 ;;
esac
curl -fsSL -o {{.TAILWIND}} \
"https://github.com/tailwindlabs/tailwindcss/releases/download/v{{.TAILWIND_VERSION}}/${asset}"
- chmod +x {{.TAILWIND}}
tools:sqlc:
desc: Download the sqlc binary into ./bin
status:
- test -x {{.SQLC}}
- "{{.SQLC}} version | grep -q 'v{{.SQLC_VERSION}}'"
cmds:
- mkdir -p bin
- |
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) platform=linux_amd64 ;;
Linux-aarch64) platform=linux_arm64 ;;
Darwin-x86_64) platform=darwin_amd64 ;;
Darwin-arm64) platform=darwin_arm64 ;;
*) echo "No sqlc binary for $(uname -s) $(uname -m)." >&2; exit 1 ;;
esac
curl -fsSL \
"https://github.com/sqlc-dev/sqlc/releases/download/v{{.SQLC_VERSION}}/sqlc_{{.SQLC_VERSION}}_${platform}.tar.gz" \
| tar -xzf - -C bin sqlc
- chmod +x {{.SQLC}}
tools:golangci:
desc: Download the golangci-lint binary into ./bin
status:
- test -x {{.GOLANGCI}}
- "{{.GOLANGCI}} --version | grep -q ' {{.GOLANGCI_VERSION}} '"
cmds:
- mkdir -p bin
- |
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) platform=linux-amd64 ;;
Linux-aarch64) platform=linux-arm64 ;;
Darwin-x86_64) platform=darwin-amd64 ;;
Darwin-arm64) platform=darwin-arm64 ;;
*) echo "No golangci-lint binary for $(uname -s) $(uname -m)." >&2; exit 1 ;;
esac
name="golangci-lint-{{.GOLANGCI_VERSION}}-${platform}"
curl -fsSL \
"https://github.com/golangci/golangci-lint/releases/download/v{{.GOLANGCI_VERSION}}/${name}.tar.gz" \
| tar -xzf - -C bin --strip-components=1 "${name}/golangci-lint"
- chmod +x {{.GOLANGCI}}
db:up:
desc: Start Postgres in the background
cmds:
- docker compose up --detach --wait
db:down:
desc: Stop Postgres and keep the data
cmds:
- docker compose down
db:reset:
desc: Stop Postgres and throw the data away
prompt: This deletes every row in the local database. Go on?
cmds:
- docker compose down --volumes
migrate:
desc: Apply the migrations to the database in DATABASE_URL
env:
DATABASE_URL: "{{.DATABASE_URL}}"
cmds:
- go run ./cmd/chat -migrate-only
seed:
desc: Write the development users into the database
env:
DATABASE_URL: "{{.DATABASE_URL}}"
cmds:
- go run ./cmd/seed
generate:
desc: Generate Go code from the templ files and the SQL queries
deps: [tools:sqlc]
cmds:
- go tool templ generate
- "{{.SQLC}} generate"
css:
desc: Build the stylesheet
deps: [tools:tailwind]
cmds:
- "{{.TAILWIND}} --input {{.CSS_IN}} --output {{.CSS_OUT}} --minify"
build:
desc: Build the server binary
cmds:
- task: generate
- task: css
- go build -o chat ./cmd/chat
dev:
desc: Run the server and rebuild on every change
deps: [tools:tailwind, generate, css]
env:
DATABASE_URL: "{{.DATABASE_URL}}"
ORIGIN: "{{.ORIGIN}}"
# The component bundle then rebuilds from the source files on every
# request, so a change to a component needs no restart.
GO_ENV: development
cmds:
- |
# The reload proxy owns port 8080, the port that the browser uses,
# and the server itself sits behind it on 8081. A passkey belongs to
# the address in the address bar, so the proxy must own that port.
go tool templ generate --watch \
--proxy=http://localhost:8081 \
--proxyport=8080 \
--open-browser=false \
--cmd="go run ./cmd/chat -addr :8081" &
{{.TAILWIND}} --input {{.CSS_IN}} --output {{.CSS_OUT}} --watch &
wait
image:
desc: Build the container image and the binaries without publishing
cmds:
- goreleaser release --snapshot --clean
test:
desc: Run the tests
deps: [generate]
env:
DATABASE_URL: "{{.DATABASE_URL}}"
cmds:
- go test ./...
test:race:
desc: Run the tests with the race detector
deps: [generate]
env:
DATABASE_URL: "{{.DATABASE_URL}}"
cmds:
# The race detector needs cgo. The variable sits in the command,
# because a value in the environment of the shell beats the env block.
- CGO_ENABLED=1 go test -race ./...
fmt:
desc: Format the code
deps: [tools:golangci]
cmds:
- go tool templ fmt .
- "{{.GOLANGCI}} fmt"
html:
desc: Check the rendered markup with an HTML validator
# The css task must run first, because the layout reads the hash of the
# stylesheet.
deps: [generate, css]
cmds:
- go run ./cmd/renderhtml tmp/html
- npx --yes html-validate@{{.HTML_VALIDATE_VERSION}} "tmp/html/*.html"
fix:
desc: Apply the modernizations that go fix suggests
deps: [generate]
cmds:
- go fix ./...
lint:
desc: Run the static checks
deps: [tools:golangci, generate]
cmds:
# golangci-lint runs govet, so a separate go vet adds nothing.
- "{{.GOLANGCI}} run"