Skip to content

Commit

Permalink
[feat]: [CI-13358]: Show stage savings for cache intel (#299)
Browse files Browse the repository at this point in the history
* [feat]: [CI-13358]: Show stage savings for cache intel

* Update runtest.go

* rename

* Update savings.go
  • Loading branch information
anurag-harness authored Jul 8, 2024
1 parent e069a15 commit 2fa6f03
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions pipeline/runtime/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"time"

"github.com/drone/runner-go/pipeline/runtime"
v2 "github.com/harness/godotenv/v2"
v3 "github.com/harness/godotenv/v3"
"github.com/harness/lite-engine/api"
Expand Down Expand Up @@ -206,3 +207,11 @@ func waitForZipUnlock(timeout time.Duration, tiConfig *tiCfg.Cfg) error {
}
}
}

// checkStepSuccess checks if the step was successful based on the return values
func checkStepSuccess(state *runtime.State, err error) bool {
if err == nil && state != nil && state.ExitCode == 0 && state.Exited {
return true
}
return false
}
2 changes: 1 addition & 1 deletion pipeline/runtime/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func executeRunStep(ctx context.Context, f RunFunc, r *api.StartStepRequest, out

// Parse and upload savings to TI
if tiConfig.GetParseSavings() {
optimizationState = savings.ParseAndUploadSavings(ctx, r.WorkingDir, log, step.Name, timeTakenMs, tiConfig, r.Envs)
optimizationState = savings.ParseAndUploadSavings(ctx, r.WorkingDir, log, step.Name, checkStepSuccess(exited, err), timeTakenMs, tiConfig, r.Envs)
}

useCINewGodotEnvVersion := false
Expand Down
2 changes: 1 addition & 1 deletion pipeline/runtime/runtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func executeRunTestStep(ctx context.Context, f RunFunc, r *api.StartStepRequest,

// Parse and upload savings to TI
if tiConfig.GetParseSavings() {
optimizationState = savings.ParseAndUploadSavings(ctx, r.WorkingDir, log, step.Name, timeTakenMs, tiConfig, r.Envs)
optimizationState = savings.ParseAndUploadSavings(ctx, r.WorkingDir, log, step.Name, checkStepSuccess(exited, err), timeTakenMs, tiConfig, r.Envs)
}

useCINewGodotEnvVersion := false
Expand Down
2 changes: 1 addition & 1 deletion pipeline/runtime/runtestsV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func executeRunTestsV2Step(ctx context.Context, f RunFunc, r *api.StartStepReque
}

if tiConfig.GetParseSavings() {
optimizationState = savings.ParseAndUploadSavings(ctx, r.WorkingDir, log, step.Name, timeTakenMs, tiConfig, r.Envs)
optimizationState = savings.ParseAndUploadSavings(ctx, r.WorkingDir, log, step.Name, checkStepSuccess(exited, err), timeTakenMs, tiConfig, r.Envs)
}

useCINewGodotEnvVersion := false
Expand Down
15 changes: 13 additions & 2 deletions ti/savings/savings.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/sirupsen/logrus"
)

func ParseAndUploadSavings(ctx context.Context, workspace string, log *logrus.Logger, stepID string, cmdTimeTaken int64,
const restoreCacheHarnessStepID = "restore-cache-harness"

func ParseAndUploadSavings(ctx context.Context, workspace string, log *logrus.Logger, stepID string, stepSuccess bool, cmdTimeTaken int64,
tiConfig *tiCfg.Cfg, envs map[string]string) types.IntelligenceExecutionState {
states := make([]types.IntelligenceExecutionState, 0)
// Cache Savings
Expand Down Expand Up @@ -62,7 +64,16 @@ func ParseAndUploadSavings(ctx context.Context, workspace string, log *logrus.Lo
}
}
}
// Cache Intel savings (Placeholder)

// Cache Intel savings
if stepID == restoreCacheHarnessStepID {
cacheIntelState := types.FULL_RUN
if stepSuccess {
cacheIntelState = types.OPTIMIZED
}
states = append(states, cacheIntelState)
}

return getStepState(states)
}

Expand Down

0 comments on commit 2fa6f03

Please sign in to comment.