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

Fix per-step test result dir handling #923

Merged
merged 1 commit into from
Mar 18, 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
23 changes: 16 additions & 7 deletions cli/run_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,25 @@ func (r WorkflowRunner) activateAndRunSteps(
"BITRISE_STEP_SOURCE_DIR": stepDir,
})

// ensure a new testDirPath and if created successfuly then attach it to the step process by and env
testDirPath, err := ioutil.TempDir(os.Getenv(configs.BitriseTestDeployDirEnvKey), "test_result")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ioutil.TempDir() is deprecated and calls os.Mkdir() directly since Go 1.17

testDeployDir := os.Getenv(configs.BitriseTestDeployDirEnvKey)
// If testDeployDir is empty, MkdirTemp() will use the default temp dir. But if it points to a path,
// we have to create it first.
if testDeployDir != "" {
err = os.MkdirAll(testDeployDir, 0755)
if err != nil {
log.Warnf("Failed to create %s, error: %s", configs.BitriseTestDeployDirEnvKey, err)
testDeployDir = ""
}
}
stepTestDir, err := os.MkdirTemp(testDeployDir, "step_test_result")
if err != nil {
log.Errorf("Failed to create test result dir, error: %s", err)
log.Errorf("Failed to create per-step test result dir: %s", err)
}

if testDirPath != "" {
if stepTestDir != "" {
// managed to create the test dir, set the env for it for the next step run
additionalEnvironments = append(additionalEnvironments, envmanModels.EnvironmentItemModel{
configs.BitrisePerStepTestResultDirEnvKey: testDirPath,
configs.BitrisePerStepTestResultDirEnvKey: stepTestDir,
})
}

Expand Down Expand Up @@ -904,8 +913,8 @@ func (r WorkflowRunner) activateAndRunSteps(

exit, outEnvironments, err := r.runStep(stepExecutionID, mergedStep, stepIDData, stepDir, stepDeclaredEnvironments, stepSecretValues, workflow, workflowID)

if testDirPath != "" {
if err := addTestMetadata(testDirPath, models.TestResultStepInfo{Number: idx, Title: *mergedStep.Title, ID: stepIDData.IDorURI, Version: stepIDData.Version}); err != nil {
if stepTestDir != "" {
if err := addTestMetadata(stepTestDir, models.TestResultStepInfo{Number: idx, Title: *mergedStep.Title, ID: stepIDData.IDorURI, Version: stepIDData.Version}); err != nil {
log.Errorf("Failed to normalize test result dir, error: %s", err)
}
}
Expand Down