-
Notifications
You must be signed in to change notification settings - Fork 102
Refactor CICD label management to use per-PR sequential queue #5035
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
Open
eyebrowsoffire
wants to merge
4
commits into
flutter:main
Choose a base branch
from
eyebrowsoffire:serial_pr_handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
34e2654
Refactor CICD label management to use per-PR sequential queue
eyebrowsoffire a927ff3
Look up by document ID instead of a filter query.
eyebrowsoffire 5c6df6a
Use redis to ensure serialized handling of PRs across instances.
eyebrowsoffire 5166206
Add alternative diagram and fix some other comments from codefu.
eyebrowsoffire 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # CICD Label Flowchart | ||
|
|
||
| This flowchart describes the logic for managing the `CICD` label in Cocoon for running presubmit CI. | ||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| PR_Opened([Event: PR Opened]) --> Is_Draft{Is Draft?} | ||
|
|
||
| Is_Draft -- No --> Is_Privileged_Open{Is Privileged?} | ||
| Is_Draft -- Yes --> Create_Awaiting[Create Awaiting Check Run] | ||
|
|
||
| Is_Privileged_Open -- Yes --> Add_Label[Add CICD Label] | ||
| Add_Label --> Start_Pre[Start Presubmits] | ||
|
|
||
| Is_Privileged_Open -- No --> Create_Awaiting | ||
|
|
||
| Create_Awaiting --> State_Awaiting((State: Awaiting)) | ||
| Start_Pre --> State_Running((State: Running)) | ||
|
|
||
| State_Awaiting --> Label_Added([Event: CICD Label Added]) | ||
| Label_Added --> Resolve_Awaiting[Resolve Awaiting Check Run] | ||
| Resolve_Awaiting --> Start_Pre | ||
|
|
||
| State_Running --> Changes_Pushed([Event: Changes Pushed]) | ||
| Changes_Pushed --> Is_Privileged_Push{Is Privileged?} | ||
| Remove_Label --> Create_Awaiting | ||
|
|
||
| Is_Privileged_Push -- No --> Remove_Label[Remove CICD Label] | ||
|
|
||
| Is_Privileged_Push -- Yes --> Label_Present{Has CICD Label?} | ||
| Label_Present -- Yes --> Start_Pre | ||
| Label_Present -- No --> Create_Awaiting | ||
| ``` | ||
|
|
||
| ## Alternative State Machine Diagram (PlantUML) | ||
|
|
||
| ```plantuml | ||
| @startuml | ||
| state PR { | ||
| state Waiting | ||
| Waiting : entry / Create Awaiting Check Run | ||
| Waiting : exit / resolve(awaiting check) | ||
|
|
||
| state Running | ||
| Running: entry/ Start Presubmits | ||
|
|
||
| state if_priv2 <<choice>> | ||
| Running --> if_priv2: onPushed | ||
| if_priv2 --> Running: isPrivileged && labeled(CICD) | ||
| if_priv2 --> Waiting : default: remove(CICD) | ||
|
|
||
| state if_draft <<choice>> | ||
| PR --> if_draft: openned | ||
|
|
||
| if_draft --> Waiting : isDraft | ||
| if_draft --> Running: isPrivileged | ||
| if_draft --> Waiting : default | ||
|
|
||
| Waiting --> Running: labeled(CICD) | ||
| } | ||
| @enduml | ||
| ``` | ||
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright 2026 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:convert'; | ||
|
|
||
| import 'package:github/github.dart'; | ||
| import 'package:googleapis/firestore/v1.dart'; | ||
|
|
||
| import '../../service/firestore.dart'; | ||
| import 'base.dart'; | ||
|
|
||
| /// Represents the state of a Pull Request that we want to persist across events. | ||
| final class PullRequestState extends AppDocument<PullRequestState> { | ||
| static const kCollectionId = 'pullRequestStates'; | ||
| static const kIsPrivilegedField = 'is_privileged'; | ||
| static const kLatestShaField = 'latest_sha'; | ||
| static const kScheduledShaField = 'scheduled_sha'; | ||
| static const kSlugField = 'slug'; | ||
| static const kNumberField = 'number'; | ||
|
|
||
| @override | ||
| AppDocumentMetadata<PullRequestState> get runtimeMetadata => metadata; | ||
|
|
||
| /// Description of the document in Firestore. | ||
| static final metadata = AppDocumentMetadata<PullRequestState>( | ||
| collectionId: kCollectionId, | ||
| fromDocument: PullRequestState.fromDocument, | ||
| ); | ||
|
|
||
| /// Create [PullRequestState] from a Document. | ||
| static PullRequestState fromDocument(Document doc) { | ||
| return PullRequestState() | ||
| ..fields = doc.fields! | ||
| ..name = doc.name!; | ||
| } | ||
|
|
||
| /// Whether the PR author is a privileged user (roller or flutter-hacker). | ||
| bool? get isPrivileged => fields[kIsPrivilegedField]?.booleanValue; | ||
|
|
||
| set isPrivileged(bool? value) { | ||
| if (value != null) { | ||
| fields[kIsPrivilegedField] = value.toValue(); | ||
| } | ||
| } | ||
|
|
||
| /// The latest SHA that we have processed for this PR. | ||
| String? get latestSha => fields[kLatestShaField]?.stringValue; | ||
|
|
||
| set latestSha(String? value) { | ||
| if (value != null) { | ||
| fields[kLatestShaField] = value.toValue(); | ||
| } | ||
| } | ||
|
|
||
| /// The SHA for which we have scheduled presubmits. | ||
| String? get scheduledSha => fields[kScheduledShaField]?.stringValue; | ||
|
|
||
| set scheduledSha(String? value) { | ||
| if (value != null) { | ||
| fields[kScheduledShaField] = value.toValue(); | ||
| } | ||
| } | ||
|
|
||
| /// The repository slug associated with the pull request. | ||
| RepositorySlug get slug => RepositorySlug.fromJson( | ||
| json.decode(fields[kSlugField]!.stringValue!) as Map<String, Object?>, | ||
| ); | ||
|
|
||
| set slug(RepositorySlug value) { | ||
| fields[kSlugField] = json.encode(value.toJson()).toValue(); | ||
|
eyebrowsoffire marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /// The PR number. | ||
| int get number => int.parse(fields[kNumberField]!.integerValue!); | ||
|
|
||
| set number(int value) { | ||
| fields[kNumberField] = value.toValue(); | ||
| } | ||
|
|
||
| /// Generates the document ID for a PR. | ||
| static String getDocumentId(RepositorySlug slug, int number) { | ||
| return '${slug.owner}\u001F${slug.name}\u001F$number'; | ||
| } | ||
| } | ||
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.