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

Restore unlock action on queued checkruns #774

Conversation

tlin4194
Copy link
Contributor

@tlin4194 tlin4194 commented Dec 2, 2024

When we update checkruns for queued commits (after the blocking commit gets confirmed or rejected), we need to check if the queue was previously locked by something else and restore the unlock button for each commit.

Sequence of events without this change:

  1. Queue is locked due to diverged commits on latest deployment vs current plan (i.e. if someone previously force applied). All queued commits should have a unlock button.
  2. New commit comes in with a pending confirm/reject action. My other PR makes it so that all queued checkruns are updated to reflect that the queue is waiting on this confirm reject action.
Screenshot 2024-11-08 at 3 08 07 PM 4. Confirm/reject commit gets resolved. All queued commit checkruns get updated to the default status, without the unlock button. Currently users would have to click on the commit they want to unlock (first screenshot below), then click on an older checkrun of that commit (linked in blue) to access the unlock button (2nd screenshot below). Screenshot 2024-11-08 at 3 07 08 PM Screenshot 2024-11-08 at 3 07 17 PM

After this change:

  1. (Previous step 4) All queued commit checkruns get updated back to its original status from before the confirm/reject commit was applied, including unlock actions if the queue was previously locked.

Additional notes:

  • LockState is migrated out of the queue package into its own lock package to avoid cyclic imports with terraform module
  • bumping max interfacebloat golangci error to allow adding GetLockState() function to queue interface

Testing

  1. Open PR 1. Force apply PR 1, and verify that the force apply is successful.
  2. Open PR 2. Merge PR 2 to master, and verify that PR 2 deployment failed and is now locked on PR 1's last commit (there should be an unlock button and link to the locking commit).
  3. Open PR 3. Force apply PR 3, and verify that there is a Confirm/Reject action.
  4. Verify that PR 2's deployment checkrun on master has an updated summary with link to the pending Confirm/Reject run on PR 3.
  5. Reject forced apply on PR 3.
  6. Verify that PR 2's deployment checkrun updates again, this time back to the original checkrun summary from step 2. If the queue was previously locked (which it was), there should be an unlock button.

@tlin4194 tlin4194 force-pushed the DEVCON-2524-restore-unlock-action-on-queue-checkruns branch from fa88f07 to 5fbd36d Compare December 2, 2024 17:06
@@ -36,6 +37,7 @@ type stateReceiver interface {
type deployQueue interface {
GetOrderedMergedItems() []DeploymentInfo
GetQueuedRevisionsSummary() string
GetLockState() lock.LockState
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I wanted to migrate LockState to its own package is so that the terraform package can also use this GetLockState function without running into cyclic package dependencies (queue package imports terraform package, but terraform package needs access to functions and structs defined in queue package).

Comment on lines +81 to +90
// 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
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we update checkruns for queued commits (after the blocking commit gets confirmed or rejected), we need to check if the queue was previously locked by something else and restore the unlock button for each commit.

GetOrderedMergedItems() []terraform.DeploymentInfo
GetQueuedRevisionsSummary() string
GetLockState() lock.LockState
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding these two functions to the interface is breaking the linter.
Solutions:

  1. separate queue package from the revision package so that queue struct can be shared without interfaces? (similar to what I did for the Lock package but this seems more complicated)
  2. Keep using interfaces, but split it up into 2 interfaces: one for functions used by deploy worker, one for terraform runner. WIP looking into if this can be done cleanly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Edit: resolved by bumping the interfacebloat max setting in golangci.yml instead

@tlin4194 tlin4194 force-pushed the DEVCON-2524-restore-unlock-action-on-queue-checkruns branch from 565a13a to 7025d13 Compare December 2, 2024 20:04
@tlin4194 tlin4194 merged commit d31039c into DEVCON-2524-output-deploy-queue-to-checkrun-summary Dec 3, 2024
3 checks passed
@tlin4194 tlin4194 deleted the DEVCON-2524-restore-unlock-action-on-queue-checkruns branch December 3, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants