diff --git a/Makefile b/Makefile index 7f06ef39ff..717817c390 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,6 @@ LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/r GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration,$(shell $(GO) list ./... | grep -v /vendor/)) MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) -GO_GOGIT_TEST_PACKAGES ?= code.gitea.io/gitea/modules/git/... code.gitea.io/gitea/modules/gitrepo/... code.gitea.io/gitea/modules/lfs/... FRONTEND_SOURCES := $(shell find web_src/js web_src/css -type f) FRONTEND_CONFIGS := vite.config.ts tailwind.config.ts @@ -383,9 +382,10 @@ test-backend: ## test backend files @$(GO) test $(GOTEST_FLAGS) -tags='$(TAGS)' $(GO_TEST_PACKAGES) .PHONY: test-backend-gogit -test-backend-gogit: ## test gogit-affected packages only - @echo "Running go test with $(GOTEST_FLAGS) -tags '$(TAGS)' over gogit-affected packages..." - @$(GO) test $(GOTEST_FLAGS) -tags='$(TAGS)' $(GO_GOGIT_TEST_PACKAGES) +test-backend-gogit: ## test packages whose code or tests import the gogit-affected modules + @pkgs=$$(./tools/find-gogit-test-pkgs.sh '$(TAGS)'); \ + echo "Running go test with $(GOTEST_FLAGS) -tags '$(TAGS)' over $$(echo $$pkgs | wc -w) gogit-affected packages..."; \ + $(GO) test $(GOTEST_FLAGS) -tags='$(TAGS)' $$pkgs .PHONY: test-frontend test-frontend: node_modules ## test frontend files diff --git a/tools/find-gogit-test-pkgs.sh b/tools/find-gogit-test-pkgs.sh new file mode 100755 index 0000000000..59525644ad --- /dev/null +++ b/tools/find-gogit-test-pkgs.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail + +# Print packages whose own code or test code imports any of the gogit-affected +# modules (modules/git, modules/gitrepo, modules/lfs). These are the packages +# whose tests can observe behavioral differences between the bindata and +# bindata+gogit tag sets. + +tags=${1:?usage: $0 TAGS} + +go list -tags "$tags" -f '{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}|{{range .Imports}}{{.}};{{end}}{{range .TestImports}}{{.}};{{end}}{{range .XTestImports}}{{.}};{{end}}{{end}}' ./... \ + | awk -F'|' '$2 ~ /code\.gitea\.io\/gitea\/modules\/(git|gitrepo|lfs)([\.\/;]|$)/ { print $1 }' \ + | sort -u