Repository navigation
fix(ci): stop nightly failure reports cancelling each other (BS-011) #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
77769db
e26ec49
1c01cec
56e15d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Require same-repo head and schedule or main push/dispatch so fork and pull_request workflow_run completions do not open nightly issues. Always comment on the lowest-number open issue, close reporter duplicates, and only close a just-created issue when a strictly older sibling exists. Run test_workflow_policy.py in the CI gate and assert the job guard. Rebased onto main (includes #599 Windows rate-limit flake fix). Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,11 @@ jobs: | |
| timeout-minutes: 10 | ||
| if: >- | ||
| github.event.workflow_run.conclusion == 'failure' && | ||
| github.event.workflow_run.head_repository.full_name == github.repository && | ||
| (github.event.workflow_run.event == 'schedule' || | ||
| github.event.workflow_run.head_branch == 'main') | ||
| (github.event.workflow_run.head_branch == 'main' && | ||
| (github.event.workflow_run.event == 'push' || | ||
| github.event.workflow_run.event == 'workflow_dispatch'))) | ||
| steps: | ||
| - name: Open or update the issue | ||
| uses: actions/github-script@v7 | ||
|
|
@@ -102,46 +105,97 @@ jobs: | |
| core.notice(`Updated issue #${issueNumber}`); | ||
| }; | ||
|
|
||
| const findByTitle = (issues) => issues.find((issue) => issue.title === title); | ||
| const REPORTER_MARKER = | ||
| "Opened by `.github/workflows/nightly-failure-issue.yml`"; | ||
|
|
||
| let match = findByTitle(await listOpenIssues()); | ||
| if (match) { | ||
| await commentOnIssue(match.number); | ||
| const isReportableIssue = (issue) => | ||
| issue.title === title && !issue.pull_request; | ||
|
|
||
| const pickKeeper = (issues) => { | ||
| const matches = issues.filter(isReportableIssue); | ||
| if (matches.length === 0) { | ||
| return undefined; | ||
| } | ||
| matches.sort((a, b) => a.number - b.number); | ||
| return matches[0]; | ||
| }; | ||
|
|
||
| const issueBodyMatches = async (issue) => { | ||
| if (issue.body && issue.body.includes(REPORTER_MARKER)) { | ||
| return true; | ||
| } | ||
| const full = await github.rest.issues.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| }); | ||
| return full.data.body.includes(REPORTER_MARKER); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking. This call sits after
|
||
| }; | ||
|
|
||
| const closeAsDuplicateOf = async (issueNumber, keeperNumber) => { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| body: `Duplicate of #${keeperNumber}. Closing in favor of the canonical nightly issue.`, | ||
| }); | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| state: "closed", | ||
| state_reason: "not_planned", | ||
| }); | ||
| }; | ||
|
|
||
| const syncKeeper = async () => { | ||
| const open = await listOpenIssues(); | ||
| const keeper = pickKeeper(open); | ||
| if (!keeper) { | ||
| return undefined; | ||
| } | ||
| await commentOnIssue(keeper.number); | ||
| for (const issue of open) { | ||
| if (!isReportableIssue(issue) || issue.number === keeper.number) { | ||
| continue; | ||
| } | ||
| if (!(await issueBodyMatches(issue))) { | ||
| continue; | ||
| } | ||
| await closeAsDuplicateOf(issue.number, keeper.number); | ||
| } | ||
| return keeper; | ||
| }; | ||
|
|
||
| let keeper = await syncKeeper(); | ||
| if (!keeper) { | ||
| keeper = await syncKeeper(); | ||
| } | ||
| if (keeper) { | ||
| core.notice(`Updated issue #${keeper.number}`); | ||
| } else { | ||
| match = findByTitle(await listOpenIssues()); | ||
| if (match) { | ||
| await commentOnIssue(match.number); | ||
| } else { | ||
| const created = await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title, | ||
| body, | ||
| labels: labelReady ? ["ci-nightly"] : [], | ||
| }); | ||
| const sameTitle = (await listOpenIssues()).filter( | ||
| (issue) => issue.title === title, | ||
| const created = await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title, | ||
| body, | ||
| labels: labelReady ? ["ci-nightly"] : [], | ||
| }); | ||
| const open = await listOpenIssues(); | ||
| const reportable = open.filter(isReportableIssue); | ||
| const older = reportable.find( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking. On The mutual-close case is fixed. A higher peer is not Select the lowest number with |
||
| (issue) => issue.number < created.data.number, | ||
| ); | ||
| if (older) { | ||
| await closeAsDuplicateOf(created.data.number, older.number); | ||
| await commentOnIssue(older.number); | ||
| core.notice( | ||
| `Closed duplicate #${created.data.number}; kept #${older.number}`, | ||
| ); | ||
| sameTitle.sort((a, b) => a.number - b.number); | ||
| const keep = sameTitle[0] ?? created.data; | ||
| if (keep.number !== created.data.number) { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: created.data.number, | ||
| body: `Duplicate of #${keep.number}. Closing in favor of the earlier open issue.`, | ||
| }); | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: created.data.number, | ||
| state: "closed", | ||
| state_reason: "not_planned", | ||
| }); | ||
| await commentOnIssue(keep.number); | ||
| core.notice( | ||
| `Closed duplicate #${created.data.number}; kept #${keep.number}`, | ||
| ); | ||
| } else { | ||
| keeper = await syncKeeper(); | ||
| if (keeper) { | ||
| core.notice(`Opened issue #${keeper.number}`); | ||
| } else { | ||
| core.notice(`Opened issue #${created.data.number}`); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right job.
gatechecks out, runs this before Rust setup, does not skip it on a docs-only diff, and a failing unittest fails the step.python3 scripts/ci/test_workflow_policy.py -vexited 0 here (16 tests).Nothing in
test_workflow_policy.pyreadsci.ymlfor this command. Deleting the step leaves the unittest green for anyone who runs the file, and the gate stops enforcing it.test_ci_gate_is_required_before_heavy_jobsalready loads this workflow. Assertpython3 scripts/ci/test_workflow_policy.pythere.The new event test is still a substring check. It stays green if the three event names remain in the file while the boolean around them changes. The expression on
nightly-failure-issue.ymllines 40–46 is parenthesized correctly today.