Makefile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. VERSION := $(shell git describe --tag)
  2. .PHONY:
  3. help:
  4. @echo "Typical commands:"
  5. @echo " make check - Run all tests, vetting/formatting checks and linters"
  6. @echo " make build-snapshot install - Build latest and install to local system"
  7. @echo
  8. @echo "Test/check:"
  9. @echo " make test - Run tests"
  10. @echo " make race - Run tests with -race flag"
  11. @echo " make coverage - Run tests and show coverage"
  12. @echo " make coverage-html - Run tests and show coverage (as HTML)"
  13. @echo " make coverage-upload - Upload coverage results to codecov.io"
  14. @echo
  15. @echo "Lint/format:"
  16. @echo " make fmt - Run 'go fmt'"
  17. @echo " make fmt-check - Run 'go fmt', but don't change anything"
  18. @echo " make vet - Run 'go vet'"
  19. @echo " make lint - Run 'golint'"
  20. @echo " make staticcheck - Run 'staticcheck'"
  21. @echo
  22. @echo "Build main client/server:"
  23. @echo " make build - Build (using goreleaser, requires clean repo)"
  24. @echo " make build-snapshot - Build snapshot (using goreleaser, dirty repo)"
  25. @echo " make build-simple - Quick & dirty build (using go build, without goreleaser)"
  26. @echo " make clean - Clean build folder"
  27. @echo
  28. @echo "Build web app:"
  29. @echo " make web - Build the web app"
  30. @echo " make web-deps - Install web app dependencies (npm install the universe)"
  31. @echo " make web-build - Actually build the web app"
  32. @echo
  33. @echo "Build documentation:"
  34. @echo " make docs - Build the documentation"
  35. @echo " make docs-deps - Install Python dependencies (pip3 install)"
  36. @echo " make docs-build - Actually build the documentation"
  37. @echo
  38. @echo "Releasing (requires goreleaser):"
  39. @echo " make release - Create a release"
  40. @echo " make release-snapshot - Create a test release"
  41. @echo
  42. @echo "Install locally (requires sudo):"
  43. @echo " make install - Copy binary from dist/ to /usr/bin"
  44. @echo " make install-deb - Install .deb from dist/"
  45. @echo " make install-lint - Install golint"
  46. # Documentation
  47. docs-deps: .PHONY
  48. pip3 install -r requirements.txt
  49. docs-build: .PHONY
  50. mkdocs build
  51. docs: docs-deps docs-build
  52. # Web app
  53. web-deps:
  54. cd web \
  55. && npm install \
  56. && node_modules/svgo/bin/svgo src/img/*.svg
  57. web-build:
  58. cd web \
  59. && npm run build \
  60. && mv build/index.html build/app.html \
  61. && rm -rf ../server/site \
  62. && mv build ../server/site \
  63. && rm \
  64. ../server/site/config.js \
  65. ../server/site/asset-manifest.json
  66. web: web-deps web-build
  67. # Test/check targets
  68. check: test fmt-check vet lint staticcheck
  69. test: .PHONY
  70. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  71. race: .PHONY
  72. go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  73. coverage:
  74. mkdir -p build/coverage
  75. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  76. go tool cover -func build/coverage/coverage.txt
  77. coverage-html:
  78. mkdir -p build/coverage
  79. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  80. go tool cover -html build/coverage/coverage.txt
  81. coverage-upload:
  82. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  83. # Lint/formatting targets
  84. fmt:
  85. gofmt -s -w .
  86. fmt-check:
  87. test -z $(shell gofmt -l .)
  88. vet:
  89. go vet ./...
  90. lint:
  91. which golint || go install golang.org/x/lint/golint@latest
  92. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  93. staticcheck: .PHONY
  94. rm -rf build/staticcheck
  95. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  96. mkdir -p build/staticcheck
  97. ln -s "go" build/staticcheck/go
  98. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  99. rm -rf build/staticcheck
  100. # Building targets
  101. build-deps: docs web
  102. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/v7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  103. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  104. build: build-deps
  105. goreleaser build --rm-dist --debug
  106. build-snapshot: build-deps
  107. goreleaser build --snapshot --rm-dist --debug
  108. build-simple: .PHONY
  109. mkdir -p dist/ntfy_linux_amd64 server/docs server/site
  110. touch server/docs/index.html
  111. touch server/site/app.html
  112. export CGO_ENABLED=1
  113. go build \
  114. -o dist/ntfy_linux_amd64/ntfy \
  115. -tags sqlite_omit_load_extension,osusergo,netgo \
  116. -ldflags \
  117. "-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)"
  118. clean: .PHONY
  119. rm -rf dist build server/docs server/site
  120. # Releasing targets
  121. release-check-tags:
  122. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  123. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  124. echo "ERROR: Must update docs/install.md with latest tag first.";\
  125. exit 1;\
  126. fi
  127. if grep -q XXXXX docs/releases.md; then\
  128. echo "ERROR: Must update docs/releases.md, found XXXXX.";\
  129. exit 1;\
  130. fi
  131. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  132. echo "ERROR: Must update docs/releases.mdwith latest tag first.";\
  133. exit 1;\
  134. fi
  135. release: build-deps release-check-tags check
  136. goreleaser release --rm-dist --debug
  137. release-snapshot: build-deps
  138. goreleaser release --snapshot --skip-publish --rm-dist --debug
  139. # Installing targets
  140. install:
  141. sudo rm -f /usr/bin/ntfy
  142. sudo cp -a dist/ntfy_linux_amd64/ntfy /usr/bin/ntfy
  143. install-deb:
  144. sudo systemctl stop ntfy || true
  145. sudo apt-get purge ntfy || true
  146. sudo dpkg -i dist/ntfy_*_linux_amd64.deb