Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. MAKEFLAGS := --jobs=1
  2. VERSION := $(shell git describe --tag)
  3. COMMIT := $(shell git rev-parse --short HEAD)
  4. .PHONY:
  5. help:
  6. @echo "Typical commands (more see below):"
  7. @echo " make build - Build web app, documentation and server/client (sloowwww)"
  8. @echo " make cli-linux-amd64 - Build server/client binary (amd64, no web app or docs)"
  9. @echo " make install-linux-amd64 - Install ntfy binary to /usr/bin/ntfy (amd64)"
  10. @echo " make web - Build the web app"
  11. @echo " make docs - Build the documentation"
  12. @echo " make check - Run all tests, vetting/formatting checks and linters"
  13. @echo
  14. @echo "Build everything:"
  15. @echo " make build - Build web app, documentation and server/client"
  16. @echo " make clean - Clean build/dist folders"
  17. @echo
  18. @echo "Build server & client (using GoReleaser, not release version):"
  19. @echo " make cli - Build server & client (all architectures)"
  20. @echo " make cli-linux-amd64 - Build server & client (Linux, amd64 only)"
  21. @echo " make cli-linux-armv6 - Build server & client (Linux, armv6 only)"
  22. @echo " make cli-linux-armv7 - Build server & client (Linux, armv7 only)"
  23. @echo " make cli-linux-arm64 - Build server & client (Linux, arm64 only)"
  24. @echo " make cli-windows-amd64 - Build client (Windows, amd64 only)"
  25. @echo " make cli-darwin-all - Build client (macOS, arm64+amd64 universal binary)"
  26. @echo
  27. @echo "Build server & client (without GoReleaser):"
  28. @echo " make cli-linux-server - Build client & server (no GoReleaser, current arch, Linux)"
  29. @echo " make cli-darwin-server - Build client & server (no GoReleaser, current arch, macOS)"
  30. @echo " make cli-client - Build client only (no GoReleaser, current arch, Linux/macOS/Windows)"
  31. @echo
  32. @echo "Build web app:"
  33. @echo " make web - Build the web app"
  34. @echo " make web-deps - Install web app dependencies (npm install the universe)"
  35. @echo " make web-build - Actually build the web app"
  36. @echo " make web-format - Run prettier on the web app
  37. @echo " make web-format-check - Run prettier on the web app, but don't change anything
  38. @echo
  39. @echo "Build documentation:"
  40. @echo " make docs - Build the documentation"
  41. @echo " make docs-deps - Install Python dependencies (pip3 install)"
  42. @echo " make docs-build - Actually build the documentation"
  43. @echo
  44. @echo "Test/check:"
  45. @echo " make test - Run tests"
  46. @echo " make race - Run tests with -race flag"
  47. @echo " make coverage - Run tests and show coverage"
  48. @echo " make coverage-html - Run tests and show coverage (as HTML)"
  49. @echo " make coverage-upload - Upload coverage results to codecov.io"
  50. @echo
  51. @echo "Lint/format:"
  52. @echo " make fmt - Run 'go fmt'"
  53. @echo " make fmt-check - Run 'go fmt', but don't change anything"
  54. @echo " make vet - Run 'go vet'"
  55. @echo " make lint - Run 'golint'"
  56. @echo " make staticcheck - Run 'staticcheck'"
  57. @echo
  58. @echo "Releasing:"
  59. @echo " make release - Create a release"
  60. @echo " make release-snapshot - Create a test release"
  61. @echo
  62. @echo "Install locally (requires sudo):"
  63. @echo " make install-linux-amd64 - Copy amd64 binary from dist/ to /usr/bin/ntfy"
  64. @echo " make install-linux-armv6 - Copy armv6 binary from dist/ to /usr/bin/ntfy"
  65. @echo " make install-linux-armv7 - Copy armv7 binary from dist/ to /usr/bin/ntfy"
  66. @echo " make install-linux-arm64 - Copy arm64 binary from dist/ to /usr/bin/ntfy"
  67. @echo " make install-linux-deb-amd64 - Install .deb from dist/ (amd64 only)"
  68. @echo " make install-linux-deb-armv6 - Install .deb from dist/ (armv6 only)"
  69. @echo " make install-linux-deb-armv7 - Install .deb from dist/ (armv7 only)"
  70. @echo " make install-linux-deb-arm64 - Install .deb from dist/ (arm64 only)"
  71. # Building everything
  72. clean: .PHONY
  73. rm -rf dist build server/docs server/site
  74. build: web docs cli
  75. update: web-deps-update cli-deps-update docs-deps-update
  76. docker pull alpine
  77. # Ubuntu-specific
  78. build-deps-ubuntu:
  79. sudo apt update
  80. sudo apt install -y \
  81. curl \
  82. gcc-aarch64-linux-gnu \
  83. gcc-arm-linux-gnueabi \
  84. jq
  85. which pip3 || sudo apt install -y python3-pip
  86. # Documentation
  87. docs: docs-deps docs-build
  88. docs-build: .PHONY
  89. @if ! /bin/echo -e "import sys\nif sys.version_info < (3,8):\n exit(1)" | python3; then \
  90. if which python3.8; then \
  91. echo "python3.8 $(shell which mkdocs) build"; \
  92. python3.8 $(shell which mkdocs) build; \
  93. else \
  94. echo "ERROR: Python version too low. mkdocs-material needs >= 3.8"; \
  95. exit 1; \
  96. fi; \
  97. else \
  98. echo "mkdocs build"; \
  99. mkdocs build; \
  100. fi
  101. docs-deps: .PHONY
  102. pip3 install -r requirements.txt
  103. docs-deps-update: .PHONY
  104. pip3 install -r requirements.txt --upgrade
  105. # Web app
  106. web: web-deps web-build
  107. web-build:
  108. cd web \
  109. && npm run build \
  110. && mv build/index.html build/app.html \
  111. && rm -rf ../server/site \
  112. && mv build ../server/site \
  113. && rm \
  114. ../server/site/config.js
  115. web-deps:
  116. cd web && npm install
  117. # If this fails for .svg files, optimize them with svgo
  118. web-deps-update:
  119. cd web && npm update
  120. web-format:
  121. cd web && npm run format
  122. web-format-check:
  123. cd web && npm run format:check
  124. web-lint:
  125. cd web && npm run lint
  126. # Main server/client build
  127. cli: cli-deps
  128. goreleaser build --snapshot --clean
  129. cli-linux-amd64: cli-deps-static-sites
  130. goreleaser build --snapshot --clean --id ntfy_linux_amd64
  131. cli-linux-armv6: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  132. goreleaser build --snapshot --clean --id ntfy_linux_armv6
  133. cli-linux-armv7: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  134. goreleaser build --snapshot --clean --id ntfy_linux_armv7
  135. cli-linux-arm64: cli-deps-static-sites cli-deps-gcc-arm64
  136. goreleaser build --snapshot --clean --id ntfy_linux_arm64
  137. cli-windows-amd64: cli-deps-static-sites
  138. goreleaser build --snapshot --clean --id ntfy_windows_amd64
  139. cli-darwin-all: cli-deps-static-sites
  140. goreleaser build --snapshot --clean --id ntfy_darwin_all
  141. cli-linux-server: cli-deps-static-sites
  142. # This is a target to build the CLI (including the server) manually.
  143. # Use this for development, if you really don't want to install GoReleaser ...
  144. mkdir -p dist/ntfy_linux_server server/docs
  145. CGO_ENABLED=1 go build \
  146. -o dist/ntfy_linux_server/ntfy \
  147. -tags sqlite_omit_load_extension,osusergo,netgo \
  148. -ldflags \
  149. "-linkmode=external -extldflags=-static -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)"
  150. cli-darwin-server: cli-deps-static-sites
  151. # This is a target to build the CLI (including the server) manually.
  152. # Use this for macOS/iOS development, so you have a local server to test with.
  153. mkdir -p dist/ntfy_darwin_server server/docs
  154. CGO_ENABLED=1 go build \
  155. -o dist/ntfy_darwin_server/ntfy \
  156. -tags sqlite_omit_load_extension,osusergo,netgo \
  157. -ldflags \
  158. "-linkmode=external -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)"
  159. cli-client: cli-deps-static-sites
  160. # This is a target to build the CLI (excluding the server) manually. This should work on Linux/macOS/Windows.
  161. # Use this for development, if you really don't want to install GoReleaser ...
  162. mkdir -p dist/ntfy_client server/docs
  163. CGO_ENABLED=0 go build \
  164. -o dist/ntfy_client/ntfy \
  165. -tags noserver \
  166. -ldflags \
  167. "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)"
  168. cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc
  169. cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64
  170. cli-deps-static-sites:
  171. mkdir -p server/docs server/site
  172. touch server/docs/index.html server/site/app.html
  173. cli-deps-all:
  174. go install github.com/goreleaser/goreleaser@latest
  175. cli-deps-gcc-armv6-armv7:
  176. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  177. cli-deps-gcc-arm64:
  178. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  179. cli-deps-update:
  180. go get -u
  181. go install honnef.co/go/tools/cmd/staticcheck@latest
  182. go install golang.org/x/lint/golint@latest
  183. go install github.com/goreleaser/goreleaser@latest
  184. cli-build-results:
  185. cat dist/config.yaml
  186. [ -f dist/artifacts.json ] && cat dist/artifacts.json | jq . || true
  187. [ -f dist/metadata.json ] && cat dist/metadata.json | jq . || true
  188. [ -f dist/checksums.txt ] && cat dist/checksums.txt || true
  189. find dist -maxdepth 2 -type f \
  190. \( -name '*.deb' -or -name '*.rpm' -or -name '*.zip' -or -name '*.tar.gz' -or -name 'ntfy' \) \
  191. -and -not -path 'dist/goreleaserdocker*' \
  192. -exec sha256sum {} \;
  193. # Test/check targets
  194. check: test web-format-check fmt-check vet web-lint lint staticcheck
  195. test: .PHONY
  196. go test $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  197. testv: .PHONY
  198. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  199. race: .PHONY
  200. go test -v -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  201. coverage:
  202. mkdir -p build/coverage
  203. go test -v -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  204. go tool cover -func build/coverage/coverage.txt
  205. coverage-html:
  206. mkdir -p build/coverage
  207. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  208. go tool cover -html build/coverage/coverage.txt
  209. coverage-upload:
  210. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  211. # Lint/formatting targets
  212. fmt:
  213. gofmt -s -w .
  214. fmt-check:
  215. test -z $(shell gofmt -l .)
  216. vet:
  217. go vet ./...
  218. lint:
  219. which golint || go install golang.org/x/lint/golint@latest
  220. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  221. staticcheck: .PHONY
  222. rm -rf build/staticcheck
  223. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  224. mkdir -p build/staticcheck
  225. ln -s "go" build/staticcheck/go
  226. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  227. rm -rf build/staticcheck
  228. # Releasing targets
  229. release: clean cli-deps release-checks docs web check
  230. goreleaser release --clean
  231. release-snapshot: clean cli-deps docs web check
  232. goreleaser release --snapshot --skip-publish --clean
  233. release-checks:
  234. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  235. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  236. echo "ERROR: Must update docs/install.md with latest tag first.";\
  237. exit 1;\
  238. fi
  239. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  240. echo "ERROR: Must update docs/releases.md with latest tag first.";\
  241. exit 1;\
  242. fi
  243. if [ -n "$(shell git status -s)" ]; then\
  244. echo "ERROR: Git repository is in an unclean state.";\
  245. exit 1;\
  246. fi
  247. # Installing targets
  248. install-linux-amd64: remove-binary
  249. sudo cp -a dist/ntfy_linux_amd64_linux_amd64_v1/ntfy /usr/bin/ntfy
  250. install-linux-armv6: remove-binary
  251. sudo cp -a dist/ntfy_linux_armv6_linux_arm_6/ntfy /usr/bin/ntfy
  252. install-linux-armv7: remove-binary
  253. sudo cp -a dist/ntfy_linux_armv7_linux_arm_7/ntfy /usr/bin/ntfy
  254. install-linux-arm64: remove-binary
  255. sudo cp -a dist/ntfy_linux_arm64_linux_arm64/ntfy /usr/bin/ntfy
  256. remove-binary:
  257. sudo rm -f /usr/bin/ntfy
  258. install-linux-amd64-deb: purge-package
  259. sudo dpkg -i dist/ntfy_*_linux_amd64.deb
  260. install-linux-armv6-deb: purge-package
  261. sudo dpkg -i dist/ntfy_*_linux_armv6.deb
  262. install-linux-armv7-deb: purge-package
  263. sudo dpkg -i dist/ntfy_*_linux_armv7.deb
  264. install-linux-arm64-deb: purge-package
  265. sudo dpkg -i dist/ntfy_*_linux_arm64.deb
  266. purge-package:
  267. sudo systemctl stop ntfy || true
  268. sudo apt-get purge ntfy || true