Makefile 8.4 KB

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