nchammas commented on code in PR #60098: URL: https://github.com/apache/spark/pull/60098#discussion_r4494380795
########## .github/workflows/update_build_status.js: ########## @@ -0,0 +1,391 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +module.exports = async ({github, context, core, env = process.env, log = console}) => { + // Open PRs are read with one GraphQL query per page of PRs. For each PR it returns + // the Build checks on the head commit (statusCheckRollup.commit) and the fork's + // workflow runs for that commit (headRef.target), both as GitHub Actions check + // suites: fork runs are Actions runs, and Build checks written with the GITHUB_TOKEN + // land in Actions suites too. + // + // A PR rarely has more than a few such suites. A fork's default branch can collect + // thousands from scheduled workflows, but suites are listed oldest first and a push + // creates its runs' suites right away, so they are still among the first. Should a + // page ever not hold everything a PR needs, the PR fails loudly rather than being + // synced from partial data. + // + // GitHub aborts a GraphQL request after 10 seconds and allows 60 seconds of GraphQL + // CPU time per minute. A page of 25 PRs takes about 3 seconds, so each page is + // followed by a pause as long as it took. + // https://docs.github.com/en/graphql/overview/rate-limits-and-query-limits-for-the-graphql-api + const GITHUB_ACTIONS_APP_ID = 15368 + const PR_PAGE_SIZE = 25 + + // Quick syncs cover only open PRs updated in the last QUICK_SYNC_LOOKBACK_DAYS. A + // push, comment, review, or label change updates a PR, but a check change does not. + // Fork runs usually finish within hours of a push, and most reruns happen within + // days. A later rerun, or a gap in quick syncs longer than the lookback, is picked + // up by the next full sync, which covers all open PRs. Both are scheduled at the + // schedule in the workflow. + const QUICK_SYNC_LOOKBACK_DAYS = 3 + const fullSync = env.FULL_SYNC == 'true' + const updatedSince = fullSync ? 0 + : Date.now() - QUICK_SYNC_LOOKBACK_DAYS * 24 * 60 * 60 * 1000 + + // A missing Build check points at the fork's build_main.yml run for the PR branch. + // Right after a push that run may not be registered yet, so a PR updated in the last + // NEW_RUN_GRACE_MINUTES without a run is left for a later pass instead of being + // told that no run exists. + const BUILD_WORKFLOW = '.github/workflows/build_main.yml' + const NEW_RUN_GRACE_MINUTES = 5 + const runGraceSince = Date.now() - NEW_RUN_GRACE_MINUTES * 60 * 1000 + + const prPageQuery = ` + query($owner: String!, $repo: String!, $size: Int!, $cursor: String, $appId: Int!) { + repository(owner: $owner, name: $repo) { + pullRequests(states: OPEN, first: $size, after: $cursor, + orderBy: {field: UPDATED_AT, direction: DESC}) { + pageInfo { hasNextPage endCursor } + nodes { + number + updatedAt + headRefOid + statusCheckRollup { + commit { + oid + checkSuites(first: 10, filterBy: {appId: $appId}) { Review Comment: Addressed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
