From 487c681b790e26c8e0ed2d39b07b12933b5034dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olive=CC=81r=20Falvai?= Date: Tue, 21 Nov 2023 16:58:47 +0100 Subject: [PATCH] Better nested handling --- cli/agent.go | 13 ------------- cli/run.go | 8 +++++++- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/cli/agent.go b/cli/agent.go index eb68e0724..958445b13 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -54,12 +54,6 @@ func runBuildStartHooks(hooks configs.AgentHooks) error { return nil } - if os.Getenv(analytics.StepExecutionIDEnvKey) != "" { - // Edge case: this Bitrise process was started by a script step running `bitrise run x`. - // In that case, we don't want to run the hooks because they would be executed twice. - return nil - } - log.Print() log.Infof("Run build start hook") log.Print(hooks.DoOnBuildStart) @@ -78,12 +72,6 @@ func runBuildEndHooks(hooks configs.AgentHooks) error { return nil } - if os.Getenv(analytics.StepExecutionIDEnvKey) != "" { - // Edge case: this Bitrise process was started by a script step running `bitrise run x`. - // In that case, we don't want to run the hooks because they would be executed twice. - return nil - } - log.Print() log.Infof("Run build end hook") log.Print(hooks.DoOnBuildEnd) @@ -104,7 +92,6 @@ func cleanupDirs(dirs []string) error { log.Print() log.Infof("Run cleanups before build") - log.Print() for _, dir := range dirs { expandedPath := os.ExpandEnv(dir) if expandedPath == "" { diff --git a/cli/run.go b/cli/run.go index 8db3d7748..c56d44b50 100644 --- a/cli/run.go +++ b/cli/run.go @@ -89,6 +89,12 @@ func run(c *cli.Context) error { if err != nil { failf("Failed to process agent config: %w", err) } + if agentConfig != nil && os.Getenv(analytics.StepExecutionIDEnvKey) != "" { + // Edge case: this Bitrise process was started by a script step running `bitrise run x`. + log.Warn("Bitrise is configured to run in agent mode, but this is a nested execution.") + log.Warn("Hooks and directory cleanups won't be executed in this process to avoid running them multiple times.") + agentConfig = nil + } runner := NewWorkflowRunner(*config, agentConfig) exitCode, err := runner.RunWorkflowsWithSetupAndCheckForUpdate() @@ -165,7 +171,7 @@ func (r WorkflowRunner) RunWorkflowsWithSetupAndCheckForUpdate() (int, error) { return 1, fmt.Errorf("setup failed: %s", err) } - if r.agentConfig != nil { + if r.agentConfig != nil && os.Getenv(analytics.StepExecutionIDEnvKey) == "" { if err := runBuildStartHooks(r.agentConfig.Hooks); err != nil { return 1, fmt.Errorf("build start hooks: %s", err) }