spark-test commented on code in PR #60305:
URL: https://github.com/apache/spark/pull/60305#discussion_r4533551300


##########
.github/workflows/update_build_status.js:
##########
@@ -282,23 +342,28 @@ module.exports = async ({github, context, core, env = 
process.env, log = console
           count.unchanged++
           continue
         }
+        // The fork run was rerun after its check completed. GitHub accepts an 
update
+        // that reopens a completed check but leaves it unchanged, so create a 
new
+        // check instead. It hides this one, since the PR query reads only the 
latest
+        // Build check in a suite.
+        if (cr.status == 'completed' && state.status != 'completed') {

Review Comment:
   Thanks, the revision fixes this. A rerun of the branch's latest build now 
gets one new check, a pending check for that run counts as showing it whichever 
suite it lands in, and the completed checks no longer get a reopen request. 
This review raises a related case separately: open PRs from different branches 
of one fork at the same head commit now get a new Build check on every pass.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:4531769492","thread_id":"inline:4531769492","verdict_sha256":"c749a3d2a7d88b0b2137c287aeb31910a2d20053e2244f3f12789dd0982f5a91"}
 -->



##########
.github/workflows/update_build_status.js:
##########
@@ -287,93 +367,37 @@ module.exports = async ({github, context, core, env = 
process.env, log = console
           const {data: updated} = await github.rest.checks.update({
             ...context.repo,
             check_run_id: cr.id,
-            ...state
+            ...state,
+            ...runLink(pr, run)
           })
-          // A successful request can leave the state unchanged, notably when 
trying
-          // to reopen a completed check after a rerun.
-          if (sameState(cr, updated)) {
-            count.unchanged++
-          } else {
-            log.log(ref + ': ' + label(cr) + ' -> ' + label(updated))
+          if (sameState(updated, state)) {
+            log.log(ref + ': ' + change)
             count.updated++
-          }
-          if (!sameState(updated, state)) {
-            count.notApplied++
+          } else {
+            core.warning(ref + ': GitHub did not apply ' + change
+              + '; the check is still ' + label(updated))
           }
         } catch (error) {
           log.error(ref + ': ' + change + ' failed: ' + error.message)
           failedPRs.add(pr.number)
         }
       }
 
-      // No syncable Build check: link one to the PR branch's build_main.yml 
run, or
-      // create action_required guidance if no run exists, it was skipped, or 
the PR
-      // is from fork master. Fork master is reserved for syncing upstream; 
new PR
-      // builds must use other branches, even if an older workflow ran on 
master.
-      // Existing run-linked checks are still synchronized above.
-      if (!syncableBuildCheck) {
-        const run = pr.branch == 'master' || pr.buildRun?.conclusion == 
'skipped'
-          ? undefined : pr.buildRun
-        if (!run) {
-          // Already provided guidance, or still within the run-registration 
grace period.
-          if (pr.buildChecks.some(cr => cr.conclusion == 'action_required')
-              || Date.parse(pr.updatedAt) > runGraceSince) {
-            count.skipped++
-            continue
-          }
-        }
-
-        const state = run ? checkState(run)
-          : {status: 'completed', conclusion: 'action_required'}
-        const check = {
-          ...context.repo, name: BUILD_CHECK_NAME, head_sha: pr.sha, ...state
-        }
-        const change = 'none -> ' + label(state)
-        try {
-          if (run) {
-            const actions_url = 'https://github.com/' + pr.forkOwner + '/' + 
pr.forkRepo
-              + '/actions/runs/' + run.id
-            check.output = {
-              title: 'Test results',
-              summary: '[See test results](' + actions_url + ')\n\n'
-                + 'If the tests fail for reasons unrelated to this pull 
request, '
-                + 'please rerun the workflow in your forked repository.\n'
-                + 'If the failures are related to this pull request, '
-                + 'please investigate them and push follow-up changes.',
-              text: JSON.stringify({
-                owner: pr.forkOwner,
-                repo: pr.forkRepo,
-                run_id: run.id
-              })
-            }
-            check.details_url = actions_url
-          } else {
-            // No usable run, or a fork-master PR: explain the required setup.
-            check.output = {
-              title: 'PR build setup requires attention',
-              summary: `
-  A supported Build check is not available for this PR head commit.
-
-  1. If you did not enable GitHub Actions in your forked repository, please 
enable it by clicking the button as shown in the image below. See also 
[Managing GitHub Actions settings for a 
repository](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository)
 for more details.
-  2. For PR build status, use a branch other than \`master\` in your fork.`
-                + (pr.branch == 'master' ? '' : `
-
-  After fixing the cause, push a new commit to your PR branch to start the 
build.`),
-              images: [
-                {
-                  alt: 'enabling workflows button',
-                  image_url: 
'https://raw.githubusercontent.com/apache/spark/master/.github/workflows/images/workflow-enable-button.png'
-                }
-              ]
-            }
-          }
-          await github.rest.checks.create(check)
-          log.log(ref + ': ' + change)
-          count.created++
-        } catch (error) {
-          log.error(ref + ': ' + change + ' failed: ' + error.message)
-          failedPRs.add(pr.number)
+      // Link a new check to the tracked run if no check shows it: the PR has 
none yet,
+      // its check completed before a rerun, or its checks link to other runs 
(e.g. an
+      // older build of the same commit). Checks for other runs are only 
synced above.
+      if (trackedRun && !trackedRunShown && !unlistedRun) {

Review Comment:
   **Non-blocking (P2):** This create fires whenever no listed Build check 
shows this PR's own tracked run, but Build checks belong to the head commit, 
not to the PR. Open PRs from different branches of one fork at the same commit 
read the same checks, while each tracks its own branch's run (`build_main.yml` 
runs on every branch push). The description says all Build checks on a commit 
share one suite and the query lists only the newest. Under that premise, each 
PR's new check hides the other's:
   
   - pass 1: PR A creates a check for its run, PR B creates one for its run, 
and only B's is listed;
   - pass 2: PR A finds B's check synced but linked to the other run, so it 
creates another;
   - pass 3: PR B finds A's new check and creates another, and so on.
   
   Running the script against a mocked GitHub with those listing semantics 
created 7 checks in 6 passes for such a pair, in either PR order. Each create 
was logged as an ordinary `none -> success` with no warning. The script created 
12 when the PRs fell on different pages of the PR query, and 13 for three 
branches. The listed check, and with it the result both PRs show, kept flipping 
between the branches' builds. The base branch and this PR's first revision 
created checks only in the first pass, because any synced check stopped the 
create. With each check in its own suite, the pair is stable on every revision, 
and PRs from different forks at one commit already alternated on the base 
branch.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60305#discussion_r4531769492).
   
   **Recommended change:** While syncing a PR's listed Build checks, also note 
whether any listed check links to a build_main.yml run of the head commit on 
another non-master branch that is newer than the PR's tracked run, in the 
oldest-first suite order the script already uses to pick the tracked run, and 
skip creating a check for the tracked run when one does. Count such a check 
even when it is completed and its run is queued or in progress again, which the 
loop otherwise leaves alone as a rerun, so a rerun of the newer build does not 
also make the older branch's PR create a check. Such a check shows a newer 
build of the same commit, made for another branch and usually another open PR, 
so the PR keeps showing it instead of replacing it. Every other create stays: 
no linked check, a rerun of the tracked run, and a newer build of the PR's own 
branch. Extend the comment above the create, and the create sentence of the 
workflow header, with this exception. The current create rule came f
 rom commit 76ca3bb (address review feedback), which replaced the base branch's 
rule of creating only when no listed check is synced; commit 84a6b8b had kept 
that rule and added creates only for reruns.
   
   **Why this works:** Two PRs at one commit alternate because each creates 
whenever the listed check shows the other PR's run. With the condition, the PR 
whose tracked run is older sees the newer branch build and creates nothing, 
while the PR with the newest build still creates when its run is not shown, so 
the commit settles on one listed check for its newest branch build after at 
most two passes, and later passes create nothing. A completed check whose newer 
run is rerun still counts, so that rerun adds one check rather than one per PR. 
Runs are compared only among the fork runs the PR already lists for its head 
commit.
   
   **Scope:** One added condition in the build status sync's per-PR create 
decision, with its code comment and the matching sentence of the workflow 
header.
   
   **Compatibility:** When no listed check shows a newer build of the commit 
from another non-master branch, the create decision, the guidance branch, the 
guard for links to unlisted runs, and the run link sent with every update 
behave as they do now.
   
   **Risks:** When open PRs from different branches of one fork share a head 
commit, only the newest of their branch builds gets new checks, so a rerun of 
an older branch's build gets no check of its own, as for reruns of other runs 
under the PR's stated scope, and with every Build check in one suite neither 
that rerun nor the older build's result is shown while the newer one is listed. 
The same applies when the newer branch's PR has closed: the PR then shows that 
newer build of its commit, as on the base branch. Removing the condition 
restores the current behavior.
   
   **Constraints:** Compare only among the fork runs the PR lists for its head 
commit, so a link to a run outside that listing, such as a deleted run or 
another fork's run, never suppresses a create. Count only build_main.yml runs 
on non-master branches other than the PR's own, so an old check for a 
fork-master build or for another workflow's run does not stop the PR's own 
build from getting a check.
   
   **Exclusions:**
   - PRs from different forks at the same head commit already alternated on the 
base branch, because neither PR can read the other fork's run, and they stay as 
they are.
   
   **Success:** Two open PRs from different non-master branches of one fork at 
the same head commit stop creating checks after their first two passes, and the 
listed check stays linked to the newest of their branch builds; after that, a 
rerun of that build or a newer build of the commit on one of their branches 
adds exactly one check. A PR whose listed checks show no newer build of its 
commit from another non-master branch gets the creates it gets now: one check 
when it has none, one per rerun of its branch's latest build, and one per newer 
build of its branch. A listed check linked to an older branch build or to a 
fork-master build of the commit does not stop the PR's branch build from 
getting a check.
   
   **Verification:**
   - **Regression:** Over several consecutive passes for two open PRs from 
different non-master branches of one fork at the same head commit, with every 
Build check in one suite and only the newest per suite listed, creates stop 
after at most two passes in either processing order, with the PRs on the same 
page of the PR query or on different pages, and the listed check stays linked 
to the newer branch build.
   - **Regression:** After the pair settles, a rerun of the newer branch build 
after its check completed makes the next pass create exactly one check, linked 
to that rerun, and the older branch's PR creates none during or after that 
rerun.
   - **Behavior:** For a PR whose listed checks show no newer build of its 
commit from another branch, a rerun of the branch's latest build after its 
check completed gets exactly one new check, a newer build of the PR branch on 
the same commit gets one check, and a PR with no linked check gets one.
   - **Compatibility:** A PR whose head commit carries a check linked to an 
older fork-master build still gets a check for its branch build, checks linked 
to other runs are still updated to their runs' states, and with the pair's 
checks in separate suites no check is created after the first pass.
   - **Inspection:** The comment above the create and the workflow header both 
say that a listed newer build of the same commit on another branch suppresses 
the create.



##########
.github/workflows/update_build_status.yml:
##########
@@ -22,10 +22,12 @@
 # workflow only reports their results. Running on a schedule avoids
 # `pull_request_target` and needs no maintainer approval for fork PRs.
 #
-# Each pass synchronizes existing `Build` checks with their fork runs. Missing
-# checks are linked to the PR head's fork build, unless no run exists, the run 
was
-# skipped, or the PR is from fork master. Those cases get `action_required` 
guidance
-# after the registration grace period. Fork master is reserved for syncing 
upstream;
+# Each pass synchronizes existing `Build` checks with their fork runs. A PR 
whose
+# branch's latest fork build has no `Build` check showing it, because the PR 
has none
+# yet, its check completed before a rerun, or its checks link to other runs, 
gets a
+# new check linked to that build. PRs with no usable build (none exists, it was
+# skipped, or the PR is from fork master) get `action_required` guidance after 
the

Review Comment:
   **Nit (P3):** The script creates guidance only when there is no tracked run 
and no listed Build check links to a fork run (`!trackedRun && 
!syncableBuildCheck` in update_build_status.js). Take a fork-master PR whose 
commit already has a check linked to an older master-branch build, which the 
next sentence says stays supported. That PR gets no guidance, although this 
sentence says it does. The old header limited guidance to PRs with missing 
checks. Adding that condition fixes it, for example: "PRs with no usable build 
(none exists, it was skipped, or the PR is from fork master) and no run-linked 
`Build` check get `action_required` guidance after the registration grace 
period."
   
   See **Shared repair plan 1** in the review body.



##########
.github/workflows/update_build_status.js:
##########
@@ -264,20 +333,31 @@ module.exports = async ({github, context, core, env = 
process.env, log = console
         if (!run) {
           if (runId && pr.forkRunsTruncated) {
             // The run may be among the fork's check suites the page left out. 
Keep
-            // the backfill from replacing the check, and fail the PR to get 
noticed.
+            // the check below from replacing it, and fail the PR to get 
noticed.
             log.error(ref + ': fork run ' + runId + ' not in the first fork 
check '
               + 'suites; raise the limits in prPageQuery')
             failedPRs.add(pr.number)
             syncableBuildCheck = true
+            unlistedRun = true
           }
           // Otherwise the check's output is unusable or its fork run was 
deleted, so
-          // it can never be synced; the backfill below replaces it.
+          // it can never be synced; a check for the tracked run replaces it 
below.

Review Comment:
   **Nit (P3):** When there is no tracked run (a fork-master PR, a skipped 
build, or a branch whose only run was deleted), line 389 can't fire. The code 
below then creates `action_required` guidance instead, and only when no other 
listed check is synced, the PR has no guidance yet, and the grace period has 
passed. The base branch's wording, "the backfill below replaces it", covered 
both outcomes. For example:
   
   ```suggestion
             // Otherwise the check's output is unusable or its fork run was 
deleted, so
             // it can never be synced. The code below may replace it with a 
check for the
             // tracked run, or with action_required guidance when there is no 
tracked run.
   ```
   
   See **Shared repair plan 1** in the review body.



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