mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
* Add golangci-lint workflow * Add a bit more lenient linter timeout 1 Minute isn't always enough, so bump to 3. * Document golangci, add make target Document how to get golangci-lint in the README file. While here, provide a QOL target in the makefile for the linter, and make it part of validation. * Introduce .golangci.yml This is the default golangci-lint configuration file location. Use it. Move configuration into the yaml file, and enable the default set of linters; we know we pass most of those. * Add gofmt and revive to golangci-lint Read the golangci-lint source code to figure out the configuration format. Copy the configuration from `revive.toml` into the linter configuration. * Do not set simplify on gofmt The project currently runs without simplify. So for consistency, don't make that a requirement for the linter. * Add new-from-rev Older issues should not be considered a failure for new PRs and issues. Use new-from-from to make the current develop as the point-in-time for when we consider errors. Once in the tree, we can go and fix the older errors in separate patches, taking a little bit at a time. * Move to golangci-lint Rewrite the way we run targets in the makefile, so it is split between frontend and backend. Use the frontend build steps in build.yml Update README to reflect the new world order. * Remove check-gofmt.sh The tool now runs as part of golangci-lint, in particular through the 'validate' target in the Makefile. * Remove targets for golangci-lint Fold these targets into the `lint` target. While here, update README.
200 lines
5.9 KiB
Makefile
200 lines
5.9 KiB
Makefile
IS_WIN =
|
|
ifeq (${SHELL}, sh.exe)
|
|
IS_WIN = true
|
|
endif
|
|
ifeq (${SHELL}, cmd)
|
|
IS_WIN = true
|
|
endif
|
|
|
|
ifdef IS_WIN
|
|
SEPARATOR := &&
|
|
SET := set
|
|
else
|
|
SEPARATOR := ;
|
|
SET := export
|
|
endif
|
|
|
|
# set LDFLAGS environment variable to any extra ldflags required
|
|
# set OUTPUT to generate a specific binary name
|
|
|
|
LDFLAGS := $(LDFLAGS)
|
|
ifdef OUTPUT
|
|
OUTPUT := -o $(OUTPUT)
|
|
endif
|
|
|
|
export CGO_ENABLED = 1
|
|
|
|
.PHONY: release pre-build
|
|
|
|
release: generate ui build-release
|
|
|
|
pre-build:
|
|
ifndef BUILD_DATE
|
|
$(eval BUILD_DATE := $(shell go run -mod=vendor scripts/getDate.go))
|
|
endif
|
|
|
|
ifndef GITHASH
|
|
$(eval GITHASH := $(shell git rev-parse --short HEAD))
|
|
endif
|
|
|
|
ifndef STASH_VERSION
|
|
$(eval STASH_VERSION := $(shell git describe --tags --exclude latest_develop))
|
|
endif
|
|
|
|
build: pre-build
|
|
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)')
|
|
go build $(OUTPUT) -mod=vendor -v -tags "sqlite_omit_load_extension osusergo netgo" $(GO_BUILD_FLAGS) -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS)"
|
|
|
|
# strips debug symbols from the release build
|
|
build-release: EXTRA_LDFLAGS := -s -w
|
|
build-release: GO_BUILD_FLAGS := -trimpath
|
|
build-release: build
|
|
|
|
build-release-static: EXTRA_LDFLAGS := -extldflags=-static -s -w
|
|
build-release-static: GO_BUILD_FLAGS := -trimpath
|
|
build-release-static: build
|
|
|
|
# cross-compile- targets should be run within the compiler docker container
|
|
cross-compile-windows: export GOOS := windows
|
|
cross-compile-windows: export GOARCH := amd64
|
|
cross-compile-windows: export CC := x86_64-w64-mingw32-gcc
|
|
cross-compile-windows: export CXX := x86_64-w64-mingw32-g++
|
|
cross-compile-windows: OUTPUT := -o dist/stash-win.exe
|
|
cross-compile-windows: build-release-static
|
|
|
|
cross-compile-osx-intel: export GOOS := darwin
|
|
cross-compile-osx-intel: export GOARCH := amd64
|
|
cross-compile-osx-intel: export CC := o64-clang
|
|
cross-compile-osx-intel: export CXX := o64-clang++
|
|
cross-compile-osx-intel: OUTPUT := -o dist/stash-osx
|
|
# can't use static build for OSX
|
|
cross-compile-osx-intel: build-release
|
|
|
|
cross-compile-osx-applesilicon: export GOOS := darwin
|
|
cross-compile-osx-applesilicon: export GOARCH := arm64
|
|
cross-compile-osx-applesilicon: export CC := oa64e-clang
|
|
cross-compile-osx-applesilicon: export CXX := oa64e-clang++
|
|
cross-compile-osx-applesilicon: OUTPUT := -o dist/stash-osx-applesilicon
|
|
# can't use static build for OSX
|
|
cross-compile-osx-applesilicon: build-release
|
|
|
|
cross-compile-linux: export GOOS := linux
|
|
cross-compile-linux: export GOARCH := amd64
|
|
cross-compile-linux: OUTPUT := -o dist/stash-linux
|
|
cross-compile-linux: build-release-static
|
|
|
|
cross-compile-linux-arm64v8: export GOOS := linux
|
|
cross-compile-linux-arm64v8: export GOARCH := arm64
|
|
cross-compile-linux-arm64v8: export CC := aarch64-linux-gnu-gcc
|
|
cross-compile-linux-arm64v8: OUTPUT := -o dist/stash-linux-arm64v8
|
|
cross-compile-linux-arm64v8: build-release-static
|
|
|
|
cross-compile-linux-arm32v7: export GOOS := linux
|
|
cross-compile-linux-arm32v7: export GOARCH := arm
|
|
cross-compile-linux-arm32v7: export GOARM := 7
|
|
cross-compile-linux-arm32v7: export CC := arm-linux-gnueabihf-gcc
|
|
cross-compile-linux-arm32v7: OUTPUT := -o dist/stash-linux-arm32v7
|
|
cross-compile-linux-arm32v7: build-release-static
|
|
|
|
cross-compile-pi: export GOOS := linux
|
|
cross-compile-pi: export GOARCH := arm
|
|
cross-compile-pi: export GOARM := 6
|
|
cross-compile-pi: export CC := arm-linux-gnueabi-gcc
|
|
cross-compile-pi: OUTPUT := -o dist/stash-pi
|
|
cross-compile-pi: build-release-static
|
|
|
|
cross-compile-all:
|
|
make cross-compile-windows
|
|
make cross-compile-osx-intel
|
|
make cross-compile-osx-applesilicon
|
|
make cross-compile-linux
|
|
make cross-compile-linux-arm64v8
|
|
make cross-compile-linux-arm32v7
|
|
make cross-compile-pi
|
|
|
|
# Regenerates GraphQL files
|
|
generate: generate-backend generate-frontend
|
|
|
|
.PHONY: generate-frontend
|
|
generate-frontend:
|
|
cd ui/v2.5 && yarn run gqlgen
|
|
|
|
.PHONY: generate-backend
|
|
generate-backend:
|
|
go generate -mod=vendor
|
|
|
|
# Regenerates stash-box client files
|
|
.PHONY: generate-stash-box-client
|
|
generate-stash-box-client:
|
|
go run -mod=vendor github.com/Yamashou/gqlgenc
|
|
|
|
# Runs gofmt -w on the project's source code, modifying any files that do not match its style.
|
|
.PHONY: fmt
|
|
fmt:
|
|
go fmt ./...
|
|
|
|
.PHONY: lint
|
|
lint:
|
|
golangci-lint run
|
|
|
|
# runs unit tests - excluding integration tests
|
|
.PHONY: test
|
|
test:
|
|
go test -mod=vendor ./...
|
|
|
|
# runs all tests - including integration tests
|
|
.PHONY: it
|
|
it:
|
|
go test -mod=vendor -tags=integration ./...
|
|
|
|
# generates test mocks
|
|
.PHONY: generate-test-mocks
|
|
generate-test-mocks:
|
|
go run -mod=vendor github.com/vektra/mockery/v2 --dir ./pkg/models --name '.*ReaderWriter' --outpkg mocks --output ./pkg/models/mocks
|
|
|
|
# installs UI dependencies. Run when first cloning repository, or if UI
|
|
# dependencies have changed
|
|
.PHONY: pre-ui
|
|
pre-ui:
|
|
cd ui/v2.5 && yarn install --frozen-lockfile
|
|
|
|
.PHONY: ui
|
|
ui: pre-build
|
|
$(SET) REACT_APP_DATE="$(BUILD_DATE)" $(SEPARATOR) \
|
|
$(SET) REACT_APP_GITHASH=$(GITHASH) $(SEPARATOR) \
|
|
$(SET) REACT_APP_STASH_VERSION=$(STASH_VERSION) $(SEPARATOR) \
|
|
cd ui/v2.5 && yarn build
|
|
|
|
.PHONY: ui-start
|
|
ui-start: pre-build
|
|
$(SET) REACT_APP_DATE="$(BUILD_DATE)" $(SEPARATOR) \
|
|
$(SET) REACT_APP_GITHASH=$(GITHASH) $(SEPARATOR) \
|
|
$(SET) REACT_APP_STASH_VERSION=$(STASH_VERSION) $(SEPARATOR) \
|
|
cd ui/v2.5 && yarn start
|
|
|
|
.PHONY: fmt-ui
|
|
fmt-ui:
|
|
cd ui/v2.5 && yarn format
|
|
|
|
# runs tests and checks on the UI and builds it
|
|
.PHONY: ui-validate
|
|
ui-validate:
|
|
cd ui/v2.5 && yarn run validate
|
|
|
|
# runs all of the tests and checks required for a PR to be accepted
|
|
.PHONY: validate
|
|
validate: validate-frontend validate-backend
|
|
|
|
# runs all of the frontend PR-acceptance steps
|
|
.PHONY: validate-frontend
|
|
validate-frontend: ui-validate
|
|
|
|
# runs all of the backend PR-acceptance steps
|
|
.PHONY: validate-backend
|
|
validate-backend: lint it
|
|
|
|
# locally builds and tags a 'stash/build' docker image
|
|
.PHONY: docker-build
|
|
docker-build:
|
|
docker build -t stash/build -f docker/build/x86_64/Dockerfile .
|