Makefile 5.1 KB

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