-
Notifications
You must be signed in to change notification settings - Fork 6
[DEVCON-2524] output deploy queue to checkrun summary #772
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
Merged
tlin4194
merged 13 commits into
main
from
DEVCON-2524-output-deploy-queue-to-checkrun-summary
Dec 3, 2024
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a5c4a0
add revisions on queue to checkrun summary
tlin4194 a986769
update tests with GetQueuedRevisionsSummary queue interface
tlin4194 f9f0431
fix updater and revision tests to throw errors from child workflow
tlin4194 f4e8ac5
exposing deploy queue to deploy terraform package
tlin4194 2334947
add commit links
tlin4194 fd38bf6
update checkruns with queue status for Terraform jobs where Apply ste…
tlin4194 43ccc09
fix deploy_test by checking apply job is not null
tlin4194 cbf4fa5
provide links to runs in queue instead of commits in queue
tlin4194 4cc6c9f
add comments, replace using reflect to check for empty Apply.Onwaitin…
tlin4194 1e2c0a8
workflow version patch for additional github checkrun updates due to …
tlin4194 c921b26
bugfix: after confirm action, queued checkruns need to be restored to…
tlin4194 d5ef226
noted TODO: current deploy checkrun is updated twice on confirm/rejec…
tlin4194 d31039c
Restore unlock action on queued checkruns (#774)
tlin4194 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package terraform | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/runatlantis/atlantis/server/metrics" | ||
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" | ||
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" | ||
|
||
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/terraform/state" | ||
"github.com/runatlantis/atlantis/server/neptune/workflows/plugins" | ||
"go.temporal.io/sdk/workflow" | ||
|
@@ -14,15 +16,23 @@ type WorkflowNotifier interface { | |
Notify(workflow.Context, notifier.Info, *state.Workflow) error | ||
} | ||
|
||
type CheckRunClient interface { | ||
CreateOrUpdate(ctx workflow.Context, deploymentID string, request notifier.GithubCheckRunRequest) (int64, error) | ||
} | ||
|
||
type StateReceiver struct { | ||
|
||
// We have separate classes of notifiers since we can be more flexible with our internal ones in terms of the data model | ||
// What we support externally should be well thought out so for now this is kept to a minimum. | ||
Queue deployQueue | ||
CheckRunCache CheckRunClient | ||
InternalNotifiers []WorkflowNotifier | ||
AdditionalNotifiers []plugins.TerraformWorkflowNotifier | ||
} | ||
|
||
func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel, deploymentInfo DeploymentInfo) { | ||
// deploymentInfo is the current deployment being processed in TerraformWorkflow. Receive is triggered whenever the TerraformWorkflow has a state change. | ||
|
||
var workflowState *state.Workflow | ||
c.Receive(ctx, &workflowState) | ||
|
||
|
@@ -39,6 +49,36 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel, | |
} | ||
} | ||
|
||
// Updates all other deployments waiting in queue when the current deployment is pending a confirm/reject user action. Current deployment is not on the queue at this point since its child TerraformWorkflow was started. | ||
if workflowState.Apply != nil && | ||
workflowState.Apply.Status == state.WaitingJobStatus && | ||
len(workflowState.Apply.OnWaitingActions.Actions) > 0 { | ||
queued_deployments := n.Queue.GetOrderedMergedItems() | ||
|
||
revisionsSummary := n.Queue.GetQueuedRevisionsSummary() | ||
state := github.CheckRunQueued | ||
runLink := github.BuildRunURLMarkdown(deploymentInfo.Repo.GetFullName(), deploymentInfo.Commit.Revision, deploymentInfo.CheckRunID) | ||
tlin4194 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
summary := fmt.Sprintf("This deploy is queued pending action on run for revision %s.\n%s", runLink, revisionsSummary) | ||
|
||
for _, i := range queued_deployments { | ||
request := notifier.GithubCheckRunRequest{ | ||
tlin4194 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Title: notifier.BuildDeployCheckRunTitle(i.Root.Name), | ||
Sha: i.Commit.Revision, | ||
State: state, | ||
Repo: i.Repo, | ||
Summary: summary, | ||
} | ||
|
||
workflow.GetLogger(ctx).Debug(fmt.Sprintf("Updating action pending summary for deployment id: %s", i.ID.String())) | ||
_, err := n.CheckRunCache.CreateOrUpdate(ctx, i.ID.String(), request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might pose some non-determinism errors, see https://community.temporal.io/t/workflow-determinism/4027, but I could be wrong. If it does, let's add some workflow versioning here |
||
|
||
if err != nil { | ||
workflow.GetLogger(ctx).Debug(fmt.Sprintf("updating check run for revision %s", i.Commit.Revision), err) | ||
} | ||
} | ||
} | ||
|
||
// Updates github check run with Terraform statuses for the current running deployment | ||
for _, notifier := range n.InternalNotifiers { | ||
if err := notifier.Notify(ctx, deploymentInfo.ToInternalInfo(), workflowState); err != nil { | ||
workflow.GetMetricsHandler(ctx).Counter("notifier_failure").Inc(1) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.