Makefile 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. BROWSERTEST_VERSION = v0.8
  2. LINT_VERSION = 1.59.1
  3. GO_BIN = $(shell printf '%s/bin' "$$(go env GOPATH)")
  4. SHELL = bash
  5. current_platform := $(shell go env GOOS)/$(shell go env GOARCH)
  6. # Only use the race detector on supported architectures.
  7. # Go's supported platforms pulled from 'go help build' under '-race'.
  8. race_platforms := linux/amd64 freebsd/amd64 darwin/amd64 darwin/arm64 windows/amd64 linux/ppc64le linux/arm64
  9. RACE_ENABLED = $(if $(findstring ${current_platform},${race_platforms}),true,false)
  10. .PHONY: all
  11. all: lint test
  12. .PHONY: lint-deps
  13. lint-deps:
  14. @if ! which golangci-lint >/dev/null || [[ "$$(golangci-lint version 2>&1)" != *${LINT_VERSION}* ]]; then \
  15. curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GO_BIN}" v${LINT_VERSION}; \
  16. fi
  17. @if ! which jsguard >/dev/null; then \
  18. go install github.com/hack-pad/safejs/jsguard/cmd/jsguard@latest; \
  19. fi
  20. .PHONY: lint
  21. lint: lint-deps
  22. "${GO_BIN}/golangci-lint" run
  23. GOOS=js GOARCH=wasm "${GO_BIN}/golangci-lint" run
  24. cd examples && "${GO_BIN}/golangci-lint" run --config=../.golangci.yml --timeout=5m
  25. GOOS=js GOARCH=wasm "${GO_BIN}/jsguard" ./...
  26. .PHONY: test-deps
  27. test-deps:
  28. @if [ ! -f "${GO_BIN}/go_js_wasm_exec" ]; then \
  29. set -ex; \
  30. GOOS= GOARCH= go install github.com/agnivade/wasmbrowsertest@${BROWSERTEST_VERSION}; \
  31. ln -s "${GO_BIN}/wasmbrowsertest" "${GO_BIN}/go_js_wasm_exec"; \
  32. fi
  33. @go install github.com/mattn/goveralls@v0.0.9
  34. .PHONY: test
  35. test: test-deps
  36. go test . # Run library-level checks first, for more helpful build tag failure messages.
  37. go test -race=${RACE_ENABLED} -coverprofile=native-cover.out ./...
  38. if [[ "$$CI" != true || $$(uname -s) == Linux ]]; then \
  39. set -ex; \
  40. GOOS=js GOARCH=wasm go test -coverprofile=js-cover.out -covermode=atomic ./...; \
  41. cd examples && go test -race=${RACE_ENABLED} ./...; \
  42. fi
  43. { echo 'mode: atomic'; cat *-cover.out | grep -v '^mode:'; } > cover.out && rm *-cover.out
  44. go tool cover -func cover.out | grep total:
  45. @if [[ "$$CI" == true && $$(uname -sm) == 'Linux x86_64' && "$$(go version)" == *go"$$COVERAGE_VERSION"* ]]; then \
  46. set -ex; \
  47. goveralls -coverprofile=cover.out -service=github || true; \
  48. fi