navidrome/Makefile

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

166 lines
6.3 KiB
Makefile
Raw Normal View History

GO_VERSION=$(shell grep "^go " go.mod | cut -f 2 -d ' ')
NODE_VERSION=$(shell cat .nvmrc)
ifneq ("$(wildcard .git/HEAD)","")
2020-01-26 18:36:24 +01:00
GIT_SHA=$(shell git rev-parse --short HEAD)
GIT_TAG=$(shell git describe --tags `git rev-list --tags --max-count=1`)
else
GIT_SHA=source_archive
GIT_TAG=$(patsubst navidrome-%,v%,$(notdir $(PWD)))
endif
2020-01-25 17:06:04 +01:00
2023-01-13 03:20:45 +01:00
CI_RELEASER_VERSION=1.19.5-1 ## https://github.com/navidrome/ci-goreleaser
setup: check_env download-deps setup-git ##@1_Run_First Install dependencies and prepare development environment
2021-05-01 17:14:24 +02: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-29 05:24:57 +02:00
npx foreman -j Procfile.dev -p 4533 start
.PHONY: dev
2020-01-20 04:48:36 +01:00
2021-05-01 17:14:24 +02:00
server: check_go_env ##@Development Start the backend in development mode
@go run github.com/cespare/reflex -d none -c reflex.conf
.PHONY: server
2021-05-01 17:14:24 +02:00
watch: ##@Development Start Go tests in watch mode (re-run when code changes)
2022-07-26 22:47:16 +02:00
go run github.com/onsi/ginkgo/v2/ginkgo watch -notify ./...
.PHONY: watch
2021-05-01 17:14:24 +02:00
test: ##@Development Run Go tests
2022-11-26 21:07:09 +01:00
go test -race ./...
.PHONY: test
2021-05-01 17:14:24 +02:00
testall: test ##@Development Run Go and JS tests
2020-01-20 01:34:54 +01:00
@(cd ./ui && npm test -- --watchAll=false)
.PHONY: testall
2020-01-20 01:34:54 +01:00
2021-05-01 17:14:24 +02:00
lint: ##@Development Lint Go code
go run github.com/golangci/golangci-lint/cmd/golangci-lint run -v --timeout 5m
.PHONY: lint
2021-05-01 17:14:24 +02:00
lintall: lint ##@Development Lint Go and JS code
2021-03-24 17:21:20 +01:00
@(cd ./ui && npm run check-formatting && npm run lint)
.PHONY: lintall
2021-05-20 19:42:29 +02: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 22:47:16 +02:00
UPDATE_SNAPSHOTS=true go run github.com/onsi/ginkgo/v2/ginkgo ./server/subsonic/...
2021-05-20 19:42:29 +02:00
.PHONY: snapshots
2021-05-01 17:14:24 +02:00
migration: ##@Development Create an empty migration file
2020-08-19 17:18:30 +02:00
@if [ -z "${name}" ]; then echo "Usage: make migration name=name_of_migration_file"; exit 1; fi
go run github.com/pressly/goose/cmd/goose -dir db/migration create ${name}
.PHONY: migration
2021-05-01 17:14:24 +02:00
setup-dev: setup
2021-05-01 14:49:34 +02:00
.PHONY: setup-dev
2021-05-01 17:14:24 +02:00
setup-git: ##@Development Setup Git hooks (pre-commit and pre-push)
2020-10-03 17:01:16 +02:00
@echo Setting up git hooks
2020-07-16 23:52:59 +02:00
@mkdir -p .git/hooks
2020-10-03 17:01:16 +02:00
@(cd .git/hooks && ln -sf ../../git/* .)
2020-07-16 23:52:59 +02:00
.PHONY: setup-git
2021-05-01 17:14:24 +02:00
buildall: buildjs build ##@Build Build the project, both frontend and backend
.PHONY: buildall
2021-10-13 15:53:44 +02:00
build: warning-noui-build check_go_env ##@Build Build only backend
2021-05-01 17:14:24 +02: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 15:53:44 +02:00
all: warning-noui-build ##@Cross_Compilation Build binaries for all supported platforms. It does not build the frontend
2021-05-01 17:14:24 +02: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 15:53:44 +02:00
single: warning-noui-build ##@Cross_Compilation Build binaries for a single supported platforms. It does not build the frontend
@if [ -z "${GOOS}" -o -z "${GOARCH}" ]; then \
echo "Usage: GOOS=<os> GOARCH=<arch> make single"; \
2021-05-01 17:14:24 +02:00
echo "Options:"; \
grep -- "- id: navidrome_" .goreleaser.yml | sed 's/- id: navidrome_//g'; \
exit 1; \
fi
@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 17:14:24 +02:00
goreleaser build --rm-dist --snapshot --single-target --id navidrome_${GOOS}_${GOARCH}
.PHONY: single
2021-10-13 15:53:44 +02: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
get-music: ##@Development Download some free music from Navidrome's demo instance
mkdir -p music
( cd music; \
curl "https://demo.navidrome.org/rest/download?u=demo&p=demo&f=json&v=1.8.0&c=dev_download&id=ec2093ec4801402f1e17cc462195cdbb" > brock.zip; \
curl "https://demo.navidrome.org/rest/download?u=demo&p=demo&f=json&v=1.8.0&c=NavidromeUI&id=b376eeb4652d2498aa2b25ba0696725e" > back_on_earth.zip; \
curl "https://demo.navidrome.org/rest/download?u=demo&p=demo&f=json&v=1.8.0&c=NavidromeUI&id=e49c609b542fc51899ee8b53aa858cb4" > ugress.zip; \
curl "https://demo.navidrome.org/rest/download?u=demo&p=demo&f=json&v=1.8.0&c=NavidromeUI&id=350bcab3a4c1d93869e39ce496464f03" > voodoocuts.zip; \
for file in *.zip; do unzip -n $${file}; done )
@echo "Done. Remember to set your MusicFolder to ./music"
.PHONY: get-music
2021-05-01 17:14:24 +02: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 14:49:34 +02:00
download-deps:
@echo Downloading Go dependencies...
2022-09-29 02:27:53 +02:00
@go mod download
2021-05-01 14:49:34 +02:00
@go mod tidy # To revert any changes made by the `go mod download` command
.PHONY: download-deps
2021-05-01 14:49:34 +02:00
check_env: check_go_env check_node_env
.PHONY: check_env
check_go_env:
@(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 14:49:34 +02:00
.PHONY: check_go_env
2021-05-01 14:49:34 +02:00
check_node_env:
@(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)
.PHONY: check_node_env
2020-01-08 17:13:05 +01:00
2021-03-24 17:21:20 +01:00
pre-push: lintall testall
.PHONY: pre-push
2021-05-01 17:14:24 +02:00
.DEFAULT_GOAL := help
2021-05-01 17:14:24 +02: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-05-01 17:14:24 +02:00
help: ##@Miscellaneous Show this help
@echo "Usage: make [target] ...\n"
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)