2019-04-25 17:06:53 +00:00
|
|
|
DIST := dist
|
|
|
|
GO ?= go
|
|
|
|
SHASUM ?= shasum -a 256
|
|
|
|
|
|
|
|
export PATH := $($(GO) env GOPATH)/bin:$(PATH)
|
|
|
|
|
2023-02-09 03:05:39 +00:00
|
|
|
GOFILES := $(shell find . -name "*.go" -type f ! -path "*/bindata.go")
|
2019-04-25 17:06:53 +00:00
|
|
|
GOFMT ?= gofmt -s
|
|
|
|
|
|
|
|
ifneq ($(DRONE_TAG),)
|
|
|
|
VERSION ?= $(subst v,,$(DRONE_TAG))
|
2019-04-26 03:41:21 +00:00
|
|
|
TEA_VERSION ?= $(VERSION)
|
2019-04-25 17:06:53 +00:00
|
|
|
else
|
|
|
|
ifneq ($(DRONE_BRANCH),)
|
|
|
|
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
|
|
|
|
else
|
2023-09-10 04:14:38 +00:00
|
|
|
VERSION ?= main
|
2019-04-25 17:06:53 +00:00
|
|
|
endif
|
2019-04-26 03:41:21 +00:00
|
|
|
TEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
2019-04-25 17:06:53 +00:00
|
|
|
endif
|
2021-03-30 11:13:23 +00:00
|
|
|
TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION))
|
|
|
|
|
2021-09-23 16:01:07 +00:00
|
|
|
TAGS ?=
|
2022-06-18 14:34:18 +00:00
|
|
|
SDK ?= $(shell $(GO) list -f '{{.Version}}' -m code.gitea.io/sdk/gitea)
|
|
|
|
LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)" -X "main.SDK=$(SDK)" -s -w
|
2021-09-23 16:01:07 +00:00
|
|
|
|
|
|
|
# override to allow passing additional goflags via make CLI
|
2023-02-09 03:05:39 +00:00
|
|
|
override GOFLAGS := $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)'
|
2019-04-25 17:06:53 +00:00
|
|
|
|
2023-02-09 03:05:39 +00:00
|
|
|
PACKAGES ?= $(shell $(GO) list ./...)
|
2019-04-25 17:06:53 +00:00
|
|
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
|
|
|
2021-12-02 20:01:10 +00:00
|
|
|
# OS specific vars.
|
2019-04-25 17:06:53 +00:00
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
EXECUTABLE := tea.exe
|
2023-07-28 14:03:26 +00:00
|
|
|
VET_TOOL := gitea-vet.exe
|
2019-04-25 17:06:53 +00:00
|
|
|
else
|
|
|
|
EXECUTABLE := tea
|
2023-07-28 14:03:26 +00:00
|
|
|
VET_TOOL := gitea-vet
|
2021-12-02 20:01:10 +00:00
|
|
|
ifneq ($(shell uname -s), OpenBSD)
|
|
|
|
override BUILDMODE := -buildmode=pie
|
|
|
|
endif
|
2019-04-25 17:06:53 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: build
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2023-02-09 03:05:39 +00:00
|
|
|
$(GO) clean -i ./...
|
2019-04-26 03:41:21 +00:00
|
|
|
rm -rf $(EXECUTABLE) $(DIST)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
|
|
|
$(GOFMT) -w $(GOFILES)
|
|
|
|
|
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
2020-04-28 13:02:21 +00:00
|
|
|
# Default vet
|
2023-02-09 03:05:39 +00:00
|
|
|
$(GO) vet $(PACKAGES)
|
2020-04-28 13:02:21 +00:00
|
|
|
# Custom vet
|
2023-02-09 03:05:39 +00:00
|
|
|
$(GO) build code.gitea.io/gitea-vet
|
2023-07-28 14:03:26 +00:00
|
|
|
$(GO) vet -vettool=$(VET_TOOL) $(PACKAGES)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: lint
|
2022-03-28 23:11:11 +00:00
|
|
|
lint: install-lint-tools
|
2023-09-08 01:40:02 +00:00
|
|
|
$(GO) run github.com/mgechev/revive@v1.3.2 -config .revive.toml ./... || exit 1
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: misspell-check
|
2022-03-28 23:11:11 +00:00
|
|
|
misspell-check: install-lint-tools
|
2023-08-21 22:01:15 +00:00
|
|
|
$(GO) run github.com/client9/misspell/cmd/misspell@latest -error -i unknwon,destory $(GOFILES)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: misspell
|
2022-03-28 23:11:11 +00:00
|
|
|
misspell: install-lint-tools
|
2023-08-21 22:01:15 +00:00
|
|
|
$(GO) run github.com/client9/misspell/cmd/misspell@latest -w -i unknwon $(GOFILES)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: fmt-check
|
|
|
|
fmt-check:
|
|
|
|
# get all go files and run go fmt on them
|
|
|
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
|
|
|
if [ -n "$$diff" ]; then \
|
|
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
|
|
|
echo "$${diff}"; \
|
|
|
|
exit 1; \
|
|
|
|
fi;
|
|
|
|
|
2023-09-01 15:34:13 +00:00
|
|
|
.PHONY: docs
|
|
|
|
docs:
|
|
|
|
$(GO) run . docs --out docs/CLI.md
|
|
|
|
|
|
|
|
.PHONY: docs-check
|
|
|
|
docs-check:
|
|
|
|
@DIFF=$$($(GO) run . docs | diff docs/CLI.md -); \
|
|
|
|
if [ -n "$$DIFF" ]; then \
|
|
|
|
echo "Please run 'make docs' and commit the result:"; \
|
|
|
|
echo "$$DIFF"; \
|
|
|
|
exit 1; \
|
|
|
|
fi;
|
|
|
|
|
2019-04-25 17:06:53 +00:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
2023-02-09 03:05:39 +00:00
|
|
|
$(GO) test -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: unit-test-coverage
|
|
|
|
unit-test-coverage:
|
2023-02-09 03:05:39 +00:00
|
|
|
$(GO) test -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
2019-04-25 17:06:53 +00:00
|
|
|
|
2023-02-09 03:05:39 +00:00
|
|
|
.PHONY: tidy
|
|
|
|
tidy:
|
|
|
|
$(GO) mod tidy
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: check
|
|
|
|
check: test
|
|
|
|
|
|
|
|
.PHONY: install
|
2021-09-23 16:01:07 +00:00
|
|
|
install: $(SOURCES)
|
2023-04-17 21:08:50 +00:00
|
|
|
@echo "installing to $(shell $(GO) env GOPATH)/bin/$(EXECUTABLE)"
|
2023-08-21 22:01:15 +00:00
|
|
|
$(GO) install -v $(BUILDMODE) $(GOFLAGS)
|
2019-04-25 17:06:53 +00:00
|
|
|
|
|
|
|
.PHONY: build
|
|
|
|
build: $(EXECUTABLE)
|
|
|
|
|
|
|
|
$(EXECUTABLE): $(SOURCES)
|
2021-12-02 20:01:10 +00:00
|
|
|
$(GO) build $(BUILDMODE) $(GOFLAGS) -o $@
|
2019-04-25 17:06:53 +00:00
|
|
|
|
2021-03-30 11:13:23 +00:00
|
|
|
.PHONY: build-image
|
|
|
|
build-image:
|
|
|
|
docker build --build-arg VERSION=$(TEA_VERSION) -t gitea/tea:$(TEA_VERSION_TAG) .
|
|
|
|
|
2022-03-28 23:11:11 +00:00
|
|
|
install-lint-tools:
|
|
|
|
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2023-09-08 01:40:02 +00:00
|
|
|
$(GO) install github.com/mgechev/revive@v1.3.2; \
|
2022-03-28 23:11:11 +00:00
|
|
|
fi
|
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
|
|
$(GO) install github.com/client9/misspell/cmd/misspell@latest; \
|
|
|
|
fi
|