Makefile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 \
  44. && npm install \
  45. && node_modules/svgo/bin/svgo src/img/*.svg
  46. web-build:
  47. cd web \
  48. && npm run build \
  49. && mv build/index.html build/app.html \
  50. && rm -rf ../server/site \
  51. && mv build ../server/site \
  52. && rm \
  53. ../server/site/config.js \
  54. ../server/site/asset-manifest.json
  55. web: web-deps web-build
  56. # Test/check targets
  57. check: test fmt-check vet lint staticcheck
  58. test: .PHONY
  59. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  60. race: .PHONY
  61. go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  62. coverage:
  63. mkdir -p build/coverage
  64. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  65. go tool cover -func build/coverage/coverage.txt
  66. coverage-html:
  67. mkdir -p build/coverage
  68. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  69. go tool cover -html build/coverage/coverage.txt
  70. coverage-upload:
  71. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  72. # Lint/formatting targets
  73. fmt:
  74. gofmt -s -w .
  75. fmt-check:
  76. test -z $(shell gofmt -l .)
  77. vet:
  78. go vet ./...
  79. lint:
  80. which golint || go install golang.org/x/lint/golint@latest
  81. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  82. staticcheck: .PHONY
  83. rm -rf build/staticcheck
  84. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  85. mkdir -p build/staticcheck
  86. ln -s "go" build/staticcheck/go
  87. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  88. rm -rf build/staticcheck
  89. # Building targets
  90. build-deps: docs web
  91. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/v7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  92. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  93. build: build-deps
  94. goreleaser build --rm-dist --debug
  95. build-snapshot: build-deps
  96. goreleaser build --snapshot --rm-dist --debug
  97. build-simple: clean
  98. mkdir -p dist/ntfy_linux_amd64 server/docs server/site
  99. touch server/docs/index.html
  100. touch server/site/app.html
  101. export CGO_ENABLED=1
  102. go build \
  103. -o dist/ntfy_linux_amd64/ntfy \
  104. -tags sqlite_omit_load_extension,osusergo,netgo \
  105. -ldflags \
  106. "-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)"
  107. clean: .PHONY
  108. rm -rf dist build server/docs server/site
  109. # Releasing targets
  110. release-check-tags:
  111. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  112. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  113. echo "ERROR: Must update docs/install.md with latest tag first.";\
  114. exit 1;\
  115. fi
  116. if grep -q XXXXX docs/releases.md; then\
  117. echo "ERROR: Must update docs/releases.md, found XXXXX.";\
  118. exit 1;\
  119. fi
  120. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  121. echo "ERROR: Must update docs/releases.mdwith latest tag first.";\
  122. exit 1;\
  123. fi
  124. release: build-deps release-check-tags check
  125. goreleaser release --rm-dist --debug
  126. release-snapshot: build-deps
  127. goreleaser release --snapshot --skip-publish --rm-dist --debug
  128. # Installing targets
  129. install:
  130. sudo rm -f /usr/bin/ntfy
  131. sudo cp -a dist/ntfy_linux_amd64/ntfy /usr/bin/ntfy
  132. install-deb:
  133. sudo systemctl stop ntfy || true
  134. sudo apt-get purge ntfy || true
  135. sudo dpkg -i dist/ntfy_*_linux_amd64.deb