Skip to content

Commit 2bb529b

Browse files
committed
Always update checkrun status for terraform workflows
Why? * Terraform workflows cannot cancel due to WaitForCancellation, so we might as well try to update the status of the checkrun. * We also think this will help with the non determinism issues we are seeing where cancellations can occur at different than expected times on replay, causing the checkrun cache to be inaccurate, thus causing wrong calls to either create or update.
1 parent ef108a9 commit 2bb529b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

server/neptune/workflows/internal/pr/revision/processor.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
)
1818

1919
const (
20-
ReviewSignalID = "pr-review"
21-
CheckRunCancelled = "checkrun was cancelled"
20+
ReviewSignalID = "pr-review"
21+
CheckRunCancelled = "checkrun was cancelled"
22+
NotifyAllCheckRunsChangeID = "notify-all-checkruns-always"
2223
)
2324

2425
type TFWorkflow func(ctx workflow.Context, request terraform.Request) (terraform.Response, error)
@@ -72,9 +73,11 @@ func (p *Processor) Process(ctx workflow.Context, prRevision Revision) {
7273
// Mark checkruns as aborted if the context was cancelled, this typically happens if revisions arrive in quick succession
7374
defer func() {
7475
if temporal.IsCanceledError(ctx.Err()) {
75-
ctx, _ := workflow.NewDisconnectedContext(ctx)
76-
p.markCheckRunsAborted(ctx, prRevision, roots)
77-
return
76+
version := workflow.GetVersion(ctx, NotifyAllCheckRunsChangeID, workflow.DefaultVersion, 1)
77+
if version == workflow.DefaultVersion {
78+
p.markCheckRunsAborted(ctx, prRevision, roots)
79+
return
80+
}
7881
}
7982

8083
// At this point, all workflows should be successful, and we can mark combined plan check run as success
@@ -131,6 +134,13 @@ func (p *Processor) awaitChildTerraformWorkflows(ctx workflow.Context, futures [
131134
selector := workflow.NewNamedSelector(ctx, "TerraformChildWorkflow")
132135
ch := workflow.GetSignalChannel(ctx, state.WorkflowStateChangeSignal)
133136
selector.AddReceive(ch, func(c workflow.ReceiveChannel, _ bool) {
137+
// The parent workflow can be cancelled when a new revision is received, but we still would like to notify
138+
// state of any of the terraform workflows which will finish regardless of parent cancellation.
139+
ctx := ctx
140+
version := workflow.GetVersion(ctx, NotifyAllCheckRunsChangeID, workflow.DefaultVersion, 1)
141+
if version == 1 {
142+
ctx, _ = workflow.NewDisconnectedContext(ctx)
143+
}
134144
p.TFStateReceiver.Receive(ctx, c, roots)
135145
})
136146

@@ -182,7 +192,6 @@ func (p *Processor) markCombinedCheckRun(ctx workflow.Context, revision Revision
182192

183193
func (p *Processor) markCheckRunsAborted(ctx workflow.Context, revision Revision, roots map[string]RootInfo) {
184194
p.markCombinedCheckRun(ctx, revision, github.CheckRunCancelled, CheckRunCancelled)
185-
186195
for _, rootInfo := range roots {
187196
ctx = workflow.WithRetryPolicy(ctx, temporal.RetryPolicy{
188197
MaximumAttempts: 3,

0 commit comments

Comments
 (0)