Makefile 12 KB

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