0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-10 14:01:54 +02:00

ci: derive gogit test packages dynamically from imports

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) <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-05-09 01:41:51 +02:00
parent 8d6615f939
commit 4037cd51c3
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
2 changed files with 17 additions and 4 deletions

View File

@ -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

13
tools/find-gogit-test-pkgs.sh Executable file
View File

@ -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