dongjoon-hyun commented on code in PR #60305:
URL: https://github.com/apache/spark/pull/60305#discussion_r4534306765
##########
.github/workflows/update_build_status.js:
##########
@@ -204,6 +204,25 @@ module.exports = async ({github, context, core, env =
process.env, log = console
}
}
+ // The fields that link a Build check to a fork run. Every update sends them
again:
+ // an update without the output text clears it, losing the run ID.
+ const runLink = (pr, run) => {
+ const actions_url = 'https://github.com/' + pr.forkOwner + '/' +
pr.forkRepo
+ + '/actions/runs/' + run.id
+ return {
+ details_url: actions_url,
+ 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})
Review Comment:
Non-blocking suggestion: the run link now depends on every `checks.update`
call resending `output.text`, an invariant each future update path has to
remember. Have you considered storing the run ID in the check's `external_id`?
It is the field the Checks API provides for an integrator's own identifier, and
it is readable in GraphQL as `CheckRun.externalId`. If it survives updates that
omit it, the link would no longer depend on resending the output, and the
output text could remain a fallback for existing checks.
##########
.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
Review Comment:
Nit: An update that GitHub does not apply now increments no counter, while
the base branch counted it as `unchanged` and in `notApplied`. So the final
`updated` / `created` / `unchanged` numbers no longer add up to the checks
processed, and the total is only visible by counting warnings, of which only
the first 10 per step become annotations. Could we keep a `notApplied` count in
the summary line?
##########
.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,
Review Comment:
Nit: Under the premise in the PR description (all `Build` checks of a commit
share one suite and the query reads `checkType: LATEST`), the check created
below hides the older run's check from the next pass on, so "Checks for other
runs are only synced above" holds only for this pass. If the older run is still
pending at that moment, its check stays `in_progress` until GitHub marks it
stale.
In practice, the per-ref concurrency in `build_and_test.yml`
(`cancel-in-progress: true`) usually cancels the older run first, so this is
mostly about the wording here and the PR description's "Checks linked to older
runs are updated so they finish".
##########
.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.
continue
}
syncableBuildCheck = true
- // Leave a check alone if it already shows the run's state, as nearly
all do.
const state = checkState(run)
+ const tracked = run.id == trackedRun?.id
+ // The run was rerun after its check completed. GitHub accepts an
update that
+ // reopens a completed check but leaves it unchanged, so leave it
alone. The
+ // tracked run gets a new check below unless another check already
shows it.
+ if (cr.status == 'completed' && state.status != 'completed') {
+ trackedRunReran ||= tracked
+ count.unchanged++
+ continue
+ }
+ trackedRunShown ||= tracked
+ // Leave a check alone if it already shows the run's state, as nearly
all do.
if (sameState(cr, state)) {
Review Comment:
When a rerun finishes between two passes (typical for PRs older than
`QUICK_SYNC_LOOKBACK_DAYS`, since only the 4-hourly full sync covers them), the
check is `completed` both before and after. The rerun branch above does not
fire, line 359 marks the tracked run as shown, and the result depends on GitHub
applying a `completed` -> `completed` conclusion change (e.g. `failure` ->
`success`) here.
On the base branch, the lost run link led to a new check anyway; with the
link now preserved, this update is the only path. The tested update cases are
`in_progress` -> `completed` and `queued` -> `in_progress` only. Was this case
verified against GitHub? If GitHub ignores it as it ignores a reopen, the PR
keeps showing the old result with a warning on every pass, and no new check is
created. Treating a tracked-run update that GitHub did not apply as not shown
would cover both outcomes.
##########
.github/workflows/update_build_status.js:
##########
@@ -251,10 +311,19 @@ module.exports = async ({github, context, core, env =
process.env, log = console
continue
}
+ // New Build checks link only to the PR branch's latest build_main.yml
run. Fork
+ // master is reserved for syncing upstream, so new PR builds must use
other
+ // branches, even if an older workflow ran on master; a skipped run has
no result.
+ const trackedRun = pr.branch == 'master' || pr.buildRun?.conclusion ==
'skipped'
+ ? undefined : pr.buildRun
+
// Sync every Build check that points at a fork run, not just the first:
a commit
// can carry more than one (e.g. left by the notify workflow this one
replaced).
// An action_required guidance check is not linked to a run.
let syncableBuildCheck = false
+ let unlistedRun = false
+ let trackedRunShown = false
+ let trackedRunReran = false
for (const cr of pr.buildChecks) {
if (cr.conclusion == 'action_required') {
Review Comment:
This skips every `action_required` check as guidance, but `checkState`
passes a fork run's `action_required` conclusion through, and `createCheck`
gives such a check the run link. If the tracked run ends with
`action_required`, its own check is skipped here, `trackedRunShown` stays
`false`, and line 389 creates another check on every pass.
The base branch had the same gap through the backfill, but since this PR
reworks this loop, could we tell guidance apart by the missing run link
instead? For example, `cr.conclusion == 'action_required' && runIdOf(cr) ===
undefined`, here and at line 395.
--
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]