Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --bulk to containerless analysis #371

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions cmd/analyze-bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"runtime"
"sort"
"strings"
"sync"

"github.com/bombsimon/logrusr/v3"
Expand Down Expand Up @@ -533,16 +534,40 @@ func (a *analyzeCommand) DependencyOutputContainerless(ctx context.Context, prov

func (a *analyzeCommand) buildStaticReportFile(ctx context.Context, staticReportPath string, depsErr bool) error {
// Prepare report args list with single input analysis
applicationName := []string{filepath.Base(a.input)}
outputAnalysis := []string{filepath.Join(a.output, "output.yaml")}
applicationNames := []string{filepath.Base(a.input)}
outputAnalyses := []string{filepath.Join(a.output, "output.yaml")}
outputDeps := []string{filepath.Join(a.output, "dependencies.yaml")}
outputJSPath := filepath.Join(staticReportPath, "output.js")

if a.bulk {
// Scan all available analysis output files to be reported
applicationNames = nil
outputAnalyses = nil
outputDeps = nil
outputFiles, err := filepath.Glob(filepath.Join(a.output, "output.yaml.*"))
if err != nil {
return err
}
for i := range outputFiles {
outputName := filepath.Base(outputFiles[i])
applicationName := strings.SplitN(outputName, "output.yaml.", 2)[1]
applicationNames = append(applicationNames, applicationName)
outputAnalyses = append(outputAnalyses, outputFiles[i])
deps := fmt.Sprintf("%s.%s", filepath.Join(a.output, "dependencies.yaml"), applicationName)
// If deps for given application are missing, empty the deps path allowing skip it in static-report
if _, err := os.Stat(deps); errors.Is(err, os.ErrNotExist) {
deps = ""
}
outputDeps = append(outputDeps, deps)
}

}

if depsErr {
outputDeps = []string{}
}
// create output.js file from analysis output.yaml
apps, err := validateFlags(outputAnalysis, applicationName, outputDeps, a.log)
apps, err := validateFlags(outputAnalyses, applicationNames, outputDeps, a.log)
if err != nil {
log.Fatalln("failed to validate flags", err)
}
Expand Down Expand Up @@ -595,8 +620,12 @@ func (a *analyzeCommand) GenerateStaticReportContainerless(ctx context.Context)
return noDepFileErr
}

staticReportAanlyzePath := filepath.Join(a.kantraDir, "static-report")
err = a.buildStaticReportFile(ctx, staticReportAanlyzePath, errors.Is(noDepFileErr, os.ErrNotExist))
if a.bulk {
a.moveResults()
}

staticReportAnalyzePath := filepath.Join(a.kantraDir, "static-report")
err = a.buildStaticReportFile(ctx, staticReportAnalyzePath, errors.Is(noDepFileErr, os.ErrNotExist))
if err != nil {
return err
}
Expand Down
Loading