Validate and publish source-only candidates
This commit is contained in:
@@ -28,7 +28,7 @@ func BenchmarkSelectInputEntriesByModuleCount(b *testing.B) {
|
||||
}
|
||||
b.ReportAllocs()
|
||||
for b.Loop() {
|
||||
selected, err := selectInputEntries(entries, byPath, ".", []string{})
|
||||
selected, err := selectInputEntries(entries, byPath, ".", []string{}, false)
|
||||
if err != nil || len(selected) != retainedFiles {
|
||||
b.Fatalf("selected %d files, error=%v; want %d", len(selected), err, retainedFiles)
|
||||
}
|
||||
|
||||
@@ -28,13 +28,14 @@ type CandidateTree struct {
|
||||
closeErr error
|
||||
}
|
||||
|
||||
// TreeScope selects the automatic input files for one physical module and
|
||||
// optional repository-shared files. ModuleDir is an absolute path. A nil
|
||||
// SharedFiles slice selects the optional default files; a non-nil slice
|
||||
// replaces those defaults.
|
||||
// TreeScope selects automatic input files under an absolute physical source
|
||||
// directory and optional repository-shared files. A nil SharedFiles slice
|
||||
// selects optional defaults; a non-nil slice replaces them. IncludeNestedModules
|
||||
// treats nested module declarations as ordinary files.
|
||||
type TreeScope struct {
|
||||
ModuleDir string
|
||||
SharedFiles []string
|
||||
ModuleDir string
|
||||
SharedFiles []string
|
||||
IncludeNestedModules bool
|
||||
}
|
||||
|
||||
// ReadCandidateTree enumerates the captured commit without reading from the
|
||||
@@ -74,7 +75,7 @@ func ReadCandidateTreeForScope(ctx context.Context, repositoryDir, commit string
|
||||
tree.directories[directory] = struct{}{}
|
||||
}
|
||||
}
|
||||
tree.inputEntries, err = selectInputEntries(entries, tree.byPath, modulePath, scope.SharedFiles)
|
||||
tree.inputEntries, err = selectInputEntries(entries, tree.byPath, modulePath, scope.SharedFiles, scope.IncludeNestedModules)
|
||||
if err != nil {
|
||||
_ = tree.Close()
|
||||
return nil, err
|
||||
@@ -94,17 +95,19 @@ func (tree *CandidateTree) InputEntries() []git.TreeEntry {
|
||||
return append([]git.TreeEntry(nil), tree.inputEntries...)
|
||||
}
|
||||
|
||||
func selectInputEntries(entries []git.TreeEntry, byPath map[string]int, modulePath string, sharedFiles []string) ([]git.TreeEntry, error) {
|
||||
func selectInputEntries(entries []git.TreeEntry, byPath map[string]int, modulePath string, sharedFiles []string, includeNestedModules bool) ([]git.TreeEntry, error) {
|
||||
boundaries := make(map[string]struct{})
|
||||
for _, entry := range entries {
|
||||
moduleRelative, ok := relativeToModule(entry.Path, modulePath)
|
||||
if !ok || moduleRelative == "go.mod" || path.Base(moduleRelative) != "go.mod" {
|
||||
continue
|
||||
if !includeNestedModules {
|
||||
for _, entry := range entries {
|
||||
moduleRelative, ok := relativeToModule(entry.Path, modulePath)
|
||||
if !ok || moduleRelative == "go.mod" || path.Base(moduleRelative) != "go.mod" {
|
||||
continue
|
||||
}
|
||||
if insideVendor(moduleRelative) {
|
||||
continue
|
||||
}
|
||||
boundaries[path.Dir(entry.Path)] = struct{}{}
|
||||
}
|
||||
if insideVendor(moduleRelative) {
|
||||
continue
|
||||
}
|
||||
boundaries[path.Dir(entry.Path)] = struct{}{}
|
||||
}
|
||||
selected := make(map[string]git.TreeEntry)
|
||||
for _, entry := range entries {
|
||||
|
||||
@@ -151,6 +151,26 @@ func TestReadCandidateTreeForRootScopeExcludesNestedModules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceScopeIncludesNestedModuleFiles(t *testing.T) {
|
||||
repository := newTreeRepository(t)
|
||||
writeTreeFile(t, repository, "config/readme.md", []byte("# Configuration\n"))
|
||||
writeTreeFile(t, repository, "config/nested/go.mod", []byte("data\n"))
|
||||
writeTreeFile(t, repository, "config/nested/readme.md", []byte("# Nested\n"))
|
||||
writeTreeFile(t, repository, "outside/readme.md", []byte("# Outside\n"))
|
||||
commit := commitCandidateTree(t, repository)
|
||||
tree, err := ReadCandidateTreeForScope(context.Background(), repository, commit, TreeScope{
|
||||
ModuleDir: filepath.Join(repository, "config"), SharedFiles: []string{}, IncludeNestedModules: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cleanupCandidateTree(t, tree)
|
||||
want := "config/nested/go.mod\nconfig/nested/readme.md\nconfig/readme.md"
|
||||
if got := strings.Join(inputPaths(tree), "\n"); got != want {
|
||||
t.Fatalf("source inputs = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadCandidateTreeSharedFilesReplaceDefaultsAndDeduplicate(t *testing.T) {
|
||||
repository := newTreeRepository(t)
|
||||
writeTreeFile(t, repository, "LICENSE", []byte("default\n"))
|
||||
|
||||
@@ -55,6 +55,8 @@ type Target struct {
|
||||
type Request struct {
|
||||
RepositoryDir string
|
||||
ModuleDir string
|
||||
SourceDir string
|
||||
SourceOnly bool
|
||||
Commit string
|
||||
Output io.Writer
|
||||
Settings Settings
|
||||
@@ -64,9 +66,14 @@ type Request struct {
|
||||
// ReadCandidateTree loads the committed-file inventory when a selected check
|
||||
// needs file-oriented input.
|
||||
func (request Request) ReadCandidateTree(ctx context.Context) (*CandidateTree, error) {
|
||||
directory := request.ModuleDir
|
||||
if request.SourceOnly {
|
||||
directory = request.SourceDir
|
||||
}
|
||||
return ReadCandidateTreeForScope(ctx, request.RepositoryDir, request.Commit, TreeScope{
|
||||
ModuleDir: request.ModuleDir,
|
||||
SharedFiles: request.Settings.SharedFiles,
|
||||
ModuleDir: directory,
|
||||
SharedFiles: request.Settings.SharedFiles,
|
||||
IncludeNestedModules: request.SourceOnly,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -89,8 +96,14 @@ func Run(ctx context.Context, request Request) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := runGoChecks(ctx, request); err != nil {
|
||||
return err
|
||||
if request.SourceOnly {
|
||||
if request.Settings.Race || request.Settings.FullVet || len(request.Settings.CompileTargets) != 0 {
|
||||
return fmt.Errorf("Go execution checks require Go capability")
|
||||
}
|
||||
} else {
|
||||
if err := runGoChecks(ctx, request); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return runTreeChecks(ctx, request)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user