Skip to content

[app_dart] Schedule prod tasks from GitHub webhooks#1109

Merged
CaseyHillers merged 5 commits intoflutter:masterfrom
CaseyHillers:webhook-scheduling
Mar 16, 2021
Merged

[app_dart] Schedule prod tasks from GitHub webhooks#1109
CaseyHillers merged 5 commits intoflutter:masterfrom
CaseyHillers:webhook-scheduling

Conversation

@CaseyHillers
Copy link
Contributor

Given [PullRequest], add it to Cocoon so tasks can be scheduled against it.

Issues

flutter/flutter#76140 - Move from cron method to webhooks
flutter/flutter#77385 - Webhook method will no longer have this issue. The GitHub refresh cron doesn't dynamically add commits

@CaseyHillers CaseyHillers changed the title [app_dart] Schedule prod tasks from GitHub [app_dart] Schedule prod tasks from GitHub webhooks Mar 11, 2021
const GithubWebhook(Config config, this.buildBucketClient, this.luciBuildService, this.githubChecksService)
GithubWebhook(Config config,
{@required this.buildBucketClient,
@visibleForTesting Scheduler schedulerValue,
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL you can apply @visibleForTesting to a param

@CaseyHillers
Copy link
Contributor Author

do you mean the PR merged webhook?

Yes. This means commits can either be scheduled via the cron or or the GitHub webhook for when PRs are closed.

After I validate the webhook approach, I'll remove the cron method.

);
} else {
// Merged pull requests can be added to CI.
await scheduler.addPullRequest(pr);
Copy link
Contributor

@christopherfujino christopherfujino Mar 11, 2021

Choose a reason for hiding this comment

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

Should we be listening for merged PRs, or commits to ____ branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's a commit webhook event - https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads

The PR event provides a lot of data, and it provides the release branch info. I'll add a test to verify release PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Offline conversation. There is a commit webhook called push - https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#push

It looks like the GitHub library doesn't support that event yet, so I'm going to look into adding it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into the push events on the archive table, and they're not the solution. We need to support this event + push events to get 100% coverage. From the last 90 days, push events made up 0% of commits that need to be tested by infra.

I'm going to follow up and modify the cron job from every minute to every hour, and have it check for any missing commits. Right now it only adds newer, missing commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed flutter/flutter#78351 for tracking the PushEvent addition

Copy link
Contributor

Choose a reason for hiding this comment

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

We sync'ed up offline again, and triggering based on PR merged even SGTM

timestamp: pr.mergedAt.millisecondsSinceEpoch,
);

if (await _commitExistsInDatastore(mergedCommit)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Since commits can be scheduled via (1) cron job and (2) webhook triggers we should ensure we haven't already added the commit. GitHub will retry commits if cocoon sends a non-2** response, so we should handle this case gracefully.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. I guess we can still guarantee the order of commits with these two scheduling logics, right?

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

nit about expanding dartdoc for _commitExistsInDatastore, otherwise LGTM

@CaseyHillers CaseyHillers added the waiting for tree to go green Merge PR when tree becomes green via fluttergithubbot label Mar 16, 2021
@CaseyHillers CaseyHillers merged commit 3643895 into flutter:master Mar 16, 2021
@CaseyHillers CaseyHillers deleted the webhook-scheduling branch March 16, 2021 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting for tree to go green Merge PR when tree becomes green via fluttergithubbot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants