Makefile 12 KB

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