From 0e9b1ac3542196af635ff329971c62c193f8ee15 Mon Sep 17 00:00:00 2001 From: zsolt-vicze <104844424+zsolt-vicze@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:21:47 +0000 Subject: [PATCH] Create HtmlReportDir if not specified (#911) * Create HtmlReportDir if not specified * Extend bitrise_dirs --- _tests/integration/agent-config.yml | 1 + cli/agent.go | 8 +++++-- configs/agent_config.go | 4 ++++ configs/paths.go | 35 ++++++++++++++++++++--------- configs/paths_test.go | 15 +++++++++++++ 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/_tests/integration/agent-config.yml b/_tests/integration/agent-config.yml index c18a0999..72881225 100644 --- a/_tests/integration/agent-config.yml +++ b/_tests/integration/agent-config.yml @@ -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: diff --git a/cli/agent.go b/cli/agent.go index d349c119..c256a653 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -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" ) @@ -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) @@ -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 { diff --git a/configs/agent_config.go b/configs/agent_config.go index 955c3f66..bc831201 100644 --- a/configs/agent_config.go +++ b/configs/agent_config.go @@ -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. diff --git a/configs/paths.go b/configs/paths.go index 8bff7fd5..392913a4 100644 --- a/configs/paths.go +++ b/configs/paths.go @@ -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 { @@ -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") diff --git a/configs/paths_test.go b/configs/paths_test.go index 44c62a80..dfd32dca 100644 --- a/configs/paths_test.go +++ b/configs/paths_test.go @@ -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)) }