Skip to content

Commit

Permalink
state receiver checks queue lock state and restores unlock button
Browse files Browse the repository at this point in the history
  • Loading branch information
tlin4194 committed Nov 9, 2024
1 parent bee9ab2 commit 5fbd36d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server/neptune/workflows/internal/deploy/terraform/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"

Check failure on line 8 in server/neptune/workflows/internal/deploy/terraform/state.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

File is not `gofmt`-ed with `-s` (gofmt)
"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/internal/deploy/lock"
"github.com/runatlantis/atlantis/server/neptune/workflows/plugins"
"go.temporal.io/sdk/workflow"
)
Expand Down Expand Up @@ -68,22 +69,34 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
len(workflowState.Apply.OnWaitingActions.Actions) > 0 {
queuedDeployments := n.Queue.GetOrderedMergedItems()
revisionsSummary := n.Queue.GetQueuedRevisionsSummary()
runState := github.CheckRunQueued
var actions []github.CheckRunAction
var summary string

if workflowState.Apply.Status == state.WaitingJobStatus {
runLink := github.BuildRunURLMarkdown(deploymentInfo.Repo.GetFullName(), deploymentInfo.Commit.Revision, deploymentInfo.CheckRunID)
summary = fmt.Sprintf("This deploy is queued pending action on run for revision %s.\n%s", runLink, revisionsSummary)
} else if workflowState.Apply.Status == state.RejectedJobStatus || workflowState.Apply.Status == state.InProgressJobStatus {
// If the current deployment is Rejected or In Progress status, we need to restore the queued check runs to reflect that the queued deployments are not blocked.
summary = "This deploy is queued and will be processed as soon as possible.\n" + revisionsSummary
// If the queue is currently locked we need to provide the unlock action.
queueLock := n.Queue.GetLockState()
if queueLock.Status == lock.LockedStatus {
actions = append(actions, github.CreateUnlockAction())
runState = github.CheckRunActionRequired
revisionLink := github.BuildRevisionURLMarkdown(deploymentInfo.Repo.GetFullName(), queueLock.Revision)
summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.\n%s", revisionLink, revisionsSummary)
} else {
summary = "This deploy is queued and will be processed as soon as possible.\n" + revisionsSummary
}
}
for _, i := range queuedDeployments {
request := notifier.GithubCheckRunRequest{
Title: notifier.BuildDeployCheckRunTitle(i.Root.Name),
Sha: i.Commit.Revision,
State: github.CheckRunQueued,
State: runState,
Repo: i.Repo,
Summary: summary,
Actions: actions,
}

workflow.GetLogger(ctx).Debug(fmt.Sprintf("Updating action pending summary for deployment id: %s", i.ID.String()))
Expand Down

0 comments on commit 5fbd36d

Please sign in to comment.