LuciferYang commented on code in PR #13644:
URL: https://github.com/apache/gluten/pull/13644#discussion_r4583230133


##########
.github/workflows/util/update-fork-build-status.js:
##########
@@ -115,93 +131,75 @@ module.exports = async ({ github, context, core }) => {
     return runs;
   };
 
-  // Jobs of the run's latest attempt that failed. Read only while the run is 
going or
-  // when it didn't pass.
-  const failedJobsOf = async (pr, run) => {
-    if (run.status == 'completed' && ['success', 'skipped', 
'neutral'].includes(run.conclusion)) return [];
-    const jobs = await github.paginate('GET 
/repos/{owner}/{repo}/actions/runs/{run_id}/jobs', {
-      owner: pr.head.repo.owner.login,
-      repo: pr.head.repo.name,
-      run_id: run.id,
-      filter: 'latest',
-      per_page: 100,
-    });
-    return jobs.filter((j) => FAILED.includes(j.conclusion));
-  };
-
-  const checkFor = async (pr, run) => {
-    const failedJobs = await failedJobsOf(pr, run);
-    const done = run.status == 'completed';
-    const count = failedJobs.length == 1 ? '1 job failed' : 
`${failedJobs.length} jobs failed`;
-    const lines = [
-      `[See the run in ${pr.head.repo.full_name}](${run.html_url}). ` +
-        'Rerun failed jobs there if the failure is unrelated to this pull 
request.',
-    ];
-    if (failedJobs.length) {
-      lines.push('', done ? 'Failed jobs:' : 'Failed jobs so far (the run is 
still going):');
-      for (const j of failedJobs) lines.push(`- [${j.name}](${j.html_url})`);
+  // Jobs of the run's latest attempt, or null if they can't be read. Not read 
for a run
+  // that passed. Small pages: a page of 100 jobs can take longer than 
GitHub's 10-second
+  // gateway timeout.
+  const jobsOf = async (pr, run) => {
+    if (run.status == 'completed' && PASSED.includes(run.conclusion)) return 
[];
+    try {
+      return await github.paginate('GET 
/repos/{owner}/{repo}/actions/runs/{run_id}/jobs', {
+        owner: pr.head.repo.owner.login,
+        repo: pr.head.repo.name,
+        run_id: run.id,
+        filter: 'latest',
+        per_page: 30,
+      });
+    } catch (e) {
+      if (isRateLimited(e)) throw e;
+      console.log(`#${pr.number}: could not read the jobs of ${run.html_url}: 
${e.status || e.message}`);
+      return null;
     }
-    return {
-      ...stateOf(run, failedJobs),
-      output: {
-        title: failedJobs.length ? count + (done ? '' : ', run still going') : 
'Fork run',
-        summary: lines.join('\n'),
-        // `done` stops further reads of a check whose run has ended.
-        text: JSON.stringify({
-          owner: pr.head.repo.owner.login,
-          repo: pr.head.repo.name,
-          run_id: run.id,
-          run_attempt: run.run_attempt,
-          done,
-        }),
-      },
-    };
-  };
-
-  const syncCheck = async (pr, w, check, run) => {
-    if (recordOf(check).done) return;
-    const next = await checkFor(pr, run);
-    const same = (k) => (check.output[k] || '') == next.output[k];
-    if (
-      check.status == next.status &&
-      check.conclusion == (next.conclusion || null) &&
-      same('title') &&
-      same('summary') &&
-      same('text')
-    ) {
-      return;
-    }
-    console.log(`#${pr.number} ${w.file}: ${next.status} ${next.conclusion || 
''} ${next.output.title}`);
-    // An update without `output` clears its text, which is how the next pass 
finds this check.
-    return github.request('PATCH 
/repos/{owner}/{repo}/check-runs/{check_run_id}', {
-      ...repo,
-      check_run_id: check.id,
-      details_url: run.html_url,
-      ...next,
-    });
   };
 
-  const createRunCheck = async (pr, w, run) => {
-    console.log(`#${pr.number} ${w.file}: tracking ${run.html_url}`);
-    return github.rest.checks.create({
+  const setStatus = (pr, w, s) => {
+    console.log(`#${pr.number} ${w.file}: ${s.state} ${s.description}`);
+    return github.request('POST /repos/{owner}/{repo}/statuses/{sha}', {
       ...repo,
-      name: w.check,
-      head_sha: pr.head.sha,
-      details_url: run.html_url,
-      ...(await checkFor(pr, run)),
+      sha: pr.head.sha,
+      context: w.context,
+      ...s,
     });
   };
 
-  const createNoRunCheck = (pr, w) => {
-    console.log(`#${pr.number} ${w.file}: no fork run`);
-    return github.rest.checks.create({
-      ...repo,
-      name: w.check,
-      head_sha: pr.head.sha,
-      status: 'completed',
-      conclusion: 'action_required',
-      output: { title: 'No run found in your fork', summary: noRunSummary(w, 
pr.head.sha) },
-    });
+  const syncPull = async (pr) => {
+    const statuses = await listStatuses(pr.head.sha);
+    const legacy = await listLegacyChecks(pr.head.sha);
+    const statusOfContext = (w) => statuses.find((s) => s.context == 
w.context);
+    const legacyOf = (w) => legacy.filter((c) => c.name == w.context);
+    // Only a workflow with nothing reported yet can have a run that hasn't 
registered.
+    const fresh = WORKFLOWS.filter((w) => !statusOfContext(w) && 
legacyOf(w).length == 0);
+    const runs = await listForkRuns(pr, fresh, fresh.length ? 3 : 1);
+    for (const w of WORKFLOWS) {
+      const current = statusOfContext(w);
+      const run = runs.filter((r) => r.path == runPath(w)).sort((a, b) => b.id 
- a.id)[0];
+      if (run) {
+        const at = attemptOf(current);
+        // Two branches can share a head commit; the newer run keeps the 
status.
+        if (at && at.id > run.id) continue;
+        if (at && at.id == run.id && at.attempt == run.run_attempt && 
isFinal(current)) continue;
+        const next = statusOf(run, await jobsOf(pr, run));
+        const same = current && ['state', 'description', 
'target_url'].every((k) => current[k] == next[k]);
+        if (!same) await setStatus(pr, w, next);
+      } else if (!current && !legacyOf(w).some((c) => c.conclusion == 
'action_required')) {

Review Comment:
   Done in 82a43094a: a commit without a fork run gets the error status first, 
and the old check is marked neutral after it.



-- 
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]

Reply via email to