Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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-fmt - Run prettier on the web app"
  41. @echo " make web-fmt-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. python3 \
  97. python3-venv \
  98. jq
  99. which pip3 || sudo apt-get install -y python3-pip
  100. # Documentation
  101. docs: docs-deps docs-build
  102. docs-venv: .PHONY
  103. python3 -m venv ./venv
  104. docs-build: docs-venv
  105. (. venv/bin/activate && mkdocs build)
  106. docs-deps: docs-venv
  107. (. venv/bin/activate && pip3 install -r requirements.txt)
  108. docs-deps-update: .PHONY
  109. (. venv/bin/activate && pip3 install -r requirements.txt --upgrade)
  110. # Web app
  111. web: web-deps web-build
  112. web-build:
  113. cd web \
  114. && npm run build \
  115. && mv build/index.html build/app.html \
  116. && rm -rf ../server/site \
  117. && mv build ../server/site \
  118. && rm \
  119. ../server/site/config.js
  120. web-deps:
  121. cd web && npm install
  122. # If this fails for .svg files, optimize them with svgo
  123. web-deps-update:
  124. cd web && npm update
  125. web-fmt:
  126. cd web && npm run format
  127. web-fmt-check:
  128. cd web && npm run format:check
  129. web-lint:
  130. cd web && npm run lint
  131. # Main server/client build
  132. cli: cli-deps
  133. goreleaser build --snapshot --clean
  134. cli-linux-amd64: cli-deps-static-sites
  135. goreleaser build --snapshot --clean --id ntfy_linux_amd64
  136. cli-linux-armv6: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  137. goreleaser build --snapshot --clean --id ntfy_linux_armv6
  138. cli-linux-armv7: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  139. goreleaser build --snapshot --clean --id ntfy_linux_armv7
  140. cli-linux-arm64: cli-deps-static-sites cli-deps-gcc-arm64
  141. goreleaser build --snapshot --clean --id ntfy_linux_arm64
  142. cli-windows-amd64: cli-deps-static-sites
  143. goreleaser build --snapshot --clean --id ntfy_windows_amd64
  144. cli-darwin-all: cli-deps-static-sites
  145. goreleaser build --snapshot --clean --id ntfy_darwin_all
  146. cli-linux-server: cli-deps-static-sites
  147. # This is a target to build the CLI (including the server) manually.
  148. # Use this for development, if you really don't want to install GoReleaser ...
  149. mkdir -p dist/ntfy_linux_server server/docs
  150. CGO_ENABLED=1 go build \
  151. -o dist/ntfy_linux_server/ntfy \
  152. -tags sqlite_omit_load_extension,osusergo,netgo \
  153. -ldflags \
  154. "-linkmode=external -extldflags=-static -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)"
  155. cli-darwin-server: cli-deps-static-sites
  156. # This is a target to build the CLI (including the server) manually.
  157. # Use this for macOS/iOS development, so you have a local server to test with.
  158. mkdir -p dist/ntfy_darwin_server server/docs
  159. CGO_ENABLED=1 go build \
  160. -o dist/ntfy_darwin_server/ntfy \
  161. -tags sqlite_omit_load_extension,osusergo,netgo \
  162. -ldflags \
  163. "-linkmode=external -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)"
  164. cli-client: cli-deps-static-sites
  165. # This is a target to build the CLI (excluding the server) manually. This should work on Linux/macOS/Windows.
  166. # Use this for development, if you really don't want to install GoReleaser ...
  167. mkdir -p dist/ntfy_client server/docs
  168. CGO_ENABLED=0 go build \
  169. -o dist/ntfy_client/ntfy \
  170. -tags noserver \
  171. -ldflags \
  172. "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)"
  173. cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc
  174. cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64
  175. cli-deps-static-sites:
  176. mkdir -p server/docs server/site
  177. touch server/docs/index.html server/site/app.html
  178. cli-deps-all:
  179. go install github.com/goreleaser/goreleaser@latest
  180. cli-deps-gcc-armv6-armv7:
  181. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  182. cli-deps-gcc-arm64:
  183. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  184. cli-deps-update:
  185. go get -u
  186. go install honnef.co/go/tools/cmd/staticcheck@latest
  187. go install golang.org/x/lint/golint@latest
  188. go install github.com/goreleaser/goreleaser@latest
  189. cli-build-results:
  190. cat dist/config.yaml
  191. [ -f dist/artifacts.json ] && cat dist/artifacts.json | jq . || true
  192. [ -f dist/metadata.json ] && cat dist/metadata.json | jq . || true
  193. [ -f dist/checksums.txt ] && cat dist/checksums.txt || true
  194. find dist -maxdepth 2 -type f \
  195. \( -name '*.deb' -or -name '*.rpm' -or -name '*.zip' -or -name '*.tar.gz' -or -name 'ntfy' \) \
  196. -and -not -path 'dist/goreleaserdocker*' \
  197. -exec sha256sum {} \;
  198. # Test/check targets
  199. check: test web-fmt-check fmt-check vet web-lint lint staticcheck
  200. test: .PHONY
  201. go test $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  202. testv: .PHONY
  203. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  204. race: .PHONY
  205. go test -v -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  206. coverage:
  207. mkdir -p build/coverage
  208. go test -v -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  209. go tool cover -func build/coverage/coverage.txt
  210. coverage-html:
  211. mkdir -p build/coverage
  212. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  213. go tool cover -html build/coverage/coverage.txt
  214. coverage-upload:
  215. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  216. # Lint/formatting targets
  217. fmt: web-fmt
  218. gofmt -s -w .
  219. fmt-check:
  220. test -z $(shell gofmt -l .)
  221. vet:
  222. go vet ./...
  223. lint:
  224. which golint || go install golang.org/x/lint/golint@latest
  225. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  226. staticcheck: .PHONY
  227. rm -rf build/staticcheck
  228. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  229. mkdir -p build/staticcheck
  230. ln -s "go" build/staticcheck/go
  231. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  232. rm -rf build/staticcheck
  233. # Releasing targets
  234. release: clean cli-deps release-checks docs web check
  235. goreleaser release --clean
  236. release-snapshot: clean cli-deps docs web check
  237. goreleaser release --snapshot --skip-publish --clean
  238. release-checks:
  239. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  240. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  241. echo "ERROR: Must update docs/install.md with latest tag first.";\
  242. exit 1;\
  243. fi
  244. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  245. echo "ERROR: Must update docs/releases.md with latest tag first.";\
  246. exit 1;\
  247. fi
  248. if [ -n "$(shell git status -s)" ]; then\
  249. echo "ERROR: Git repository is in an unclean state.";\
  250. exit 1;\
  251. fi
  252. # Installing targets
  253. install-linux-amd64: remove-binary
  254. sudo cp -a dist/ntfy_linux_amd64_linux_amd64_v1/ntfy /usr/bin/ntfy
  255. install-linux-armv6: remove-binary
  256. sudo cp -a dist/ntfy_linux_armv6_linux_arm_6/ntfy /usr/bin/ntfy
  257. install-linux-armv7: remove-binary
  258. sudo cp -a dist/ntfy_linux_armv7_linux_arm_7/ntfy /usr/bin/ntfy
  259. install-linux-arm64: remove-binary
  260. sudo cp -a dist/ntfy_linux_arm64_linux_arm64/ntfy /usr/bin/ntfy
  261. remove-binary:
  262. sudo rm -f /usr/bin/ntfy
  263. install-linux-amd64-deb: purge-package
  264. sudo dpkg -i dist/ntfy_*_linux_amd64.deb
  265. install-linux-armv6-deb: purge-package
  266. sudo dpkg -i dist/ntfy_*_linux_armv6.deb
  267. install-linux-armv7-deb: purge-package
  268. sudo dpkg -i dist/ntfy_*_linux_armv7.deb
  269. install-linux-arm64-deb: purge-package
  270. sudo dpkg -i dist/ntfy_*_linux_arm64.deb
  271. purge-package:
  272. sudo systemctl stop ntfy || true
  273. sudo apt-get purge ntfy || true