2021-10-24 03:29:45 +02:00
|
|
|
VERSION := $(shell git describe --tag)
|
|
|
|
|
|
|
|
.PHONY:
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo "Typical commands:"
|
|
|
|
@echo " make check - Run all tests, vetting/formatting checks and linters"
|
|
|
|
@echo " make fmt build-snapshot install - Build latest and install to local system"
|
|
|
|
@echo
|
|
|
|
@echo "Test/check:"
|
|
|
|
@echo " make test - Run tests"
|
|
|
|
@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 "Build:"
|
|
|
|
@echo " make build - Build"
|
|
|
|
@echo " make build-snapshot - Build snapshot"
|
|
|
|
@echo " make build-simple - Build (using go build, without goreleaser)"
|
|
|
|
@echo " make clean - Clean build folder"
|
|
|
|
@echo
|
|
|
|
@echo "Releasing (requires goreleaser):"
|
|
|
|
@echo " make release - Create a release"
|
|
|
|
@echo " make release-snapshot - Create a test release"
|
|
|
|
@echo
|
|
|
|
@echo "Install locally (requires sudo):"
|
|
|
|
@echo " make install - Copy binary from dist/ to /usr/bin"
|
|
|
|
@echo " make install-deb - Install .deb from dist/"
|
|
|
|
@echo " make install-lint - Install golint"
|
|
|
|
|
|
|
|
|
2021-12-07 18:23:42 +01:00
|
|
|
# Documentation
|
2022-03-06 03:15:40 +01:00
|
|
|
|
2021-12-07 19:37:01 +01:00
|
|
|
docs-deps: .PHONY
|
|
|
|
pip3 install -r requirements.txt
|
|
|
|
|
|
|
|
docs: docs-deps
|
2021-12-07 18:23:42 +01:00
|
|
|
mkdocs build
|
|
|
|
|
2022-03-06 02:24:10 +01:00
|
|
|
|
|
|
|
# Web app
|
|
|
|
|
|
|
|
web-deps:
|
|
|
|
cd web && npm install
|
|
|
|
|
|
|
|
web-build:
|
|
|
|
cd web \
|
|
|
|
&& npm run build \
|
|
|
|
&& mv build/index.html build/app.html \
|
|
|
|
&& rm -rf ../server/site \
|
|
|
|
&& mv build ../server/site \
|
|
|
|
&& rm \
|
2022-03-10 05:28:55 +01:00
|
|
|
../server/site/config.js \
|
2022-03-06 02:24:10 +01:00
|
|
|
../server/site/precache* \
|
|
|
|
../server/site/service-worker.js \
|
|
|
|
../server/site/asset-manifest.json \
|
|
|
|
../server/site/static/js/*.js.map \
|
|
|
|
../server/site/static/js/*.js.LICENSE.txt
|
|
|
|
|
|
|
|
web: web-deps web-build
|
|
|
|
|
|
|
|
|
2021-10-24 03:29:45 +02:00
|
|
|
# Test/check targets
|
|
|
|
|
|
|
|
check: test fmt-check vet lint staticcheck
|
|
|
|
|
|
|
|
test: .PHONY
|
2021-12-22 23:20:43 +01:00
|
|
|
go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
race: .PHONY
|
2021-12-22 23:20:43 +01:00
|
|
|
go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
coverage:
|
|
|
|
mkdir -p build/coverage
|
2021-12-22 23:20:43 +01:00
|
|
|
go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
|
|
|
|
go tool cover -func build/coverage/coverage.txt
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
coverage-html:
|
|
|
|
mkdir -p build/coverage
|
2021-12-22 23:20:43 +01:00
|
|
|
go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
|
|
|
|
go tool cover -html build/coverage/coverage.txt
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
coverage-upload:
|
|
|
|
cd build/coverage && (curl -s https://codecov.io/bash | bash)
|
|
|
|
|
2021-11-20 21:43:15 +01:00
|
|
|
|
2021-10-24 03:29:45 +02:00
|
|
|
# Lint/formatting targets
|
|
|
|
|
|
|
|
fmt:
|
2021-12-07 21:39:42 +01:00
|
|
|
gofmt -s -w .
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
fmt-check:
|
|
|
|
test -z $(shell gofmt -l .)
|
|
|
|
|
|
|
|
vet:
|
2021-12-22 23:20:43 +01:00
|
|
|
go vet ./...
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
lint:
|
2022-01-26 04:30:53 +01:00
|
|
|
which golint || go install golang.org/x/lint/golint@latest
|
2021-12-22 23:20:43 +01:00
|
|
|
go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
staticcheck: .PHONY
|
|
|
|
rm -rf build/staticcheck
|
2021-12-07 20:06:33 +01:00
|
|
|
which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
|
2021-10-24 03:29:45 +02:00
|
|
|
mkdir -p build/staticcheck
|
2021-12-22 23:20:43 +01:00
|
|
|
ln -s "go" build/staticcheck/go
|
2021-10-24 03:29:45 +02:00
|
|
|
PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
|
|
|
|
rm -rf build/staticcheck
|
|
|
|
|
2021-11-20 21:43:15 +01:00
|
|
|
|
2021-10-24 03:29:45 +02:00
|
|
|
# Building targets
|
|
|
|
|
2022-03-06 02:24:10 +01:00
|
|
|
build-deps: docs web
|
2021-11-20 21:43:15 +01:00
|
|
|
which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/v7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
|
|
|
|
which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
|
|
|
|
|
|
|
|
build: build-deps
|
|
|
|
goreleaser build --rm-dist --debug
|
2021-10-24 03:29:45 +02:00
|
|
|
|
2021-11-20 21:43:15 +01:00
|
|
|
build-snapshot: build-deps
|
|
|
|
goreleaser build --snapshot --rm-dist --debug
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
build-simple: clean
|
2022-03-06 02:24:10 +01:00
|
|
|
mkdir -p dist/ntfy_linux_amd64 server/docs server/site
|
|
|
|
touch server/docs/index.html
|
|
|
|
touch server/site/app.html
|
2021-11-03 16:46:24 +01:00
|
|
|
export CGO_ENABLED=1
|
2021-12-22 23:20:43 +01:00
|
|
|
go build \
|
2021-10-24 03:29:45 +02:00
|
|
|
-o dist/ntfy_linux_amd64/ntfy \
|
2021-11-21 02:27:17 +01:00
|
|
|
-tags sqlite_omit_load_extension,osusergo,netgo \
|
2021-10-24 03:29:45 +02:00
|
|
|
-ldflags \
|
2021-11-21 02:18:40 +01:00
|
|
|
"-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)"
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
clean: .PHONY
|
2022-03-06 03:15:40 +01:00
|
|
|
rm -rf dist build server/docs server/site
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Releasing targets
|
|
|
|
|
2021-12-05 22:28:12 +01:00
|
|
|
release-check-tags:
|
|
|
|
$(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
|
2021-12-06 22:43:06 +01:00
|
|
|
if ! grep -q $(LATEST_TAG) docs/install.md; then\
|
2021-12-05 22:28:12 +01:00
|
|
|
echo "ERROR: Must update docs/install.md with latest tag first.";\
|
|
|
|
exit 1;\
|
|
|
|
fi
|
|
|
|
|
2021-12-07 16:38:58 +01:00
|
|
|
release: build-deps release-check-tags check
|
2021-11-20 21:43:15 +01:00
|
|
|
goreleaser release --rm-dist --debug
|
2021-10-24 03:29:45 +02:00
|
|
|
|
2021-11-20 21:43:15 +01:00
|
|
|
release-snapshot: build-deps
|
|
|
|
goreleaser release --snapshot --skip-publish --rm-dist --debug
|
2021-10-24 03:29:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Installing targets
|
|
|
|
|
|
|
|
install:
|
|
|
|
sudo rm -f /usr/bin/ntfy
|
|
|
|
sudo cp -a dist/ntfy_linux_amd64/ntfy /usr/bin/ntfy
|
|
|
|
|
|
|
|
install-deb:
|
|
|
|
sudo systemctl stop ntfy || true
|
|
|
|
sudo apt-get purge ntfy || true
|
2021-12-09 04:08:44 +01:00
|
|
|
sudo dpkg -i dist/ntfy_*_linux_amd64.deb
|