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

Agent hooks #896

Merged
merged 13 commits into from
Nov 21, 2023
Merged

Agent hooks #896

merged 13 commits into from
Nov 21, 2023

Conversation

ofalvai
Copy link
Contributor

@ofalvai ofalvai commented Nov 17, 2023

Checklist

Version

Requires a MINOR version update

Context

Same theme as #894, but this PR is about running arbitrary commands before and after the CLI picks up a build in agent mode.

Changes

  • Rename some config fields from workflow to build as these actions are meant to be run in the context of a build, i.e. when an agent picks up a build to execute. One such CLI invocation can result in multiple workflows executed, such as run_before, run_after and inner bitrise run workflow calls.
  • Move dir override handling to cli/agent.go
  • Run build start/end hooks at the right time. Output is streamed to stdout and a non-zero exit code results in a failed execution.

Investigation details

Decisions

@ofalvai ofalvai marked this pull request as ready for review November 20, 2023 11:36
return nil
}

if os.Getenv(analytics.StepExecutionIDEnvKey) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work with Run bitrise Step too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the point of this. Everything running in a scrip step has this env var defined, so the CLI process spawned there will run into this block.

cli/agent.go Outdated
log.Print()

cmd := exec.Command(hooks.DoOnBuildStart)
cmd.Stdout = os.Stdout
Copy link
Contributor

Choose a reason for hiding this comment

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

Logging to stdout could be problematic as it would not be in the JSON log format expected in CI run. It can be omitted or wrapped in additional logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, good point! Take a look now

type WorkflowRunner struct {
config RunConfig
config RunConfig
agentConfig *configs.AgentConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you document why agentconfig has top be seperate from config for posterity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@ofalvai ofalvai merged commit 0f81204 into master Nov 21, 2023
@ofalvai ofalvai deleted the BE-1249-agent-hooks branch November 21, 2023 14:15
@ofalvai ofalvai mentioned this pull request Nov 22, 2023
2 tasks
@godrei godrei mentioned this pull request Nov 30, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants