-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
justfile
236 lines (188 loc) · 7.13 KB
/
justfile
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
set dotenv-load
# Displays this help message
help:
@echo "Available commands:"
@just --list
# Builds the go binary into the git ignored ./build/ dir for the local architecture
build:
#!/usr/bin/env sh
echo "Building for local arch"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza
# Builds and installs the go binary for the local architecture. WARNING: requires sudo access
install: build
sudo cp "./build/pizza" "/usr/local/bin/"
# Builds all build targets arcross all OS and architectures
build-all: \
build \
build-container \
build-darwin-amd64 build-darwin-arm64 \
build-linux-amd64 build-linux-arm64 \
build-windows-amd64 build-windows-arm64
# Builds for Darwin linux (i.e., MacOS) on amd64 architecture
build-darwin-amd64:
#!/usr/bin/env sh
echo "Building darwin amd64"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
export CGO_ENABLED=0
export GOOS="darwin"
export GOARCH="amd64"
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza-${GOOS}-${GOARCH}
# Builds for Darwin linux (i.e., MacOS) on arm64 architecture (i.e. Apple silicon)
build-darwin-arm64:
#!/usr/bin/env sh
echo "Building darwin arm64"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
export CGO_ENABLED=0
export GOOS="darwin"
export GOARCH="arm64"
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza-${GOOS}-${GOARCH}
# Builds for agnostic Linux on amd64 architecture
build-linux-amd64:
#!/usr/bin/env sh
echo "Building linux amd64"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
export CGO_ENABLED=0
export GOOS="linux"
export GOARCH="amd64"
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza-${GOOS}-${GOARCH}
# Builds for agnostic Linux on arm64 architecture
build-linux-arm64:
#!/usr/bin/env sh
echo "Building linux arm64"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
export CGO_ENABLED=0
export GOOS="linux"
export GOARCH="arm64"
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza-${GOOS}-${GOARCH}
# Builds for Windows on amd64 architecture
build-windows-amd64:
#!/usr/bin/env sh
echo "Building windows amd64"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
export CGO_ENABLED=0
export GOOS="windows"
export GOARCH="amd64"
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza-${GOOS}-${GOARCH}
# Builds for Windows on arm64 architecture
build-windows-arm64:
#!/usr/bin/env sh
echo "Building windows arm64"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
export CGO_ENABLED=0
export GOOS="windows"
export GOARCH="arm64"
go build \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/pizza-${GOOS}-${GOARCH}
# Builds the Docker container and tags it as "dev"
build-container:
#!/usr/bin/env sh
echo "Building container"
export VERSION="${RELEASE_TAG_VERSION:-dev}"
export DATETIME=$(date -u +"%Y-%m-%d-%H:%M:%S")
export SHA=$(git rev-parse HEAD)
docker build \
--build-arg VERSION="${VERSION}" \
--build-arg SHA="${SHA}" \
--build-arg DATETIME="${DATETIME}" \
--build-arg POSTHOG_PUBLIC_API_KEY="${POSTHOG_PUBLIC_API_KEY}" \
-t pizza:dev .
# Removes build artifacts
clean:
rm -rf build/
# Runs all tests
test: unit-test
# Runs all in-code, unit tests
unit-test:
go test ./...
# Lints Go code via golangci-lint within Docker
lint:
docker run \
-t \
--rm \
-v "$(pwd)/:/app" \
-w /app \
golangci/golangci-lint:v1.60 \
golangci-lint run -v
# Formats Go code via goimports
format:
find . -type f -name "*.go" -exec goimports -local github.com/open-sauced/pizza-cli -w {} \;
# Installs the dev tools for working with this project. Requires "go", "just", and "docker"
install-dev-tools:
#!/usr/bin/env sh
go install golang.org/x/tools/cmd/goimports@latest
# Runs Go code manually through the main.go
run:
go run main.go
# Re-generates the docs from the cobra command tree
gen-docs:
go run main.go docs ./docs/
# Runs all the dev tasks (like formatting, linting, building, etc.)
dev: format lint test build-all
# Calls the various Posthog capture events to add the Insights to the database
bootstrap-telemetry:
#!/usr/bin/env sh
echo "Building telemetry-oneshot"
go build \
-tags telemetry \
-ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o build/telemetry-oneshot \
telemetry.go
./build/telemetry-oneshot
rm ./build/telemetry-oneshot