Makefile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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-armv7 - Install .deb from dist/ (armv7 only)"
  58. @echo " make install-deb-arm64 - Install .deb from dist/ (arm64 only)"
  59. # Building everything
  60. clean: .PHONY
  61. rm -rf dist build server/docs server/site
  62. build: web docs server
  63. # Documentation
  64. docs: docs-deps docs-build
  65. docs-deps: .PHONY
  66. pip3 install -r requirements.txt
  67. docs-build: .PHONY
  68. mkdocs build
  69. # Web app
  70. web: web-deps web-build
  71. web-deps:
  72. cd web && npm install
  73. # If this fails for .svg files, optimizes them with svgo
  74. web-build:
  75. cd web \
  76. && npm run build \
  77. && mv build/index.html build/app.html \
  78. && rm -rf ../server/site \
  79. && mv build ../server/site \
  80. && rm \
  81. ../server/site/config.js \
  82. ../server/site/asset-manifest.json
  83. # Main server/client build
  84. server: server-deps
  85. goreleaser build --snapshot --rm-dist --debug
  86. server-amd64: server-deps-static-sites
  87. goreleaser build --snapshot --rm-dist --debug --id ntfy_amd64
  88. server-armv6: server-deps-static-sites server-deps-gcc-armv6-armv7
  89. goreleaser build --snapshot --rm-dist --debug --id ntfy_armv6
  90. server-armv7: server-deps-static-sites server-deps-gcc-armv6-armv7
  91. goreleaser build --snapshot --rm-dist --debug --id ntfy_armv7
  92. server-arm64: server-deps-static-sites server-deps-gcc-arm64
  93. goreleaser build --snapshot --rm-dist --debug --id ntfy_arm64
  94. server-deps: server-deps-static-sites server-deps-all server-deps-gcc
  95. server-deps-gcc: server-deps-gcc-armv6-armv7 server-deps-gcc-arm64
  96. server-deps-static-sites:
  97. mkdir -p server/docs server/site
  98. touch server/docs/index.html server/site/app.html
  99. server-deps-all:
  100. which upx || { echo "ERROR: upx not installed. On Ubuntu, run: apt install upx"; exit 1; }
  101. server-deps-gcc-armv6-armv7:
  102. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  103. server-deps-gcc-arm64:
  104. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  105. # Test/check targets
  106. check: test fmt-check vet lint staticcheck
  107. test: .PHONY
  108. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  109. race: .PHONY
  110. go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  111. coverage:
  112. mkdir -p build/coverage
  113. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  114. go tool cover -func build/coverage/coverage.txt
  115. coverage-html:
  116. mkdir -p build/coverage
  117. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  118. go tool cover -html build/coverage/coverage.txt
  119. coverage-upload:
  120. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  121. # Lint/formatting targets
  122. fmt:
  123. gofmt -s -w .
  124. fmt-check:
  125. test -z $(shell gofmt -l .)
  126. vet:
  127. go vet ./...
  128. lint:
  129. which golint || go install golang.org/x/lint/golint@latest
  130. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  131. staticcheck: .PHONY
  132. rm -rf build/staticcheck
  133. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  134. mkdir -p build/staticcheck
  135. ln -s "go" build/staticcheck/go
  136. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  137. rm -rf build/staticcheck
  138. # Releasing targets
  139. release: release-deps
  140. goreleaser release --rm-dist --debug
  141. release-snapshot: release-deps
  142. goreleaser release --snapshot --skip-publish --rm-dist --debug
  143. release-deps: clean server-deps release-check-tags docs web check
  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_armv6/ntfy /usr/bin/ntfy
  159. install-armv7: remove-binary
  160. sudo cp -a dist/ntfy_armv7_linux_armv7/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-armv7-deb: purge-package
  168. sudo dpkg -i dist/ntfy_*_linux_armv7.deb
  169. install-arm64-deb: purge-package
  170. sudo dpkg -i dist/ntfy_*_linux_arm64.deb
  171. purge-package:
  172. sudo systemctl stop ntfy || true
  173. sudo apt-get purge ntfy || true