Makefile 7.2 KB

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