Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. GO=$(shell which go)
  2. VERSION := $(shell git describe --tag)
  3. .PHONY:
  4. help:
  5. @echo "Typical commands:"
  6. @echo " make check - Run all tests, vetting/formatting checks and linters"
  7. @echo " make fmt build-snapshot install - Build latest and install to local system"
  8. @echo
  9. @echo "Test/check:"
  10. @echo " make test - Run tests"
  11. @echo " make race - Run tests with -race flag"
  12. @echo " make coverage - Run tests and show coverage"
  13. @echo " make coverage-html - Run tests and show coverage (as HTML)"
  14. @echo " make coverage-upload - Upload coverage results to codecov.io"
  15. @echo
  16. @echo "Lint/format:"
  17. @echo " make fmt - Run 'go fmt'"
  18. @echo " make fmt-check - Run 'go fmt', but don't change anything"
  19. @echo " make vet - Run 'go vet'"
  20. @echo " make lint - Run 'golint'"
  21. @echo " make staticcheck - Run 'staticcheck'"
  22. @echo
  23. @echo "Build:"
  24. @echo " make build - Build"
  25. @echo " make build-snapshot - Build snapshot"
  26. @echo " make build-simple - Build (using go build, without goreleaser)"
  27. @echo " make clean - Clean build folder"
  28. @echo
  29. @echo "Releasing (requires goreleaser):"
  30. @echo " make release - Create a release"
  31. @echo " make release-snapshot - Create a test release"
  32. @echo
  33. @echo "Install locally (requires sudo):"
  34. @echo " make install - Copy binary from dist/ to /usr/bin"
  35. @echo " make install-deb - Install .deb from dist/"
  36. @echo " make install-lint - Install golint"
  37. # Documentation
  38. docs: .PHONY
  39. mkdocs build
  40. # Test/check targets
  41. check: test fmt-check vet lint staticcheck
  42. test: .PHONY
  43. $(GO) test ./...
  44. race: .PHONY
  45. $(GO) test -race ./...
  46. coverage:
  47. mkdir -p build/coverage
  48. $(GO) test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic ./...
  49. $(GO) tool cover -func build/coverage/coverage.txt
  50. coverage-html:
  51. mkdir -p build/coverage
  52. $(GO) test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic ./...
  53. $(GO) tool cover -html build/coverage/coverage.txt
  54. coverage-upload:
  55. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  56. # Lint/formatting targets
  57. fmt:
  58. $(GO) fmt ./...
  59. fmt-check:
  60. test -z $(shell gofmt -l .)
  61. vet:
  62. $(GO) vet ./...
  63. lint:
  64. which golint || $(GO) get -u golang.org/x/lint/golint
  65. $(GO) list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  66. staticcheck: .PHONY
  67. rm -rf build/staticcheck
  68. which staticcheck || go get honnef.co/go/tools/cmd/staticcheck
  69. mkdir -p build/staticcheck
  70. ln -s "$(GO)" build/staticcheck/go
  71. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  72. rm -rf build/staticcheck
  73. # Building targets
  74. build-deps: docs
  75. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/v7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  76. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  77. build: build-deps
  78. goreleaser build --rm-dist --debug
  79. build-snapshot: build-deps
  80. goreleaser build --snapshot --rm-dist --debug
  81. build-simple: clean
  82. mkdir -p dist/ntfy_linux_amd64
  83. export CGO_ENABLED=1
  84. $(GO) build \
  85. -o dist/ntfy_linux_amd64/ntfy \
  86. -tags sqlite_omit_load_extension,osusergo,netgo \
  87. -ldflags \
  88. "-linkmode=external -extldflags=-static -s -w -X main.version=$(VERSION) -X main.commit=$(shell git rev-parse --short HEAD) -X main.date=$(shell date +%s)"
  89. clean: .PHONY
  90. rm -rf dist build
  91. # Releasing targets
  92. release-check-tags:
  93. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  94. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  95. echo "ERROR: Must update docs/install.md with latest tag first.";\
  96. exit 1;\
  97. fi
  98. release: build-deps release-check-tags check
  99. goreleaser release --rm-dist --debug
  100. release-snapshot: build-deps
  101. goreleaser release --snapshot --skip-publish --rm-dist --debug
  102. # Installing targets
  103. install:
  104. sudo rm -f /usr/bin/ntfy
  105. sudo cp -a dist/ntfy_linux_amd64/ntfy /usr/bin/ntfy
  106. install-deb:
  107. sudo systemctl stop ntfy || true
  108. sudo apt-get purge ntfy || true
  109. sudo dpkg -i dist/*.deb