-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
147 lines (115 loc) · 4.15 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
MAKEFLAGS += --no-print-directory
TARGET = texd
VERSION = $(shell git describe --tags --always --dirty)
COMMIT_DATE = $(shell git show -s --format=%cI HEAD)
BUILD_DATE = $(shell date --iso-8601=seconds)
DEVELOPMENT = 1
LDFLAGS = -s -w \
-X 'github.com/digineo/texd.version=$(VERSION)' \
-X 'github.com/digineo/texd.commitat=$(COMMIT_DATE)' \
-X 'github.com/digineo/texd.buildat=$(BUILD_DATE)' \
-X 'github.com/digineo/texd.isdev=$(DEVELOPMENT)'
GOFLAGS = -trimpath -ldflags="$(LDFLAGS)"
# passed to run-* targets
RUN_ARGS = --job-directory ./tmp --log-level debug
EXTRA_RUN_ARGS =
## help (prints target names with trailing "## comment")
PHONY: help
help: ## print a short help message
@grep -hE '^[a-zA-Z_-]+:[^:]*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-18s\033[0m %s\n", $$1, $$2}'
## building
build: $(TARGET) ## build a development binary
.PHONY: $(TARGET)
$(TARGET):
go build -o $@ $(GOFLAGS) ./cmd/texd
.PHONY: clean
clean: ## cleanup build fragments
rm -rf tmp/ dist/ texd coverage.*
## development
.PHONY: lint
lint: ## runs golangci-lint on source files
golangci-lint run
.PHONY: run-local
run-local: tmp build ## builds and runs texd in local mode
./$(TARGET) $(RUN_ARGS) $(EXTRA_RUN_ARGS)
.PHONY: run-container
run-container: tmp build ## builds and runs texd in container mode
./$(TARGET) $(RUN_ARGS) $(EXTRA_RUN_ARGS) ghcr.io/digineo/texd:base
.PHONY: run-dind-bind
run-dind-bind: tmp docker-latest ## build and runs texd in container mode, using Docker-in-Docker
docker run \
--rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $$(pwd)/tmp:/texd \
-p 127.0.0.1:2201:2201 \
ghcr.io/digineo/texd:latest \
--log-level debug $(EXTRA_RUN_ARGS) \
ghcr.io/digineo/texd:base
.PHONY: run-dind-volume
run-dind-volume: tmp docker-latest ## build and runs texd in container mode, using Docker-in-Docker
docker run \
--rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v texd-work:/texd \
-p 127.0.0.1:2201:2201 \
ghcr.io/digineo/texd:latest \
--log-level debug $(EXTRA_RUN_ARGS) \
ghcr.io/digineo/texd:base
## testing
.PHONY: coverage.out
coverage.out:
go test -race -covermode=atomic -coverprofile=$@ ./...
coverage.html: coverage.out
go tool cover -html $< -o $@
.PHONY: test
test: coverage.out ## runs tests
.PHONY: test-simple
test-simple: tmp ## sends a simple document to a running instance
curl http://localhost:2201/render \
-F "input.tex=<testdata/simple/input.tex" \
-s -o tmp/$@-$$(date +%F_%T)-$$$$
.PHONY: test-multi
test-multi: tmp ## sends a more complex document to a running instance
curl http://localhost:2201/render \
-F "input.tex=<testdata/multi/input.tex" \
-F "doc.tex=<testdata/multi/doc.tex" \
-F "chapter/input.tex=<testdata/multi/chapter/input.tex" \
-s -o tmp/$@-$$(date +%F_%T)-$$$$
.PHONY: test-missing
test-missing: tmp ## send a broken document to a running instance
curl 'http://localhost:2201/render?errors=condensed' \
-F "input.tex=<testdata/missing/input.tex" \
-s -o tmp/$@-$$(date +%F_%T)-$$$$
.PHONY: test-load
test-load: tmp ## sends 200 documents to a running instance
for i in $$(seq 1 100); do \
$(MAKE) -j2 test-multi test-missing & \
done
## release engineering
.PHONY: release-test
release-test: ## runs goreleaser, but skips publishing
goreleaser release --clean --skip=publish
.PHONY: release-publish
release-publish: ## runs goreleaser and publishes artifacts
goreleaser release --clean
.PHONY: docker-latest
docker-latest: build ## builds a Docker container with the latest binary
docker build --pull \
--label=org.opencontainers.image.created=$(BUILD_DATE) \
--label=org.opencontainers.image.title=$(TARGET) \
--label=org.opencontainers.image.revision=$(shell git show -s --format=%H HEAD) \
--label=org.opencontainers.image.version=$(VERSION) \
-t ghcr.io/digineo/texd:latest \
.
.PHONY: bump bump-major bump-minor bump-patch
bump: bump-patch ## bump version
bump-major: ## bump major version
go run ./cmd/build bump --major
bump-minor: ## bump minor version
go run ./cmd/build bump --minor
bump-patch: ## bump patch version
go run ./cmd/build bump
## misc
tmp:
mkdir -p ./tmp