-
Notifications
You must be signed in to change notification settings - Fork 44
/
Makefile
183 lines (151 loc) · 5.25 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
SHELL := /bin/bash
GO_ROOT := $(shell go env GOROOT)
GIT_SHA := $(shell git rev-parse HEAD)
GIT_SHA_SHORT := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION := $(shell git describe --tags)-$(GIT_SHA_SHORT)
LDFLAGS := -s -w \
-X 'github.com/stateful/runme/v3/internal/version.BuildDate=$(DATE)' \
-X 'github.com/stateful/runme/v3/internal/version.BuildVersion=$(subst v,,$(VERSION))' \
-X 'github.com/stateful/runme/v3/internal/version.Commit=$(GIT_SHA)'
LDTESTFLAGS := -X 'github.com/stateful/runme/v3/internal/version.BuildVersion=$(subst v,,$(VERSION))'
ifeq ($(RUNME_EXT_BASE),)
RUNME_EXT_BASE := "../vscode-runme"
endif
.PHONY: build
build: BUILD_OUTPUT ?= runme
build:
CGO_ENABLED=0 go build -o $(BUILD_OUTPUT) -ldflags="$(LDFLAGS)" main.go
.PHONY: wasm
wasm: WASM_OUTPUT ?= examples/web
wasm:
cp $(GO_ROOT)/misc/wasm/wasm_exec.js $(WASM_OUTPUT)
GOOS=js GOARCH=wasm go build -o $(WASM_OUTPUT)/runme.wasm -ldflags="$(LDFLAGS)" ./web
.PHONY: test/execute
test/execute: PKGS ?= "./..."
test/execute: RUN ?= .*
test/execute: RACE ?= false
test/execute: TAGS ?= "" # e.g. TAGS="docker_enabled"
# It depends on the build target because the runme binary
# is used for tests, for example, "runme env dump".
test/execute: build
TZ=UTC go test -ldflags="$(LDTESTFLAGS)" -run="$(RUN)" -tags="$(TAGS)" -timeout=60s -race=$(RACE) $(PKGS)
.PHONY: test/coverage
test/coverage: PKGS ?= "./..."
test/coverage: RUN ?= .*
test/coverage: GOCOVERDIR ?= "."
test/coverage: TAGS ?= "" # e.g. TAGS="docker_enabled"
# It depends on the build target because the runme binary
# is used for tests, for example, "runme env dump".
test/coverage: build
TZ=UTC go test -ldflags="$(LDTESTFLAGS)" -run="$(RUN)" -tags="$(TAGS)" -timeout=180s -covermode=atomic -coverprofile=cover.out -coverpkg=./... $(PKGS)
.PHONY: test
test: test/execute
.PHONY: test-coverage
test-coverage: test/coverage
.PHONY: test-docker
test-docker: test-docker/setup test-docker/run
.PHONY: test-docker/setup
test-docker/setup:
docker build \
--progress=plain \
-t runme-test-env:latest \
-f ./docker/runme-test-env.Dockerfile .
docker volume create dev.runme.test-env-gocache
.PHONY: test-docker/cleanup
test-docker/cleanup:
docker volume rm dev.runme.test-env-gocache
.PHONY: test-docker/run
test-docker/run:
docker run --rm \
-e RUNME_TEST_ENV=docker \
-v $(shell pwd):/workspace \
-v dev.runme.test-env-gocache:/root/.cache/go-build \
runme-test-env:latest
.PHONY: test/update-snapshots
test/update-snapshots:
@TZ=UTC UPDATE_SNAPSHOTS=true go test ./...
.PHONY: test/parser
test/parser:
./runme --version
find "$$GOPATH/pkg/mod/github.com" -name "*.md" | grep -v "\/\." | grep -v glamour | xargs dirname | uniq | xargs -n1 -I {} ./runme fmt --project {} > /dev/null
.PHONY: coverage/html
test/coverage/html:
go tool cover -html=cover.out
.PHONY: coverage/func
test/coverage/func:
go tool cover -func=cover.out
.PHONY: fmt
fmt:
@gofumpt -w .
.PHONY: lint
lint:
@gofumpt -d .
@revive \
-config revive.toml \
-formatter friendly \
-exclude integration/subject/... \
./...
@staticcheck ./...
@gosec -quiet -exclude=G110,G204,G304,G404 -exclude-generated ./...
@go vet -stdmethods=false ./...
@go vet -vettool=$(shell go env GOPATH)/bin/checklocks ./...
.PHONY: pre-commit
pre-commit: build wasm test lint
pre-commit run --all-files
.PHONY: install/dev
install/dev:
go install github.com/mgechev/revive@v1.3.9
go install github.com/securego/gosec/v2/cmd/gosec@v2.20.0
go install honnef.co/go/tools/cmd/staticcheck@v0.5.1
go install mvdan.cc/gofumpt@v0.7.0
go install github.com/icholy/gomajor@v0.13.1
go install github.com/stateful/go-proto-gql/protoc-gen-gql@latest
go install github.com/atombender/go-jsonschema@v0.16.0
go install gvisor.dev/gvisor/tools/checklocks/cmd/checklocks@go
.PHONY: install/goreleaser
install/goreleaser:
go install github.com/goreleaser/goreleaser@v1.26.2
.PHONY: proto/generate
proto/generate:
buf lint
buf format -w
buf generate
.PHONY: proto/clean
proto/clean:
rm -rf pkg/api/gen/proto
.PHONY: proto/dev
proto/dev: build proto/clean proto/generate
rm -rf $(RUNME_EXT_BASE)/node_modules/@buf/stateful_runme.community_timostamm-protobuf-ts/runme
cp -vrf pkg/api/gen/proto/ts/runme $(RUNME_EXT_BASE)/node_modules/@buf/stateful_runme.community_timostamm-protobuf-ts
.PHONY: proto/dev/reset
proto/dev/reset:
rm -rf $(RUNME_EXT_BASE)/node_modules/@buf/stateful_runme.community_timostamm-protobuf-ts
cd $(RUNME_EXT_BASE) && runme run setup
# Remember to set up buf registry beforehand.
# More: https://docs.buf.build/bsr/authentication
.PHONY: proto/publish
proto/publish:
@cd ./pkg/api/proto && buf push
.PHONY: schema/generate
schema/generate:
go-jsonschema -t \
-p config \
--tags "json,yaml" \
-o internal/config/config_schema.go \
internal/config/config.schema.json
.PHONY: release
release: install/goreleaser
@goreleaser check
@goreleaser release --snapshot --clean
.PHONY: release/publish
release/publish: install/goreleaser
@goreleaser release
.PHONY: update-gql-schema
update-gql-schema:
@go run ./cmd/gqltool/main.go > ./internal/client/graphql/schema/introspection_query_result.json
@npm install --prefix internal/client/graphql/schema
@cd ./internal/client/graphql/schema && npm run convert
.PHONY: generate
generate:
go generate ./...