From 4037cd51c3eda399693052bca1a0c43f9bc74954 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 9 May 2026 01:41:51 +0200 Subject: [PATCH] ci: derive gogit test packages dynamically from imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the hardcoded list of three top-level paths (modules/git, modules/gitrepo, modules/lfs) with an at-build-time derivation. tools/find-gogit-test-pkgs.sh queries `go list` for every package whose own code or test code imports any of the gogit-affected modules — currently 72 packages — and feeds that list into `make test-backend-gogit`. This restores coverage that the static list dropped: callers like models/git, services/repository, modules/repository, etc., whose unit tests transitively exercise gogit/nogogit code paths via the modules/git API. Co-Authored-By: Claude (Opus 4.7) --- Makefile | 8 ++++---- tools/find-gogit-test-pkgs.sh | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100755 tools/find-gogit-test-pkgs.sh 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