Makefile 11 KB

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