mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
Part 1/5 of the tea 1.0 rewrite. **Stack** (split from #1121; each PR targets `main` and builds, tests and lints on its own — the shipped CLI only changes in part 5): 1. #1122 Toolchain and foundation packages ← this PR 2. #1123 Credentials and Git 3. #1124 Terminal 4. #1125 Services 5. #1126 CLI wiring, docs, removal of the old tree ## Changes - **build:** require Go 1.27; bump gofumpt and golangci-lint to releases that can read Go 1.27 export data (own commit). - `internal/clierr`: typed errors and executable exit codes. - `internal/version`: build version and tags. - `internal/filelock`: moved unchanged from `modules/filelock`. - `internal/aliases`: user-defined command aliases. - `internal/transport`: the HTTP client the Gitea SDK runs on (part 4): token, Sudo and SSH-signature auth, retries for safe reads, connect/TLS/response-header timeouts, typed API errors that keep Gitea's message, and a redacted request log for `--debug`; plus raw requests for `tea api`, signed downloads that follow object-storage redirects, and log streaming. - `internal/settings`: split `config.yml` / `hosts.yml` with locked transactions, plus remote URL parsing. Nothing imports these packages yet. Note: `flake.nix` now asks for `go_1_27`; the pinned nixpkgs in `flake.lock` predates Go 1.27 and still needs a `nix flake update nixpkgs`. Reviewed-on: https://gitea.com/gitea/tea/pulls/1122 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
145 lines
3.7 KiB
Makefile
145 lines
3.7 KiB
Makefile
DIST := dist
|
|
GO ?= go
|
|
SHASUM ?= shasum -a 256
|
|
|
|
export PATH := $($(GO) env GOPATH)/bin:$(PATH)
|
|
|
|
GOFILES := $(shell find . -name "*.go" -type f ! -path "*/bindata.go")
|
|
|
|
# Tool packages with pinned versions
|
|
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.12.0
|
|
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0
|
|
|
|
ifneq ($(DRONE_TAG),)
|
|
VERSION ?= $(subst v,,$(DRONE_TAG))
|
|
TEA_VERSION ?= $(VERSION)
|
|
else
|
|
ifneq ($(DRONE_BRANCH),)
|
|
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
|
|
else
|
|
VERSION ?= main
|
|
endif
|
|
TEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
|
endif
|
|
TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION))
|
|
|
|
TAGS ?=
|
|
SDK ?= $(shell $(GO) list -f '{{.Version}}' -m gitea.dev/sdk)
|
|
LDFLAGS := -X "gitea.dev/tea/modules/version.Version=$(TEA_VERSION)" -X "gitea.dev/tea/modules/version.Tags=$(TAGS)" -X "gitea.dev/tea/modules/version.SDK=$(SDK)" -s -w
|
|
|
|
# override to allow passing additional goflags via make CLI
|
|
override GOFLAGS := $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)'
|
|
|
|
PACKAGES ?= $(shell $(GO) list ./... | grep -v '^gitea.dev/tea/tests')
|
|
UNIT_PACKAGES ?= $(PACKAGES)
|
|
INTEGRATION_PACKAGES ?= $(shell $(GO) list ./tests/... 2>/dev/null)
|
|
INTEGRATION_TEST_TAGS ?= testtools
|
|
INTEGRATION_TEST_GOFLAGS ?= -v
|
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
|
|
# OS specific vars.
|
|
ifeq ($(OS), Windows_NT)
|
|
EXECUTABLE := tea.exe
|
|
VET_TOOL := gitea-vet.exe
|
|
else
|
|
EXECUTABLE := tea
|
|
VET_TOOL := gitea-vet
|
|
endif
|
|
|
|
.PHONY: all
|
|
all: build
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(GO) clean -i ./...
|
|
rm -rf $(EXECUTABLE) $(DIST)
|
|
|
|
.PHONY: fmt
|
|
fmt:
|
|
$(GO) run $(GOFUMPT_PACKAGE) -w $(GOFILES)
|
|
|
|
.PHONY: vet
|
|
vet:
|
|
# Default vet
|
|
$(GO) vet $(PACKAGES)
|
|
# Custom vet
|
|
$(GO) build code.gitea.io/gitea-vet
|
|
$(GO) vet -vettool=$(VET_TOOL) $(PACKAGES)
|
|
|
|
.PHONY: lint
|
|
lint:
|
|
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --build-tags testtools
|
|
|
|
.PHONY: lint-fix
|
|
lint-fix:
|
|
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --build-tags testtools --fix
|
|
|
|
.PHONY: fmt-check
|
|
fmt-check:
|
|
# get all go files and run gofumpt on them
|
|
@diff=$$($(GO) run $(GOFUMPT_PACKAGE) -d $(GOFILES)); \
|
|
if [ -n "$$diff" ]; then \
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
|
echo "$${diff}"; \
|
|
exit 1; \
|
|
fi;
|
|
|
|
.PHONY: docs
|
|
docs:
|
|
$(GO) run docs/docs.go --out docs/CLI.md
|
|
|
|
.PHONY: docs-check
|
|
docs-check:
|
|
@DIFF=$$($(GO) run docs/docs.go | diff docs/CLI.md -); \
|
|
if [ -n "$$DIFF" ]; then \
|
|
echo "Please run 'make docs' and commit the result:"; \
|
|
echo "$$DIFF"; \
|
|
exit 1; \
|
|
fi;
|
|
|
|
.PHONY: unit-test
|
|
unit-test:
|
|
$(GO) test $(UNIT_PACKAGES)
|
|
|
|
.PHONY: integration-test
|
|
integration-test:
|
|
@if [ -n "$(INTEGRATION_PACKAGES)" ]; then \
|
|
$(GO) test $(INTEGRATION_TEST_GOFLAGS) -tags='$(INTEGRATION_TEST_TAGS)' $(INTEGRATION_PACKAGES); \
|
|
else \
|
|
echo "No integration test packages found"; \
|
|
fi
|
|
|
|
.PHONY: test
|
|
test: unit-test integration-test
|
|
|
|
.PHONY: unit-test-coverage
|
|
unit-test-coverage:
|
|
$(GO) test -cover -coverprofile coverage.out $(UNIT_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
|
|
|
.PHONY: tidy
|
|
tidy:
|
|
$(eval GO_TOOLCHAIN := $(shell grep -Eo '^toolchain\s+go[0-9.]+' go.mod | cut -d' ' -f2))
|
|
$(GO) mod tidy
|
|
@# workaround https://github.com/golang/go/issues/75331: restore toolchain if tidy dropped it
|
|
@if [ -n "$(GO_TOOLCHAIN)" ] && ! grep -qE '^toolchain\s' go.mod; then \
|
|
$(GO) mod edit -toolchain=$(GO_TOOLCHAIN); \
|
|
fi
|
|
|
|
.PHONY: check
|
|
check: test
|
|
|
|
.PHONY: install
|
|
install: $(SOURCES)
|
|
@echo "installing to $(shell $(GO) env GOPATH)/bin/$(EXECUTABLE)"
|
|
$(GO) install -v $(BUILDMODE) $(GOFLAGS)
|
|
|
|
.PHONY: build
|
|
build: $(EXECUTABLE)
|
|
|
|
$(EXECUTABLE): $(SOURCES)
|
|
$(GO) build $(BUILDMODE) $(GOFLAGS) -o $@
|
|
|
|
.PHONY: build-image
|
|
build-image:
|
|
docker build --build-arg VERSION=$(TEA_VERSION) -t gitea/tea:$(TEA_VERSION_TAG) .
|