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


##########
.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:
   Thanks for adding it to the description. I'd still fix it in this PR, 
because for those PRs it is a regression, not just a case the new logic leaves 
out. On the base branch, any synced check stops the create, so two PRs from 
different branches at the same commit settle on one check. With this change, 
and with the commit's Build checks in one suite as your survey found, every 
pass that syncs both PRs creates one or two Build checks, with no warning, for 
as long as both stay open, and the result both PRs show keeps switching between 
the two builds. No open PR being in this state today makes it rare, but not 
harmless once it happens. The fix can stay small: one condition that skips the 
create when a listed check already shows a newer build of the same commit from 
another non-master branch of the fork, counting that check even while its build 
is rerun. When no listed check shows such a build, every other create this PR 
adds stays as it is: for a missing check, a rerun, an update GitHu
 b did not apply, or a newer build of the PR's own branch.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:4533551001","thread_id":"inline:4533551001","verdict_sha256":"a5745f695b8e1ab645f43a6ae97402ed755536a407c8355563a8a52134d446d6"}
 -->



##########
.github/workflows/update_build_status.js:
##########
@@ -193,14 +193,28 @@ module.exports = async ({github, context, core, env = 
process.env, log = console
     }
   }
 
-  // The fork run ID a Build check points at, stored as JSON in its output 
text, or
-  // undefined if the text is not that JSON (e.g. a check from an older 
version or a
-  // manual run).
-  const runIdOf = (cr) => {
-    try {
-      return JSON.parse(cr.text).run_id
-    } catch {
-      return undefined
+  // The fork run ID a Build check points at, stored in its external ID, or 
undefined if
+  // the check is not linked to a run (e.g. action_required guidance, or a 
check from an
+  // older version of this script).
+  const runIdOf = (cr) => cr.externalId || undefined

Review Comment:
   **Non-blocking (P2):** `runIdOf` now reads the run link only from 
`externalId`, and the PR query no longer fetches the output text, so every 
Build check created before this change, by an earlier version of this workflow 
or by the removed notify workflow, counts as unlinked. On a PR with a tracked 
run, the new linked check is the replacement the description describes. On a PR 
without one, such as a PR from a fork's `master` branch or one whose latest 
branch build was skipped, the loop skips the old check, `syncableBuildCheck` 
stays false, and once the grace period has passed the guidance branch creates 
`action_required` guidance.
   
   From the code: a fork-`master` PR whose head commit carries a completed 
check linked through output text to a listed `master`-branch build gets no 
write on the base branch and keeps showing that build's result. At this head, 
its first sync replaces that result with "PR build setup requires attention", 
and a pending check of that kind is never updated again. With both checks in 
one suite, as the description's survey found, a revert would not bring the 
result back, because the base script then lists only the guidance and leaves it.
   
   The base branch's header said existing run-linked checks remain supported, 
including older `master`-branch builds, and the SPARK-60879 description said 
they continue updating. This PR drops that sentence without a stated reason, 
and the comment above the sync loop still names checks left by the notify 
workflow as checks it syncs.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60305#discussion_r4534306765).
   
   **Recommended change:** Read the run link from a check's output text when 
the check has no external ID. Select text again in the PR page query's Build 
check fields, carry it through toPR, and make runIdOf return the external ID 
when present and otherwise the run_id of the {owner, repo, run_id} JSON that 
earlier versions wrote there, or undefined when the text is absent or not that 
JSON, as the base branch's runIdOf did. New checks keep writing only 
external_id, and every update keeps sending the run link, so a check read 
through the fallback gains an external ID the next time its state changes. 
Update the comment above runIdOf to say it reads checks from earlier versions 
through their output text. Commit 9d06087 (address review feedback, whose 
message gives no reason) removed the output-text read that the base branch had 
and that 84a6b8b and 76ca3bb kept; the base branch's runIdOf is the starting 
point.
   
   **Why this works:** With the fallback, a check linked only through output 
text resolves to its fork run again, so the loop syncs it as the base branch 
did: it counts as syncable, which keeps the guidance branch from replacing it 
on PRs without a tracked run, it is updated when its run's state changes, and 
it counts as showing the tracked run when it links to that run. Only checks 
without an external ID take the fallback, so checks this script writes keep 
their external_id link.
   
   **Scope:** Restore the base branch's output-text read as a fallback in the 
build status script's run-link reader.
   
   **Compatibility:** Checks this script creates or updates keep linking to 
their run through external_id, and every create and update keeps sending the 
link.
   
   **Risks:** PRs with a tracked run whose earlier check already shows that 
run's state keep that check instead of getting a new linked check, so the 
one-time migration the description describes mostly no longer happens, and the 
description's migration note should say instead that earlier checks keep 
syncing through their output text and gain an external ID when they next 
change; reverting the repair restores the current behavior. The page query 
fetches each listed Build check's output text again, as the base branch did; it 
is a short JSON object for earlier checks and empty for checks this script now 
writes.
   
   **Constraints:** Prefer the external ID whenever a check has one, so a check 
this script wrote is never relinked through older output text. Treat output 
text that is missing, is not JSON, or has no run_id as unlinked, as the base 
branch did, so guidance and manually created checks stay unlinked.
   
   **Exclusions:**
   - Checks whose output text an earlier update already cleared stay unlinked, 
as on the base branch: a PR with a tracked run gets a linked check for it, and 
a PR without one gets guidance after the grace period.
   
   **Success:** A Build check created before this change and linked to its fork 
run only through its output text is synced with that run on PRs with or without 
a tracked run, as on the base branch. A PR from a fork's master branch whose 
head commit carries such a check gets no action_required guidance while the 
check links to a listed fork run. When such a check's run changes state, the 
update writes the check's external ID, and later passes resolve the check 
through it. The comment above the sync loop, the comment above runIdOf, and the 
workflow header's statement that each pass syncs existing checks match the code.
   
   **Verification:**
   - **Regression:** Over several passes against a mocked GitHub that lists the 
newest Build check per check suite, a PR from a fork's master branch whose head 
commit carries a completed Build check linked only through output-text JSON to 
a listed master-branch run receives no write and no guidance, and the same PR 
with an in-progress check of that kind gets the check updated to its run's 
final state once the run completes, with the update carrying the run's external 
ID.
   - **Regression:** A PR whose branch's latest build was skipped, with an 
earlier output-text-linked check for an older run of its head commit, keeps 
that check synced and gets no guidance over several passes.
   - **Behavior:** A PR with a tracked run whose earlier output-text-linked 
check already shows that run's state gets no new check, and a rerun of that run 
after the check completed gets exactly one new check linked through its 
external ID.
   - **Compatibility:** Checks with an external ID still resolve through it, 
and checks with neither an external ID nor run JSON in their output text, 
including action_required guidance, are still treated as unlinked, so guidance 
detection, the unlisted-run guard, and the create and guidance decisions behave 
for them as they do now.
   - **Inspection:** The comments above runIdOf and above the sync loop 
describe reading earlier checks through their output text, and the workflow 
header's statement that each pass syncs existing checks holds for them.



##########
.github/workflows/update_build_status.js:
##########
@@ -287,105 +364,48 @@ 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)) {
+            trackedRunShown ||= tracked
+            log.log(ref + ': ' + change)
             count.updated++
-          }
-          if (!sameState(updated, state)) {
+          } else {
             count.notApplied++
+            core.warning(ref + ': GitHub did not apply ' + change
+              + '; the check is still ' + label(updated))
           }
         } catch (error) {
+          // A failed request has an unknown outcome; retry it on the next 
pass.
+          trackedRunShown ||= tracked
           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 its current 
state: the PR
+      // has none yet, its check completed before a rerun, an update was not 
applied, or
+      // its checks link to other runs (e.g. an older build of the same 
commit).
+      if (trackedRun && !trackedRunShown && !unlistedRun) {
+        await createCheck(pr, ref, trackedRun, trackedRunReran ? 'rerun' : 
'none')

Review Comment:
   **Nit (P3):** `createCheck` documents `from` as describing what the new 
check takes over from (line 250), but this call passes `'none'` for every 
create that is not a rerun, including the cases the comment above lists in 
which the new check replaces an existing Build check: an update GitHub did not 
apply, checks linked to other runs, and, per lines 339-341, an unlinked check. 
The guidance create at line 401 does the same. From the code, a pass that warns 
`GitHub did not apply failure -> success` then logs `none -> success` for the 
replacement, and each migration create and each re-create for PRs that share a 
head commit reads like a PR's first check.
   
   Pass a label for what the new check replaces instead: `'rerun'` for a rerun 
of the tracked run, as now; otherwise the state of the Build checks the PR 
lists, joined when there are several; and `'none'` only when it lists none. 
Give the guidance create the same label, and keep the comment on `from` in step 
with what both calls pass.
   
   **Verification:**
   - **Behavior:** With a mocked GitHub, a pass over a PR that lists no Build 
check logs its create as 'none -> <state>'; a pass in which GitHub does not 
apply a tracked-run update from failure to success logs the replacement as 
'failure -> success'; a pass over a PR whose only listed check links to an 
older build of the same commit logs the new check with that check's state; a 
guidance create over an unlinked check logs that check's state; and a rerun of 
the tracked run is still logged as 'rerun -> in_progress'.
   - **Inspection:** The comment on createCheck's from argument matches the 
labels that both create calls pass.



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