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

Always update checkrun status for terraform workflows #719

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions server/neptune/workflows/internal/pr/revision/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

const (
ReviewSignalID = "pr-review"
CheckRunCancelled = "checkrun was cancelled"
ReviewSignalID = "pr-review"
CheckRunCancelled = "checkrun was cancelled"
NotifyAllCheckRunsChangeID = "notify-all-checkruns-always"
)

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

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

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

func (p *Processor) markCheckRunsAborted(ctx workflow.Context, revision Revision, roots map[string]RootInfo) {
p.markCombinedCheckRun(ctx, revision, github.CheckRunCancelled, CheckRunCancelled)

for _, rootInfo := range roots {
ctx = workflow.WithRetryPolicy(ctx, temporal.RetryPolicy{
MaximumAttempts: 3,
Expand Down
5 changes: 5 additions & 0 deletions server/neptune/workflows/internal/terraform/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest"
"net/url"
"strings"
"time"

key "github.com/runatlantis/atlantis/server/neptune/context"
Expand Down Expand Up @@ -146,6 +147,10 @@ func (r *Runner) Plan(ctx workflow.Context, root *terraform.LocalRoot, serverURL
return response, newUpdateJobError(err, "unable to update job with in-progress status")
}

if strings.HasSuffix(root.Path, "simple") {
_ = workflow.Sleep(ctx, 20*time.Second)
}

response, err = r.JobRunner.Plan(ctx, root, jobID.String(), r.Request.WorkflowMode)

if err != nil {
Expand Down
Loading