MAKEFLAGS := --jobs=1 NPM := npm PYTHON := python3 PIP := pip3 VERSION := $(shell git describe --tag) COMMIT := $(shell git rev-parse --short HEAD) # FORCE is an always-out-of-date target with no recipe; listing it as a prerequisite # forces that target's recipe to run every time (the classic "FORCE target" idiom). FORCE: help: @echo "Typical commands (more see below):" @echo " make build - Build web app, documentation and server/client (sloowwww)" @echo " make cli-linux-amd64 - Build server/client binary (amd64, no web app or docs)" @echo " make install-linux-amd64 - Install ntfy binary to /usr/bin/ntfy (amd64)" @echo " make web - Build the web app" @echo " make docs - Build the documentation" @echo " make check - Run all tests, vetting/formatting checks and linters" @echo @echo "Build everything:" @echo " make build - Build web app, documentation and server/client" @echo " make clean - Clean build/dist folders" @echo @echo "Build server & client (using GoReleaser, not release version):" @echo " make cli - Build server & client (all architectures)" @echo " make cli-linux-amd64 - Build server & client (Linux, amd64 only)" @echo " make cli-linux-armv6 - Build server & client (Linux, armv6 only)" @echo " make cli-linux-armv7 - Build server & client (Linux, armv7 only)" @echo " make cli-linux-arm64 - Build server & client (Linux, arm64 only)" @echo " make cli-windows-amd64 - Build client (Windows, amd64 only)" @echo " make cli-darwin-all - Build client (macOS, arm64+amd64 universal binary)" @echo @echo "Build server & client (without GoReleaser):" @echo " make cli-linux-server - Build client & server (no GoReleaser, current arch, Linux)" @echo " make cli-darwin-server - Build client & server (no GoReleaser, current arch, macOS)" @echo " make cli-windows-server - Build client & server (no GoReleaser, amd64 only, Windows)" @echo " make cli-client - Build client only (no GoReleaser, current arch, Linux/macOS/Windows)" @echo @echo "Build dev Docker:" @echo " make docker-dev - Build client & server for current architecture using Docker only" @echo @echo "Build web app:" @echo " make web - Build the web app" @echo " make web-deps - Install web app dependencies (npm install the universe)" @echo " make web-build - Actually build the web app" @echo " make web-lint - Run eslint on the web app" @echo " make web-test - Run vitest unit tests for the web app" @echo " make web-fmt - Run prettier on the web app" @echo " make web-fmt-check - Run prettier on the web app, but don't change anything" @echo @echo "Build documentation:" @echo " make docs - Build the documentation" @echo " make docs-deps - Install Python dependencies (pip3 install)" @echo " make docs-build - Actually build the documentation" @echo @echo "Test/check:" @echo " make test - Run all tests (Go + web)" @echo " make cli-test - Run Go tests only" @echo " make web-test - Run web app tests only" @echo " make race - Run tests with -race flag" @echo " make coverage - Run tests and show coverage" @echo " make coverage-html - Run tests and show coverage (as HTML)" @echo " make coverage-upload - Upload coverage results to codecov.io" @echo @echo "Lint/format:" @echo " make fmt - Run 'go fmt'" @echo " make fmt-check - Run 'go fmt', but don't change anything" @echo " make vet - Run 'go vet'" @echo " make lint - Run 'golint'" @echo " make staticcheck - Run 'staticcheck'" @echo @echo "Releasing:" @echo " make release - Create a release" @echo " make release-snapshot - Create a test release" @echo @echo "Install locally (requires sudo):" @echo " make install-linux-amd64 - Copy amd64 binary from dist/ to /usr/bin/ntfy" @echo " make install-linux-armv6 - Copy armv6 binary from dist/ to /usr/bin/ntfy" @echo " make install-linux-armv7 - Copy armv7 binary from dist/ to /usr/bin/ntfy" @echo " make install-linux-arm64 - Copy arm64 binary from dist/ to /usr/bin/ntfy" @echo " make install-linux-deb-amd64 - Install .deb from dist/ (amd64 only)" @echo " make install-linux-deb-armv6 - Install .deb from dist/ (armv6 only)" @echo " make install-linux-deb-armv7 - Install .deb from dist/ (armv7 only)" @echo " make install-linux-deb-arm64 - Install .deb from dist/ (arm64 only)" # Building everything clean: FORCE rm -rf dist build server/docs server/site build: web docs cli update: web-deps-update cli-deps-update docs-deps-update go-check docker pull alpine docker-dev: docker build \ --file ./Dockerfile-build \ --tag binwiederhier/ntfy:$(VERSION) \ --tag binwiederhier/ntfy:dev \ --build-arg VERSION=$(VERSION) \ --build-arg COMMIT=$(COMMIT) \ ./ # Ubuntu-specific build-deps-ubuntu: sudo apt-get update sudo apt-get install -y \ curl \ gcc-aarch64-linux-gnu \ gcc-arm-linux-gnueabi \ gcc-mingw-w64-x86-64 \ python3 \ python3-venv \ jq which pip3 || sudo apt-get install -y python3-pip # Documentation docs: docs-deps docs-build docs-venv: FORCE $(PYTHON) -m venv ./venv docs-build: docs-venv (. venv/bin/activate && $(PYTHON) -m mkdocs build) docs-deps: docs-venv (. venv/bin/activate && $(PIP) install -r requirements.txt) docs-deps-update: FORCE (. venv/bin/activate && $(PIP) install -r requirements.txt --upgrade) # Web app web: web-deps web-build web-build: cd web \ && $(NPM) run build \ && mv build/index.html build/app.html \ && rm -rf ../server/site \ && mv build ../server/site \ && rm \ ../server/site/config.js web-deps: cd web && $(NPM) ci # Use "npm ci" so that we don't change the package lock file # If this fails for .svg files, optimize them with svgo web-deps-update: cd web && $(NPM) update --before="$(shell date -d '7 days ago' +%Y-%m-%d)" cd web && $(NPM) install web-fmt: cd web && $(NPM) run format web-fmt-check: cd web && $(NPM) run format:check web-lint: cd web && $(NPM) run lint web-test: cd web && $(NPM) run test # Main server/client build cli: cli-deps goreleaser build --snapshot --clean cli-linux-amd64: cli-deps-static-sites goreleaser build --snapshot --clean --id ntfy_linux_amd64 cli-linux-armv6: cli-deps-static-sites cli-deps-gcc-armv6-armv7 goreleaser build --snapshot --clean --id ntfy_linux_armv6 cli-linux-armv7: cli-deps-static-sites cli-deps-gcc-armv6-armv7 goreleaser build --snapshot --clean --id ntfy_linux_armv7 cli-linux-arm64: cli-deps-static-sites cli-deps-gcc-arm64 goreleaser build --snapshot --clean --id ntfy_linux_arm64 cli-windows-amd64: cli-deps-static-sites goreleaser build --snapshot --clean --id ntfy_windows_amd64 cli-darwin-all: cli-deps-static-sites goreleaser build --snapshot --clean --id ntfy_darwin_all cli-linux-server: cli-deps-static-sites # This is a target to build the CLI (including the server) manually. # Use this for development, if you really don't want to install GoReleaser ... mkdir -p dist/ntfy_linux_server server/docs CGO_ENABLED=1 go build \ -o dist/ntfy_linux_server/ntfy \ -tags sqlite_omit_load_extension,osusergo,netgo \ -ldflags \ "-linkmode=external -extldflags=-static -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)" cli-darwin-server: cli-deps-static-sites # This is a target to build the CLI (including the server) manually. # Use this for macOS/iOS development, so you have a local server to test with. mkdir -p dist/ntfy_darwin_server server/docs CGO_ENABLED=1 go build \ -o dist/ntfy_darwin_server/ntfy \ -tags sqlite_omit_load_extension,osusergo,netgo \ -ldflags \ "-linkmode=external -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)" cli-windows-server: cli-deps-static-sites # This is a target to build the CLI (including the server) for Windows. # Use this for Windows development, if you really don't want to install GoReleaser ... mkdir -p dist/ntfy_windows_server server/docs CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build \ -o dist/ntfy_windows_server/ntfy.exe \ -tags sqlite_omit_load_extension,osusergo,netgo \ -ldflags \ "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)" cli-client: cli-deps-static-sites # This is a target to build the CLI (excluding the server) manually. This should work on Linux/macOS/Windows. # Use this for development, if you really don't want to install GoReleaser ... mkdir -p dist/ntfy_client server/docs CGO_ENABLED=0 go build \ -o dist/ntfy_client/ntfy \ -tags noserver \ -ldflags \ "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(shell date +%s)" cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64 cli-deps-gcc-windows cli-deps-static-sites: mkdir -p server/docs server/site touch server/docs/index.html server/site/app.html cli-deps-all: go install github.com/goreleaser/goreleaser/v2@latest cli-deps-gcc-armv6-armv7: which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; } cli-deps-gcc-arm64: which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; } cli-deps-gcc-windows: which x86_64-w64-mingw32-gcc || { echo "ERROR: Windows cross compiler not installed. On Ubuntu, run: apt install gcc-mingw-w64-x86-64"; exit 1; } cli-deps-update: go get -u go mod tidy go install honnef.co/go/tools/cmd/staticcheck@latest go install golang.org/x/lint/golint@latest go install github.com/goreleaser/goreleaser/v2@latest cli-build-results: cat dist/config.yaml [ -f dist/artifacts.json ] && cat dist/artifacts.json | jq . || true [ -f dist/metadata.json ] && cat dist/metadata.json | jq . || true [ -f dist/checksums.txt ] && cat dist/checksums.txt || true find dist -maxdepth 2 -type f \ \( -name '*.deb' -or -name '*.rpm' -or -name '*.zip' -or -name '*.tar.gz' -or -name 'ntfy' \) \ -and -not -path 'dist/goreleaserdocker*' \ -exec sha256sum {} \; # Test/check targets check: test web-fmt-check fmt-check vet web-lint lint staticcheck template-check go-check checkv: testv web-fmt-check fmt-check vet web-lint lint staticcheck template-check go-check test: cli-test web-test testv: cli-testv web-test cli-test: FORCE go test $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./... | grep -vE 'ntfy/v2/(test|examples|tools)') cli-testv: FORCE go test -v $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./... | grep -vE 'ntfy/v2/(test|examples|tools)') race: FORCE go test -v -race $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./... | grep -vE 'ntfy/v2/(test|examples|tools)') coverage: mkdir -p build/coverage go test -v -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./... | grep -vE 'ntfy/v2/(test|examples|tools|web)') go tool cover -func build/coverage/coverage.txt coverage-html: mkdir -p build/coverage go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./... | grep -vE 'ntfy/v2/(test|examples|tools)') go tool cover -html build/coverage/coverage.txt coverage-upload: cd build/coverage && (curl -s https://codecov.io/bash | bash) # Lint/formatting targets fmt: web-fmt gofmt -s -w . fmt-check: test -z $(shell gofmt -l .) vet: go vet ./... lint: which golint || go install golang.org/x/lint/golint@latest go list ./... | grep -v /vendor/ | grep -vE 'ntfy/v2/template/gotext' | xargs -L1 golint -set_exit_status staticcheck: FORCE rm -rf build/staticcheck which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest mkdir -p build/staticcheck ln -s "go" build/staticcheck/go PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck $$(go list ./... | grep -vE 'ntfy/v2/template/gotext') rm -rf build/staticcheck # Vendored template targets (see template/README.md) TEMPLATE_GO_VERSION := go$(shell cat .go-version 2>/dev/null) update-template: @if [ "$$(go env GOVERSION)" != "$(TEMPLATE_GO_VERSION)" ]; then \ echo "ERROR: local Go $$(go env GOVERSION) != $(TEMPLATE_GO_VERSION) pinned in .go-version."; \ echo "Bump .go-version and install that toolchain first: go install golang.org/dl/$(TEMPLATE_GO_VERSION)@latest && $(TEMPLATE_GO_VERSION) download"; \ exit 1; \ fi src="$$(go env GOROOT)/src"; \ rm -f template/gotext/*.go template/gotext/fmtsort/*.go; \ for f in $$(go list -f '{{range .GoFiles}}{{.}} {{end}}' text/template); do cp "$$src/text/template/$$f" template/gotext/; done; \ for f in $$(go list -f '{{range .GoFiles}}{{.}} {{end}}' internal/fmtsort); do cp "$$src/internal/fmtsort/$$f" template/gotext/fmtsort/; done; \ sed -i 's/^package template$$/package gotext/' template/gotext/*.go; \ sed -i 's#"internal/fmtsort"#"heckel.io/ntfy/v2/template/gotext/fmtsort"#' template/gotext/*.go; \ ( cd template/gotext && for p in patches/*.patch; do echo "Applying $$p"; git apply "$$p" || exit 1; done ) go env GOVERSION > template/gotext/GENERATED_FROM @echo "Regenerated template/gotext/ from $(TEMPLATE_GO_VERSION) (files enumerated via 'go list'); review with 'git diff'." template-check: FORCE @if [ "$$(cat template/gotext/GENERATED_FROM)" != "$(TEMPLATE_GO_VERSION)" ]; then \ echo "ERROR: template/gotext was generated from $$(cat template/gotext/GENERATED_FROM), but .go-version pins $(TEMPLATE_GO_VERSION). Run 'make update-template' on the pinned Go."; \ exit 1; \ fi @if [ "$$(go env GOVERSION)" != "$(TEMPLATE_GO_VERSION)" ]; then \ echo "SKIP: local Go $$(go env GOVERSION) != pinned $(TEMPLATE_GO_VERSION); skipping vendored template content check (version marker already verified)."; \ exit 0; \ fi @tmp=$$(mktemp -d); src="$$(go env GOROOT)/src"; \ mkdir -p "$$tmp/gotext/fmtsort"; \ for f in $$(go list -f '{{range .GoFiles}}{{.}} {{end}}' text/template); do cp "$$src/text/template/$$f" "$$tmp/gotext/"; done; \ for f in $$(go list -f '{{range .GoFiles}}{{.}} {{end}}' internal/fmtsort); do cp "$$src/internal/fmtsort/$$f" "$$tmp/gotext/fmtsort/"; done; \ sed -i 's/^package template$$/package gotext/' "$$tmp/gotext/"*.go; \ sed -i 's#"internal/fmtsort"#"heckel.io/ntfy/v2/template/gotext/fmtsort"#' "$$tmp/gotext/"*.go; \ cp template/gotext/patches/*.patch "$$tmp/"; \ ( cd "$$tmp/gotext" && for p in "$$tmp"/*.patch; do git apply "$$p" || exit 1; done ); \ if diff -rq -x 'README.md' -x 'GENERATED_FROM' -x 'patches' "$$tmp/gotext" template/gotext >/dev/null 2>&1; then \ rm -rf "$$tmp"; \ else \ echo "ERROR: template/gotext/ drifted from GOROOT+patches (or its file set changed). Run 'make update-template' on Go $(TEMPLATE_GO_VERSION):"; \ diff -rq -x 'README.md' -x 'GENERATED_FROM' -x 'patches' "$$tmp/gotext" template/gotext; \ rm -rf "$$tmp"; exit 1; \ fi # go-check is advisory only (never fails): it warns when the pinned Go (.go-version) is behind the # latest upstream release, so template/gotext doesn't silently fall behind on text/template fixes. go-check: FORCE @latest=$$(curl -s --max-time 10 'https://go.dev/VERSION?m=text' 2>/dev/null | head -1); \ if [ -n "$$latest" ] && [ "$$latest" != "$(TEMPLATE_GO_VERSION)" ]; then \ echo ""; \ echo "note: latest Go is $$latest, but template/gotext is pinned to $(TEMPLATE_GO_VERSION) (.go-version)."; \ echo " to bump: install $$latest, set .go-version to $${latest#go}, then run 'make update-template'."; \ fi # Releasing targets release: clean cli-deps release-checks docs web check goreleaser release --clean release-snapshot: clean cli-deps docs web check goreleaser release --snapshot --clean release-checks: $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-)) if [ "$$(go env GOVERSION)" != "go$$(cat .go-version)" ]; then\ echo "ERROR: releases must use the pinned Go toolchain (go$$(cat .go-version) from .go-version), but this is $$(go env GOVERSION). This also ensures 'make check' enforces (not skips) the template/gotext drift check.";\ exit 1;\ fi if ! grep -q $(LATEST_TAG) docs/install.md; then\ echo "ERROR: Must update docs/install.md with latest tag first.";\ exit 1;\ fi if ! grep -q $(LATEST_TAG) docs/releases.md; then\ echo "ERROR: Must update docs/releases.md with latest tag first.";\ exit 1;\ fi if [ -n "$(shell git status -s)" ]; then\ echo "ERROR: Git repository is in an unclean state.";\ exit 1;\ fi # Installing targets install-linux-amd64: remove-binary sudo cp -a dist/ntfy_linux_amd64_linux_amd64_v1/ntfy /usr/bin/ntfy install-linux-armv6: remove-binary sudo cp -a dist/ntfy_linux_armv6_linux_arm_6/ntfy /usr/bin/ntfy install-linux-armv7: remove-binary sudo cp -a dist/ntfy_linux_armv7_linux_arm_7/ntfy /usr/bin/ntfy install-linux-arm64: remove-binary sudo cp -a dist/ntfy_linux_arm64_linux_arm64/ntfy /usr/bin/ntfy remove-binary: sudo rm -f /usr/bin/ntfy install-linux-amd64-deb: purge-package sudo dpkg -i dist/ntfy_*_linux_amd64.deb install-linux-armv6-deb: purge-package sudo dpkg -i dist/ntfy_*_linux_armv6.deb install-linux-armv7-deb: purge-package sudo dpkg -i dist/ntfy_*_linux_armv7.deb install-linux-arm64-deb: purge-package sudo dpkg -i dist/ntfy_*_linux_arm64.deb purge-package: sudo systemctl stop ntfy || true sudo apt-get purge ntfy || true