Skip to content

Commit

Permalink
Create HtmlReportDir if not specified (#911)
Browse files Browse the repository at this point in the history
* Create HtmlReportDir if not specified

* Extend bitrise_dirs
  • Loading branch information
zsolt-vicze authored Jan 18, 2024
1 parent 3fad648 commit 0e9b1ac
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions _tests/integration/agent-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bitrise_dirs:
BITRISE_SOURCE_DIR: $INTEGRATION_TEST_BINARY_PATH/../agent/workspace/$BITRISE_APP_SLUG
BITRISE_DEPLOY_DIR: $INTEGRATION_TEST_BINARY_PATH/../agent/$BITRISE_APP_SLUG/$BITRISE_BUILD_SLUG/artifacts
BITRISE_TEST_DEPLOY_DIR: $INTEGRATION_TEST_BINARY_PATH/../agent/$BITRISE_APP_SLUG/$BITRISE_BUILD_SLUG/test_results
BITRISE_HTML_REPORT_DIR: $INTEGRATION_TEST_BINARY_PATH/../agent/$BITRISE_APP_SLUG/$BITRISE_BUILD_SLUG/html_reports

hooks:
cleanup_on_workflow_start:
Expand Down
8 changes: 6 additions & 2 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/bitrise-io/bitrise/configs"
"github.com/bitrise-io/bitrise/log"
"github.com/bitrise-io/colorstring"
"github.com/bitrise-io/bitrise/log/logwriter"
"github.com/bitrise-io/colorstring"
"github.com/bitrise-io/go-utils/pathutil"
)

Expand All @@ -33,6 +33,10 @@ func registerAgentOverrides(dirs configs.BitriseDirs) error {
dir: dirs.TestDeployDir,
envKey: configs.BitriseTestDeployDirEnvKey,
},
{
dir: dirs.HtmlReportDir,
envKey: configs.BitriseHtmlReportDirEnvKey,
},
}
for _, param := range params {
err := pathutil.EnsureDirExist(param.dir)
Expand Down Expand Up @@ -88,7 +92,7 @@ func cleanupDirs(dirs []string) error {
if len(dirs) == 0 {
return nil
}

log.Print()
log.Infof("Run directory cleanups")
for _, dir := range dirs {
Expand Down
4 changes: 4 additions & 0 deletions configs/agent_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type BitriseDirs struct {
// TestDeployDir is for deployable test result artifacts.
// It might be outside of BitriseDataHomeDir if the user has configured it so
TestDeployDir string `yaml:"BITRISE_TEST_DEPLOY_DIR"`

// HtmlReportDir is for deployable html reports.
// It might be outside of BitriseDataHomeDir if the user has configured it so
HtmlReportDir string `yaml:"BITRISE_HTML_REPORT_DIR"`
}

// AgentHooks are various hooks that are executed before and after the CLI runs a build.
Expand Down
35 changes: 24 additions & 11 deletions configs/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import (
)

var (
InputEnvstorePath string
OutputEnvstorePath string
FormattedOutputPath string
BitriseWorkDirPath string
InputEnvstorePath string
OutputEnvstorePath string
FormattedOutputPath string
BitriseWorkDirPath string
BitriseWorkStepsDirPath string
CurrentDir string
CurrentDir string
)

const (
EnvstorePathEnvKey = "ENVMAN_ENVSTORE_PATH"
FormattedOutputPathEnvKey = "BITRISE_STEP_FORMATTED_OUTPUT_FILE_PATH"
BitriseDataHomeDirEnvKey = "BITRISE_DATA_HOME_DIR"
BitriseSourceDirEnvKey = "BITRISE_SOURCE_DIR"
BitriseDeployDirEnvKey = "BITRISE_DEPLOY_DIR"
EnvstorePathEnvKey = "ENVMAN_ENVSTORE_PATH"
FormattedOutputPathEnvKey = "BITRISE_STEP_FORMATTED_OUTPUT_FILE_PATH"
BitriseDataHomeDirEnvKey = "BITRISE_DATA_HOME_DIR"
BitriseSourceDirEnvKey = "BITRISE_SOURCE_DIR"
BitriseDeployDirEnvKey = "BITRISE_DEPLOY_DIR"
BitriseTestDeployDirEnvKey = "BITRISE_TEST_DEPLOY_DIR"
// BitrisePerStepTestResultDirEnvKey is a unique subdirectory in BITRISE_TEST_DEPLOY_DIR for each step run, steps should place test reports and attachments into this directory
BitrisePerStepTestResultDirEnvKey = "BITRISE_TEST_RESULT_DIR"
BitriseTmpDirEnvKey = "BITRISE_TMP_DIR"
BitriseTmpDirEnvKey = "BITRISE_TMP_DIR"
BitriseHtmlReportDirEnvKey = "BITRISE_HTML_REPORT_DIR"
)

func GetBitriseHomeDirPath() string {
Expand Down Expand Up @@ -161,6 +162,18 @@ func InitPaths() error {
}
}

// BITRISE_HTML_REPORT_DIR
if os.Getenv(BitriseHtmlReportDirEnvKey) == "" {
reportDir, err := pathutil.NormalizedOSTempDirPath("html-reports")
if err != nil {
return fmt.Errorf("Failed to create html-reports dir, error: %s", err)
}

if err := os.Setenv(BitriseHtmlReportDirEnvKey, reportDir); err != nil {
return fmt.Errorf("Failed to set BITRISE_HTML_REPORT_DIR, error: %s", err)
}
}

// BITRISE_TEST_RESULTS_DIR
if os.Getenv(BitriseTestDeployDirEnvKey) == "" {
testsDir, err := pathutil.NormalizedOSTempDirPath("test_results")
Expand Down
15 changes: 15 additions & 0 deletions configs/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,19 @@ func TestInitPaths(t *testing.T) {
t.Setenv(BitriseTmpDirEnvKey, "$HOME/test")
require.Equal(t, nil, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(BitriseTmpDirEnvKey))

//
// BITRISE_HTML_REPORT_DIR

// Unset BITRISE_HTML_REPORT_DIR -> after InitPaths BITRISE_HTML_REPORT_DIR should be temp dir
if os.Getenv(BitriseHtmlReportDirEnvKey) != "" {
require.Equal(t, nil, os.Unsetenv(BitriseHtmlReportDirEnvKey))
}
require.Equal(t, nil, InitPaths())
require.NotEqual(t, "", os.Getenv(BitriseHtmlReportDirEnvKey))

// Set BITRISE_HTML_REPORT_DIR -> after InitPaths BITRISE_TEST_DEPLOY_DIR should keep content
t.Setenv(BitriseHtmlReportDirEnvKey, "$HOME/test")
require.Equal(t, nil, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(BitriseHtmlReportDirEnvKey))
}

0 comments on commit 0e9b1ac

Please sign in to comment.