Skip to content

Commit

Permalink
worker: run dynamic and static analysis unconditionally (#921)
Browse files Browse the repository at this point in the history
* worker: run dynamic and static analysis unconditionally and don't let errors for one type of analysis cause the other to be skipped (including saving of results)

Signed-off-by: Max Fisher <[email protected]>

* run static analysis before dynamic analysis to preserve order of saving

Signed-off-by: Max Fisher <[email protected]>

---------

Signed-off-by: Max Fisher <[email protected]>
  • Loading branch information
maxfisher-g authored Oct 16, 2023
1 parent f382942 commit 5133dd6
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/ossf/package-analysis/internal/sandbox"
"github.com/ossf/package-analysis/internal/staticanalysis"
"github.com/ossf/package-analysis/internal/worker"
"github.com/ossf/package-analysis/pkg/api/analysisrun"
"github.com/ossf/package-analysis/pkg/api/pkgecosystem"
)

Expand Down Expand Up @@ -153,34 +152,30 @@ func handleMessage(ctx context.Context, msg *pubsub.Message, packagesBucket *blo
return err
}

staticSandboxOpts := append(worker.StaticSandboxOptions(), sandboxOpts...)
dynamicSandboxOpts := append(worker.DynamicSandboxOptions(), sandboxOpts...)
result, err := worker.RunDynamicAnalysis(ctx, pkg, dynamicSandboxOpts, "")
if err != nil {
return err
}

staticSandboxOpts := append(worker.StaticSandboxOptions(), sandboxOpts...)
var staticResults analysisrun.StaticAnalysisResults
// TODO run static analysis first and remove the if statement below
if resultStores.StaticAnalysis != nil {
staticResults, _, err = worker.RunStaticAnalysis(ctx, pkg, staticSandboxOpts, staticanalysis.All)
if err != nil {
return err
}
// run both dynamic and static analysis regardless of error status of either
// and return combined error(s) afterwards, if applicable
staticResults, _, staticAnalysisErr := worker.RunStaticAnalysis(ctx, pkg, staticSandboxOpts, staticanalysis.All)
if staticAnalysisErr == nil {
staticAnalysisErr = worker.SaveStaticAnalysisData(ctx, pkg, resultStores, staticResults)
}

if err := worker.SaveStaticAnalysisData(ctx, pkg, resultStores, staticResults); err != nil {
return err
}
if err := worker.SaveDynamicAnalysisData(ctx, pkg, resultStores, result.AnalysisData); err != nil {
return err
result, dynamicAnalysisErr := worker.RunDynamicAnalysis(ctx, pkg, dynamicSandboxOpts, "")
if dynamicAnalysisErr == nil {
dynamicAnalysisErr = worker.SaveDynamicAnalysisData(ctx, pkg, resultStores, result.AnalysisData)
}

resultStores.AnalyzedPackageSaved = false

// combine errors
if analysisErr := errors.Join(dynamicAnalysisErr, staticAnalysisErr); analysisErr != nil {
return analysisErr
}

if notificationTopic != nil {
err := notification.PublishAnalysisCompletion(ctx, notificationTopic, name, version, ecosystem)
if err != nil {
if err := notification.PublishAnalysisCompletion(ctx, notificationTopic, name, version, ecosystem); err != nil {
return err
}
}
Expand Down

0 comments on commit 5133dd6

Please sign in to comment.