Skip to content

Commit

Permalink
Better nested handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai committed Nov 21, 2023
1 parent 42709ad commit 487c681
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
13 changes: 0 additions & 13 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 == "" {
Expand Down
8 changes: 7 additions & 1 deletion cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 487c681

Please sign in to comment.