This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Makefile
195 lines (163 loc) · 4.95 KB
/
Makefile
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
VERSION = $(shell git describe --tags --dirty --always)
GIT_COMMIT = $(shell git rev-parse HEAD)
RANDOM_SUFFIX := $(shell cat /dev/urandom | tr -dc 'a-z0-9' | head -c5)
IMAGE_NAME = leg100/otfd
IMAGE_TAG ?= $(VERSION)-$(RANDOM_SUFFIX)
DBSTRING=postgres:///otf
LD_FLAGS = " \
-s -w \
-X 'github.com/leg100/otf/internal.Version=$(VERSION)' \
-X 'github.com/leg100/otf/internal.Commit=$(GIT_COMMIT)' \
-X 'github.com/leg100/otf/internal.Built=$(shell date +%s)' \
" \
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
.PHONY: go-tfe-tests
go-tfe-tests: image compose-up
./hack/go-tfe-tests.bash
.PHONY: watch
watch: tailwind-watch modd
.PHONY: modd
modd:
+modd
.PHONY: tailwind
tailwind:
npx tailwindcss -i ./internal/http/html/static/css/input.css -o ./internal/http/html/static/css/output.css
.PHONY: tailwind-watch
tailwind-watch:
+npx tailwindcss -i ./internal/http/html/static/css/input.css -o ./internal/http/html/static/css/output.css --watch
.PHONY: test
test:
go test ./...
.PHONY: build
build:
CGO_ENABLED=0 go build -o _build/ -ldflags $(LD_FLAGS) ./...
chmod -R +x _build/*
.PHONY: install
install:
go install -ldflags $(LD_FLAGS) ./...
.PHONY: install-latest-release
install-latest-release:
{ \
set -ex ;\
ZIP_FILE=$$(mktemp) ;\
RELEASE_URL=$$(curl -s https://api.github.com/repos/leg100/otf/releases/latest | \
jq -r '.assets[] | select(.name | test("otfd_.*_linux_amd64.zip$$")) | .browser_download_url') ;\
curl -Lo $$ZIP_FILE $$RELEASE_URL ;\
unzip -o -d $(GOBIN) $$ZIP_FILE otfd ;\
}
# Run docker compose stack
.PHONY: compose-up
compose-up: image
docker compose up -d --wait --wait-timeout 60
# Remove docker compose stack
.PHONY: compose-rm
compose-rm:
docker compose rm -sf
# Run postgresql via docker compose
.PHONY: postgres
postgres:
docker compose up -d postgres
# Run staticcheck metalinter recursively against code
.PHONY: lint
lint:
go list ./... | grep -v pggen | xargs staticcheck
# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./...
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# Build docker image
.PHONY: image
image: build
docker build -f Dockerfile -t $(IMAGE_NAME):$(IMAGE_TAG) -t $(IMAGE_NAME):latest ./_build
# Build and load image into k8s kind
.PHONY: load
load: image
kind load docker-image $(IMAGE_NAME):$(IMAGE_TAG)
# Install pre-commit
.PHONY: install-pre-commit
install-pre-commit:
pip install pre-commit==3.2.2
pre-commit install
# Install sql code generator
.PHONY: install-pggen
install-pggen:
@sh -c "which pggen > /dev/null || go install github.com/leg100/pggen/cmd/pggen@latest"
# Generate sql code
.PHONY: sql
sql: install-pggen
pggen gen go \
--postgres-connection $(DBSTRING) \
--query-glob 'internal/sql/queries/*.sql' \
--output-dir ./internal/sql/pggen \
--go-type 'text=github.com/jackc/pgtype.Text' \
--go-type 'int4=github.com/jackc/pgtype.Int4' \
--go-type 'int8=github.com/jackc/pgtype.Int8' \
--go-type 'bool=github.com/jackc/pgtype.Bool' \
--go-type 'bytea=[]byte' \
--acronym url \
--acronym cli \
--acronym sha \
--acronym json \
--acronym vcs \
--acronym html \
--acronym http \
--acronym tls \
--acronym sso \
--acronym hcl \
--acronym ip
goimports -w ./internal/sql/pggen
go fmt ./internal/sql/pggen
# Install DB migration tool
.PHONY: install-goose
install-goose:
@sh -c "which goose > /dev/null || go install github.com/pressly/goose/v3/cmd/goose@latest"
# Migrate SQL schema to latest version
.PHONY: migrate
migrate: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations up
# Redo SQL schema migration
.PHONY: migrate-redo
migrate-redo: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations redo
# Rollback SQL schema by one version
.PHONY: migrate-rollback
migrate-rollback: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations down
# Get SQL schema migration status
.PHONY: migrate-status
migrate-status: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations status
# Run docs server with live reload
.PHONY: serve-docs
serve-docs:
mkdocs serve -a localhost:9999
.PHONY: doc-screenshots
doc-screenshots: # update documentation screenshots
OTF_DOC_SCREENSHOTS=true go test ./internal/integration/... -count 1
# Create tunnel between local server and cloudflare - useful for testing
# webhooks, e.g. a github webhook sending events to local server.
.PHONY: tunnel
tunnel:
cloudflared tunnel run otf
# Generate path helpers
.PHONY: paths
paths:
go generate ./internal/http/html/paths
goimports -w ./internal/http/html/paths
# Re-generate RBAC action strings
.PHONY: actions
actions:
stringer -type Action ./internal/rbac
# Install staticcheck linter
.PHONY: install-linter
install-linter:
go install honnef.co/go/tools/cmd/staticcheck@latest