Makefile 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. VERSION := $(shell git describe --tag)
  2. .PHONY:
  3. help:
  4. @echo "Typical commands (more see below):"
  5. @echo " make build - Build web app, documentation and server/client (sloowwww)"
  6. @echo " make server-amd64 - Build server/client binary (amd64, no web app or docs)"
  7. @echo " make install-amd64 - Install ntfy binary to /usr/bin/ntfy (amd64)"
  8. @echo " make web - Build the web app"
  9. @echo " make docs - Build the documentation"
  10. @echo " make check - Run all tests, vetting/formatting checks and linters"
  11. @echo
  12. @echo "Build everything:"
  13. @echo " make build - Build web app, documentation and server/client"
  14. @echo " make clean - Clean build/dist folders"
  15. @echo
  16. @echo "Build server & client (not release version):"
  17. @echo " make server - Build server & client (all architectures)"
  18. @echo " make server-amd64 - Build server & client (amd64 only)"
  19. @echo " make server-armv6 - Build server & client (armv6 only)"
  20. @echo " make server-armv7 - Build server & client (armv7 only)"
  21. @echo " make server-arm64 - Build server & client (arm64 only)"
  22. @echo
  23. @echo "Build web app:"
  24. @echo " make web - Build the web app"
  25. @echo " make web-deps - Install web app dependencies (npm install the universe)"
  26. @echo " make web-build - Actually build the web app"
  27. @echo
  28. @echo "Build documentation:"
  29. @echo " make docs - Build the documentation"
  30. @echo " make docs-deps - Install Python dependencies (pip3 install)"
  31. @echo " make docs-build - Actually build the documentation"
  32. @echo
  33. @echo "Test/check:"
  34. @echo " make test - Run tests"
  35. @echo " make race - Run tests with -race flag"
  36. @echo " make coverage - Run tests and show coverage"
  37. @echo " make coverage-html - Run tests and show coverage (as HTML)"
  38. @echo " make coverage-upload - Upload coverage results to codecov.io"
  39. @echo
  40. @echo "Lint/format:"
  41. @echo " make fmt - Run 'go fmt'"
  42. @echo " make fmt-check - Run 'go fmt', but don't change anything"
  43. @echo " make vet - Run 'go vet'"
  44. @echo " make lint - Run 'golint'"
  45. @echo " make staticcheck - Run 'staticcheck'"
  46. @echo
  47. @echo "Releasing:"
  48. @echo " make release - Create a release"
  49. @echo " make release-snapshot - Create a test release"
  50. @echo
  51. @echo "Install locally (requires sudo):"
  52. @echo " make install-amd64 - Copy amd64 binary from dist/ to /usr/bin/ntfy"
  53. @echo " make install-armv6 - Copy armv6 binary from dist/ to /usr/bin/ntfy"
  54. @echo " make install-armv7 - Copy armv7 binary from dist/ to /usr/bin/ntfy"
  55. @echo " make install-arm64 - Copy arm64 binary from dist/ to /usr/bin/ntfy"
  56. @echo " make install-deb-amd64 - Install .deb from dist/ (amd64 only)"
  57. @echo " make install-deb-armv6 - Install .deb from dist/ (armv6 only)"
  58. @echo " make install-deb-armv7 - Install .deb from dist/ (armv7 only)"
  59. @echo " make install-deb-arm64 - Install .deb from dist/ (arm64 only)"
  60. # Building everything
  61. clean: .PHONY
  62. rm -rf dist build server/docs server/site
  63. build: web docs server
  64. # Documentation
  65. docs: docs-deps docs-build
  66. docs-deps: .PHONY
  67. pip3 install -r requirements.txt
  68. docs-build: .PHONY
  69. mkdocs build
  70. # Web app
  71. web: web-deps web-build
  72. web-deps:
  73. cd web && npm install
  74. # If this fails for .svg files, optimizes them with svgo
  75. web-build:
  76. cd web \
  77. && npm run build \
  78. && mv build/index.html build/app.html \
  79. && rm -rf ../server/site \
  80. && mv build ../server/site \
  81. && rm \
  82. ../server/site/config.js \
  83. ../server/site/asset-manifest.json
  84. # Main server/client build
  85. server: server-deps
  86. goreleaser build --snapshot --rm-dist --debug
  87. server-amd64: server-deps-static-sites
  88. goreleaser build --snapshot --rm-dist --debug --id ntfy_amd64
  89. server-armv6: server-deps-static-sites server-deps-gcc-armv6-armv7
  90. goreleaser build --snapshot --rm-dist --debug --id ntfy_armv6
  91. server-armv7: server-deps-static-sites server-deps-gcc-armv6-armv7
  92. goreleaser build --snapshot --rm-dist --debug --id ntfy_armv7
  93. server-arm64: server-deps-static-sites server-deps-gcc-arm64
  94. goreleaser build --snapshot --rm-dist --debug --id ntfy_arm64
  95. server-deps: server-deps-static-sites server-deps-all server-deps-gcc
  96. server-deps-gcc: server-deps-gcc-armv6-armv7 server-deps-gcc-arm64
  97. server-deps-static-sites:
  98. mkdir -p server/docs server/site
  99. touch server/docs/index.html server/site/app.html
  100. server-deps-all:
  101. which upx || { echo "ERROR: upx not installed. On Ubuntu, run: apt install upx"; exit 1; }
  102. server-deps-gcc-armv6-armv7:
  103. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  104. server-deps-gcc-arm64:
  105. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  106. # Test/check targets
  107. check: test fmt-check vet lint staticcheck
  108. test: .PHONY
  109. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  110. race: .PHONY
  111. go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  112. coverage:
  113. mkdir -p build/coverage
  114. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  115. go tool cover -func build/coverage/coverage.txt
  116. coverage-html:
  117. mkdir -p build/coverage
  118. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  119. go tool cover -html build/coverage/coverage.txt
  120. coverage-upload:
  121. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  122. # Lint/formatting targets
  123. fmt:
  124. gofmt -s -w .
  125. fmt-check:
  126. test -z $(shell gofmt -l .)
  127. vet:
  128. go vet ./...
  129. lint:
  130. which golint || go install golang.org/x/lint/golint@latest
  131. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  132. staticcheck: .PHONY
  133. rm -rf build/staticcheck
  134. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  135. mkdir -p build/staticcheck
  136. ln -s "go" build/staticcheck/go
  137. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  138. rm -rf build/staticcheck
  139. # Releasing targets
  140. release: clean server-deps release-check-tags docs web check
  141. goreleaser release --rm-dist --debug
  142. release-snapshot: clean server-deps docs web check
  143. goreleaser release --snapshot --skip-publish --rm-dist --debug
  144. release-check-tags:
  145. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  146. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  147. echo "ERROR: Must update docs/install.md with latest tag first.";\
  148. exit 1;\
  149. fi
  150. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  151. echo "ERROR: Must update docs/releases.md with latest tag first.";\
  152. exit 1;\
  153. fi
  154. # Installing targets
  155. install-amd64: remove-binary
  156. sudo cp -a dist/ntfy_amd64_linux_amd64_v1/ntfy /usr/bin/ntfy
  157. install-armv6: remove-binary
  158. sudo cp -a dist/ntfy_armv6_linux_arm_6/ntfy /usr/bin/ntfy
  159. install-armv7: remove-binary
  160. sudo cp -a dist/ntfy_armv7_linux_arm_7/ntfy /usr/bin/ntfy
  161. install-arm64: remove-binary
  162. sudo cp -a dist/ntfy_arm64_linux_arm64/ntfy /usr/bin/ntfy
  163. remove-binary:
  164. sudo rm -f /usr/bin/ntfy
  165. install-amd64-deb: purge-package
  166. sudo dpkg -i dist/ntfy_*_linux_amd64.deb
  167. install-armv6-deb: purge-package
  168. sudo dpkg -i dist/ntfy_*_linux_armv6.deb
  169. install-armv7-deb: purge-package
  170. sudo dpkg -i dist/ntfy_*_linux_armv7.deb
  171. install-arm64-deb: purge-package
  172. sudo dpkg -i dist/ntfy_*_linux_arm64.deb
  173. purge-package:
  174. sudo systemctl stop ntfy || true
  175. sudo apt-get purge ntfy || true