Makefile 2.42 KB
Newer Older
Addshore's avatar
Addshore committed
1
2
3
4
GOPATH=$(shell pwd)/vendor:$(shell pwd)
GOBIN=$(shell pwd)/bin
GONAME=mw

5
6
SHELL := /bin/bash
RELEASE_DIR ?= ./_release
Jeena Huneidi's avatar
Jeena Huneidi committed
7
TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le windows/amd64
8
9

PACKAGE := gerrit.wikimedia.org/r/mediawiki/tools/cli
Addshore's avatar
Addshore committed
10
VERSION := latest
11
SEMVER := $(subst v,,$(VERSION))
12
13
14
15

GO_LIST_GOFILES := '{{range .GoFiles}}{{printf "%s/%s\n" $$.Dir .}}{{end}}{{range .XTestGoFiles}}{{printf "%s/%s\n" $$.Dir .}}{{end}}'
GO_PACKAGES := $(shell go list ./...)

Addshore's avatar
Addshore committed
16
all: get-dev generate get build
17

Addshore's avatar
Addshore committed
18
19
get:
	@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get .
20

Addshore's avatar
Addshore committed
21
22
23
get-dev:
	@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get github.com/ahmetb/govvv@v0.3.0
	@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get bou.ke/staticfiles@v0.0.0-20210106104248-dd04075d4104
Addshore's avatar
Addshore committed
24
	@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get github.com/mitchellh/gox@v1.0.1
25

Addshore's avatar
Addshore committed
26
27
build:
	@echo "Building $(GOFILES) to ./bin"
Addshore's avatar
Addshore committed
28
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go build -v -ldflags "$(shell ./bin/govvv -flags)" -o bin/mw ./
29

Addshore's avatar
Addshore committed
30
release:
31
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) ./bin/gox -output="$(RELEASE_DIR)/$(SEMVER)/mw_$(VERSION)_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' -ldflags '$(shell ./bin/govvv -flags)' $(GO_PACKAGES)
Addshore's avatar
Addshore committed
32
	cp LICENSE "$(RELEASE_DIR)"
33
	for f in "$(RELEASE_DIR)"/$(SEMVER)/mw_*; do \
Addshore's avatar
Addshore committed
34
35
		shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256"; \
	done
36

Addshore's avatar
Addshore committed
37
38
39
install: all
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go install -v $(GO_PACKAGES)

40
generate: generate-staticfiles
Addshore's avatar
Addshore committed
41
42
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go generate $(GO_PACKAGES)

43
generate-staticfiles:
Addshore's avatar
Addshore committed
44
45
	rm -f internal/mwdd/files/files.go || true
	./bin/staticfiles -o internal/mwdd/files/files.go static/mwdd/
46
47

clean:
Addshore's avatar
Addshore committed
48
49
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean $(GO_PACKAGES)
	rm -rf bin || true
Addshore's avatar
Addshore committed
50
	rm -rf _release || true
51
	rm internal/mwdd/files/files.go || true
52

Addshore's avatar
Addshore committed
53
test: get-dev generate unit lint
54

Addshore's avatar
Addshore committed
55
unit:
56
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go test -covermode=count -coverprofile "coverage.txt" -ldflags "$(shell ./bin/govvv -flags)" $(GO_PACKAGES)
57
58
59

lint:
	@echo > .lint-gofmt.diff
Addshore's avatar
Addshore committed
60
	@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go list -f $(GO_LIST_GOFILES) $(GO_PACKAGES) | while read f; do \
61
62
63
		gofmt -e -d "$${f}" >> .lint-gofmt.diff; \
	done
	@test -z "$(grep '[^[:blank:]]' .lint-gofmt.diff)" || (echo "gofmt found errors:"; cat .lint-gofmt.diff; exit 1)
Addshore's avatar
Addshore committed
64
65
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) golint -set_exit_status $(GO_PACKAGES)
	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go vet -composites=false $(GO_PACKAGES)
66

Addshore's avatar
Addshore committed
67

68
.PHONY: all get build release install generate generate-staticfiles clean test unit lint