2020-08-19 11:40:31 -08:00
|
|
|
GO_VERSION=$(shell grep "^go " go.mod | cut -f 2 -d ' ')
|
2020-03-06 07:50:39 -09:00
|
|
|
NODE_VERSION=$(shell cat .nvmrc)
|
2020-01-13 18:53:23 -09:00
|
|
|
|
2021-10-23 17:27:19 -08:00
|
|
|
ifneq ("$(wildcard .git/HEAD)","")
|
2020-01-26 08:36:24 -09:00
|
|
|
GIT_SHA=$(shell git rev-parse --short HEAD)
|
2020-04-20 05:47:44 -08:00
|
|
|
GIT_TAG=$(shell git describe --tags `git rev-list --tags --max-count=1`)
|
2021-09-06 17:26:04 -08:00
|
|
|
else
|
|
|
|
|
GIT_SHA=source_archive
|
|
|
|
|
GIT_TAG=$(patsubst navidrome-%,v%,$(notdir $(PWD)))
|
2021-07-15 05:49:34 -08:00
|
|
|
endif
|
2020-01-25 07:06:04 -09:00
|
|
|
|
2022-09-27 12:47:47 -08:00
|
|
|
CI_RELEASER_VERSION=1.19.1-3 ## https://github.com/navidrome/ci-goreleaser
|
2020-03-20 08:21:41 -08:00
|
|
|
|
2021-08-21 09:45:34 -08:00
|
|
|
setup: check_env download-deps setup-git ##@1_Run_First Install dependencies and prepare development environment
|
2021-05-01 07:14:24 -08:00
|
|
|
@echo Downloading Node dependencies...
|
|
|
|
|
@(cd ./ui && npm ci)
|
|
|
|
|
.PHONY: setup
|
|
|
|
|
|
|
|
|
|
dev: check_env ##@Development Start Navidrome in development mode, with hot-reload for both frontend and backend
|
2020-04-28 19:24:57 -08:00
|
|
|
npx foreman -j Procfile.dev -p 4533 start
|
2020-03-20 08:21:41 -08:00
|
|
|
.PHONY: dev
|
2020-01-19 18:48:36 -09:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
server: check_go_env ##@Development Start the backend in development mode
|
2021-02-01 12:16:30 -09:00
|
|
|
@go run github.com/cespare/reflex -d none -c reflex.conf
|
2020-03-20 08:21:41 -08:00
|
|
|
.PHONY: server
|
2020-01-20 09:43:51 -09:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
watch: ##@Development Start Go tests in watch mode (re-run when code changes)
|
2022-07-26 12:47:16 -08:00
|
|
|
go run github.com/onsi/ginkgo/v2/ginkgo watch -notify ./...
|
2020-03-20 08:21:41 -08:00
|
|
|
.PHONY: watch
|
2020-01-15 19:40:22 -09:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
test: ##@Development Run Go tests
|
2021-05-11 13:21:18 -08:00
|
|
|
go test ./...
|
2020-03-20 08:21:41 -08:00
|
|
|
.PHONY: test
|
2020-01-13 18:53:23 -09:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
testall: test ##@Development Run Go and JS tests
|
2020-01-19 15:34:54 -09:00
|
|
|
@(cd ./ui && npm test -- --watchAll=false)
|
2020-03-20 08:21:41 -08:00
|
|
|
.PHONY: testall
|
2020-01-19 15:34:54 -09:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
lint: ##@Development Lint Go code
|
2021-04-08 06:19:53 -08:00
|
|
|
go run github.com/golangci/golangci-lint/cmd/golangci-lint run -v --timeout 5m
|
2020-10-24 18:43:59 -08:00
|
|
|
.PHONY: lint
|
|
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
lintall: lint ##@Development Lint Go and JS code
|
2021-03-24 08:21:20 -08:00
|
|
|
@(cd ./ui && npm run check-formatting && npm run lint)
|
|
|
|
|
.PHONY: lintall
|
|
|
|
|
|
2021-05-20 09:42:29 -08:00
|
|
|
wire: check_go_env ##@Development Update Dependency Injection
|
|
|
|
|
go run github.com/google/wire/cmd/wire ./...
|
|
|
|
|
.PHONY: wire
|
|
|
|
|
|
|
|
|
|
snapshots: ##@Development Update (GoLang) Snapshot tests
|
2022-07-26 12:47:16 -08:00
|
|
|
UPDATE_SNAPSHOTS=true go run github.com/onsi/ginkgo/v2/ginkgo ./server/subsonic/...
|
2021-05-20 09:42:29 -08:00
|
|
|
.PHONY: snapshots
|
2020-05-09 17:00:38 -08:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
migration: ##@Development Create an empty migration file
|
2020-08-19 07:18:30 -08:00
|
|
|
@if [ -z "${name}" ]; then echo "Usage: make migration name=name_of_migration_file"; exit 1; fi
|
2021-02-01 12:16:30 -09:00
|
|
|
go run github.com/pressly/goose/cmd/goose -dir db/migration create ${name}
|
2020-07-31 05:55:44 -08:00
|
|
|
.PHONY: migration
|
2020-06-08 13:29:09 -08:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
setup-dev: setup
|
2021-05-01 04:49:34 -08:00
|
|
|
.PHONY: setup-dev
|
2020-04-26 12:10:40 -08:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
setup-git: ##@Development Setup Git hooks (pre-commit and pre-push)
|
2020-10-03 07:01:16 -08:00
|
|
|
@echo Setting up git hooks
|
2020-07-16 13:52:59 -08:00
|
|
|
@mkdir -p .git/hooks
|
2020-10-03 07:01:16 -08:00
|
|
|
@(cd .git/hooks && ln -sf ../../git/* .)
|
2020-07-16 13:52:59 -08:00
|
|
|
.PHONY: setup-git
|
|
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
buildall: buildjs build ##@Build Build the project, both frontend and backend
|
|
|
|
|
.PHONY: buildall
|
|
|
|
|
|
2021-10-13 05:53:44 -08:00
|
|
|
build: warning-noui-build check_go_env ##@Build Build only backend
|
2021-05-01 07:14:24 -08:00
|
|
|
go build -ldflags="-X github.com/navidrome/navidrome/consts.gitSha=$(GIT_SHA) -X github.com/navidrome/navidrome/consts.gitTag=$(GIT_TAG)-SNAPSHOT" -tags=netgo
|
|
|
|
|
.PHONY: build
|
|
|
|
|
|
|
|
|
|
buildjs: check_node_env ##@Build Build only frontend
|
|
|
|
|
@(cd ./ui && npm run build)
|
|
|
|
|
.PHONY: buildjs
|
|
|
|
|
|
2021-10-13 05:53:44 -08:00
|
|
|
all: warning-noui-build ##@Cross_Compilation Build binaries for all supported platforms. It does not build the frontend
|
2021-05-01 07:14:24 -08:00
|
|
|
docker run -t -v $(PWD):/workspace -w /workspace deluan/ci-goreleaser:$(CI_RELEASER_VERSION) \
|
|
|
|
|
goreleaser release --rm-dist --skip-publish --snapshot
|
|
|
|
|
.PHONY: all
|
|
|
|
|
|
2021-10-13 05:53:44 -08:00
|
|
|
single: warning-noui-build ##@Cross_Compilation Build binaries for a single supported platforms. It does not build the frontend
|
2021-05-04 13:02:17 -08:00
|
|
|
@if [ -z "${GOOS}" -o -z "${GOARCH}" ]; then \
|
|
|
|
|
echo "Usage: GOOS=<os> GOARCH=<arch> make single"; \
|
2021-05-01 07:14:24 -08:00
|
|
|
echo "Options:"; \
|
|
|
|
|
grep -- "- id: navidrome_" .goreleaser.yml | sed 's/- id: navidrome_//g'; \
|
|
|
|
|
exit 1; \
|
|
|
|
|
fi
|
2021-05-04 13:02:17 -08:00
|
|
|
@echo "Building binaries for ${GOOS}/${GOARCH}"
|
|
|
|
|
docker run -t -v $(PWD):/workspace -e GOOS -e GOARCH -w /workspace deluan/ci-goreleaser:$(CI_RELEASER_VERSION) \
|
2021-05-01 07:14:24 -08:00
|
|
|
goreleaser build --rm-dist --snapshot --single-target --id navidrome_${GOOS}_${GOARCH}
|
|
|
|
|
.PHONY: single
|
|
|
|
|
|
2021-10-13 05:53:44 -08:00
|
|
|
warning-noui-build:
|
|
|
|
|
@echo "WARNING: This command does not build the frontend, it uses the latest built with 'make buildjs'"
|
|
|
|
|
.PHONY: warning-noui-build
|
2021-05-01 07:14:24 -08:00
|
|
|
##########################################
|
|
|
|
|
#### Miscellaneous
|
|
|
|
|
|
|
|
|
|
release:
|
|
|
|
|
@if [[ ! "${V}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$$ ]]; then echo "Usage: make release V=X.X.X"; exit 1; fi
|
|
|
|
|
go mod tidy
|
|
|
|
|
@if [ -n "`git status -s`" ]; then echo "\n\nThere are pending changes. Please commit or stash first"; exit 1; fi
|
|
|
|
|
make pre-push
|
|
|
|
|
git tag v${V}
|
|
|
|
|
git push origin v${V} --no-verify
|
|
|
|
|
.PHONY: release
|
|
|
|
|
|
2021-05-01 04:49:34 -08:00
|
|
|
download-deps:
|
|
|
|
|
@echo Downloading Go dependencies...
|
2022-09-28 16:27:53 -08:00
|
|
|
@go mod download
|
2021-05-01 04:49:34 -08:00
|
|
|
@go mod tidy # To revert any changes made by the `go mod download` command
|
|
|
|
|
.PHONY: download-deps
|
2021-03-10 11:36:57 -09:00
|
|
|
|
2021-05-01 04:49:34 -08:00
|
|
|
check_env: check_go_env check_node_env
|
|
|
|
|
.PHONY: check_env
|
|
|
|
|
|
|
|
|
|
check_go_env:
|
2021-03-10 11:36:57 -09:00
|
|
|
@(hash go) || (echo "\nERROR: GO environment not setup properly!\n"; exit 1)
|
|
|
|
|
@current_go_version=`go version | cut -d ' ' -f 3 | cut -c3-` && \
|
|
|
|
|
echo "$(GO_VERSION) $$current_go_version" | \
|
|
|
|
|
tr ' ' '\n' | sort -V | tail -1 | \
|
|
|
|
|
grep -q "^$${current_go_version}$$" || \
|
|
|
|
|
(echo "\nERROR: Please upgrade your GO version\nThis project requires at least the version $(GO_VERSION)"; exit 1)
|
2021-05-01 04:49:34 -08:00
|
|
|
.PHONY: check_go_env
|
2021-03-10 11:36:57 -09:00
|
|
|
|
2021-05-01 04:49:34 -08:00
|
|
|
check_node_env:
|
2021-03-10 11:36:57 -09:00
|
|
|
@(hash node) || (echo "\nERROR: Node environment not setup properly!\n"; exit 1)
|
|
|
|
|
@current_node_version=`node --version` && \
|
|
|
|
|
echo "$(NODE_VERSION) $$current_node_version" | \
|
|
|
|
|
tr ' ' '\n' | sort -V | tail -1 | \
|
|
|
|
|
grep -q "^$${current_node_version}$$" || \
|
|
|
|
|
(echo "\nERROR: Please check your Node version. Should be at least $(NODE_VERSION)\n"; exit 1)
|
2020-03-20 08:21:41 -08:00
|
|
|
.PHONY: check_node_env
|
2020-01-08 07:13:05 -09:00
|
|
|
|
2021-03-24 08:21:20 -08:00
|
|
|
pre-push: lintall testall
|
2020-09-24 13:23:46 -08:00
|
|
|
.PHONY: pre-push
|
|
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
.DEFAULT_GOAL := help
|
2020-01-30 12:33:27 -09:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
HELP_FUN = \
|
|
|
|
|
%help; while(<>){push@{$$help{$$2//'options'}},[$$1,$$3] \
|
|
|
|
|
if/^([\w-_]+)\s*:.*\#\#(?:@(\w+))?\s(.*)$$/}; \
|
|
|
|
|
print"$$_:\n", map" $$_->[0]".(" "x(20-length($$_->[0])))."$$_->[1]\n",\
|
|
|
|
|
@{$$help{$$_}},"\n" for sort keys %help; \
|
2021-04-26 13:21:59 -08:00
|
|
|
|
2021-05-01 07:14:24 -08:00
|
|
|
help: ##@Miscellaneous Show this help
|
|
|
|
|
@echo "Usage: make [target] ...\n"
|
|
|
|
|
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
|