Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions internal/discovery/dependencydiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,21 @@ func (dd *DependencyDiscovery) dependencyToDiscover(
// Record in report as excluded external dependency
if dd.report != nil {
absPath := util.CleanPath(depPath)
run, _ := dd.report.EnsureRun(absPath)
_ = dd.report.EndRun(run.Path, report.WithResult(report.ResultExcluded), report.WithReason(report.ReasonExcludeExternal))

_, err := dd.report.EnsureRun(l, absPath)
if err != nil {
l.Errorf("Error ensuring run for excluded external dependency %s: %v", absPath, err)
}

err = dd.report.EndRun(
l,
absPath,
report.WithResult(report.ResultExcluded),
report.WithReason(report.ReasonExcludeExternal),
)
if err != nil {
l.Errorf("Error ending run for excluded external dependency %s: %v", absPath, err)
}
}

dd.markSeen(depPath)
Expand Down
18 changes: 14 additions & 4 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"slices"
"sync"
"time"

"github.com/gruntwork-io/terragrunt/pkg/log"
)

// Report captures data for a report/summary.
Expand Down Expand Up @@ -129,7 +131,7 @@ var ErrRunAlreadyExists = errors.New("run already exists")

// AddRun adds a run to the report.
// If the run already exists, it returns the ErrRunAlreadyExists error.
func (r *Report) AddRun(run *Run) error {
func (r *Report) AddRun(l log.Logger, run *Run) error {
r.mu.Lock()
defer r.mu.Unlock()

Expand All @@ -139,6 +141,8 @@ func (r *Report) AddRun(run *Run) error {
}
}

l.Debugf("Adding report run %s", run.Path)

r.Runs = append(r.Runs, run)

return nil
Expand Down Expand Up @@ -169,22 +173,26 @@ func (r *Report) GetRun(path string) (*Run, error) {
// EnsureRun tries to get a run from the report.
// If the run does not exist, it creates a new run and adds it to the report, then returns the run.
// This is useful when a run is being ended that might not have been started due to exclusion, etc.
func (r *Report) EnsureRun(path string) (*Run, error) {
func (r *Report) EnsureRun(l log.Logger, path string) (*Run, error) {
run, err := r.GetRun(path)
if err == nil {
l.Debugf("Report run %s already exists, returning existing run", path)

return run, nil
}

if !errors.Is(err, ErrRunNotFound) {
return run, err
}

l.Debugf("Report run %s not found, creating new run", path)

run, err = NewRun(path)
if err != nil {
return run, err
}

if err = r.AddRun(run); err != nil {
if err = r.AddRun(l, run); err != nil {
return run, err
}

Expand All @@ -195,7 +203,7 @@ func (r *Report) EnsureRun(path string) (*Run, error) {
// If the run does not exist, it returns the ErrRunNotFound error.
// By default, the run is assumed to have succeeded. To change this, pass WithResult to the function.
// If the run has already ended from an early exit, it does nothing.
func (r *Report) EndRun(path string, endOptions ...EndOption) error {
func (r *Report) EndRun(l log.Logger, path string, endOptions ...EndOption) error {
r.mu.Lock()
defer r.mu.Unlock()

Expand Down Expand Up @@ -231,6 +239,8 @@ func (r *Report) EndRun(path string, endOptions ...EndOption) error {
endOption(run)
}

l.Debugf("Ending report run %s with result %s", path, run.Result)

return nil
}

Expand Down
Loading
Loading