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

Publish workflow invocation workspace status event sooner #6529

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions enterprise/server/cmd/ci_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,25 @@ func (ar *actionRunner) Run(ctx context.Context, ws *workspace) error {
return nil
}
}
workspaceStatusEvent := &bespb.BuildEvent{
Id: &bespb.BuildEventId{Id: &bespb.BuildEventId_WorkspaceStatus{WorkspaceStatus: &bespb.BuildEventId_WorkspaceStatusId{}}},
Payload: &bespb.BuildEvent_WorkspaceStatus{WorkspaceStatus: &bespb.WorkspaceStatus{
Item: []*bespb.WorkspaceStatus_Item{
{Key: "BUILD_USER", Value: ar.username},
{Key: "BUILD_HOST", Value: ar.hostname},
{Key: "GIT_BRANCH", Value: *pushedBranch},
{Key: "GIT_TREE_STATUS", Value: "Clean"},
// Note: COMMIT_SHA may not actually reflect the current state of the
// repo since we merge the target branch before running the workflow;
// we set this for the purpose of reporting statuses to GitHub.
{Key: "COMMIT_SHA", Value: *commitSHA},
Copy link
Contributor

@maggie-lou maggie-lou May 8, 2024

Choose a reason for hiding this comment

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

One thing to note is that we sometimes set commitSha in sync() if it was not passed in as a flag (i.e. only a branch was passed). For that case, now the UI won't contain the commit sha

That should only happen in the ExecuteWorkflow API though, and in most cases we'd expect both to be set, so I think this is still worth it

Copy link
Member Author

@bduffany bduffany May 8, 2024

Choose a reason for hiding this comment

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

If this becomes a major issue for people, we could write to the DB twice, once when seeing WorkflowConfigured and once when seeing WorkspaceStatus, then move this back to after the git repo is fetched

Copy link
Member Author

@bduffany bduffany May 8, 2024

Choose a reason for hiding this comment

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

hmm actually I think this would affect any users who are currently using the ExecuteWorkflow API. For those people, we would wind up setting COMMIT_SHA to an empty string which would break GH status publishing.

@tylerwilliams wdyt about allowing workflows to do 1 extra invocation DB write - once when getting WorkflowConfigured, and once after checking out the git repo (which is when we can reliably compute WorkspaceStatus)? The problem it'd solve is that today, we don't always know the commit_sha until checking out the repo, but if the git fetch is slow then the user is stuck in this "Invocation in progress..." page until it's done, rather than being able to see incremental progress

{Key: "REPO_URL", Value: baseURL},
},
}},
}
if err := ar.reporter.Publish(workspaceStatusEvent); err != nil {
return nil
}

if err := ws.setup(ctx); err != nil {
return status.WrapError(err, "failed to set up git repo")
Expand Down Expand Up @@ -903,26 +922,6 @@ func (ar *actionRunner) Run(ctx context.Context, ws *workspace) error {
return nil
}

workspaceStatusEvent := &bespb.BuildEvent{
Id: &bespb.BuildEventId{Id: &bespb.BuildEventId_WorkspaceStatus{WorkspaceStatus: &bespb.BuildEventId_WorkspaceStatusId{}}},
Payload: &bespb.BuildEvent_WorkspaceStatus{WorkspaceStatus: &bespb.WorkspaceStatus{
Item: []*bespb.WorkspaceStatus_Item{
{Key: "BUILD_USER", Value: ar.username},
{Key: "BUILD_HOST", Value: ar.hostname},
{Key: "GIT_BRANCH", Value: *pushedBranch},
{Key: "GIT_TREE_STATUS", Value: "Clean"},
// Note: COMMIT_SHA may not actually reflect the current state of the
// repo since we merge the target branch before running the workflow;
// we set this for the purpose of reporting statuses to GitHub.
{Key: "COMMIT_SHA", Value: *commitSHA},
{Key: "REPO_URL", Value: baseURL},
},
}},
}
if err := ar.reporter.Publish(workspaceStatusEvent); err != nil {
return nil
}

if ws.setupError != nil {
return ws.setupError
}
Expand Down
Loading