Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: close the unit-run issue once a later full unit run on main succeeds (#9781)

Cindy Zhang83f8e2a96912
diff --git a/.github/scripts/ci-heavy-lanes.test.mjs b/.github/scripts/ci-heavy-lanes.test.mjs
index d4bd126f02..1c197d293a 100644
--- a/.github/scripts/ci-heavy-lanes.test.mjs
+++ b/.github/scripts/ci-heavy-lanes.test.mjs
@@ -226,6 +226,7 @@ describe("main's release-check and full unit run, about once an hour (DEC-11, FR
listed: [],
issues: [],
comments: [],
+ updates: [],
});
const github = {
rest: {
@@ -262,6 +263,7 @@ describe("main's release-check and full unit run, about once an hour (DEC-11, FR
issues: {
create: async args => calls.issues.push(args),
createComment: async args => calls.comments.push(args),
+ update: async args => calls.updates.push(args),
},
},
};
@@ -594,6 +596,90 @@ describe("main's release-check and full unit run, about once an hour (DEC-11, FR
},
);
+ const bot = {login: 'github-actions[bot]'};
+
+ it("closes this job's own open issue, naming the green run, once a later full unit run succeeds", async () => {
+ const calls = await run({
+ runs: [check(20, {head_sha: sha})],
+ units: [check(20)],
+ issue: {number: 42, title, user: bot},
+ });
+ expect(calls.comments).toEqual([
+ expect.objectContaining({issue_number: 42}),
+ ]);
+ expect(calls.comments[0].body).toContain(
+ 'https://github.com/meta/astryx/actions/runs/20',
+ );
+ expect(calls.comments[0].body).toContain('succeeded');
+ // An unnamed run names no commit: it tested main's tip when it started.
+ expect(calls.comments[0].body).not.toMatch(/ for [0-9a-f]{7} /);
+ expect(calls.updates).toEqual([
+ expect.objectContaining({
+ issue_number: 42,
+ state: 'closed',
+ state_reason: 'completed',
+ }),
+ ]);
+ expect(calls.issues).toEqual([]);
+ });
+
+ it('names the commit a named run tested', async () => {
+ // The run's event commit differs from the commit it names, as when a
+ // dispatch races a merge.
+ const calls = await run({
+ runs: [check(20, {head_sha: sha})],
+ units: [unitAt(20, {head_sha: 'e'.repeat(40)})],
+ issue: {number: 42, title, user: bot},
+ });
+ expect(calls.comments[0].body).toContain(
+ ` for ${sha.slice(0, 7)} succeeded`,
+ );
+ });
+
+ it('leaves an issue a person opened with the same title open', async () => {
+ const calls = await run({
+ runs: [check(20, {head_sha: sha})],
+ units: [check(20)],
+ issue: {number: 43, title, user: {login: 'someone'}},
+ });
+ expect(calls.comments).toEqual([]);
+ expect(calls.updates).toEqual([]);
+ });
+
+ it('does nothing after a success when no issue is open', async () => {
+ const calls = await run({
+ runs: [check(20, {head_sha: sha})],
+ units: [check(20)],
+ });
+ expect(calls.comments).toEqual([]);
+ expect(calls.updates).toEqual([]);
+ expect(calls.issues).toEqual([]);
+ });
+
+ it('keeps the issue open while the newest full unit run did not complete', async () => {
+ const calls = await run({
+ runs: [check(20, {head_sha: sha})],
+ units: [check(20, {conclusion: 'cancelled'})],
+ issue: {number: 42, title, user: bot},
+ });
+ expect(calls.updates).toEqual([]);
+ expect(calls.comments).toEqual([
+ expect.objectContaining({issue_number: 42}),
+ ]);
+ });
+
+ it('warns and keeps going when the issue lookup fails after a success', async () => {
+ const calls = await run({
+ runs: [check(20, {head_sha: sha})],
+ units: [check(20)],
+ issue: 'unavailable',
+ });
+ expect(calls.updates).toEqual([]);
+ expect(calls.warnings.join('\n')).toMatch(
+ /Could not close the unit-run issue/,
+ );
+ });
+
it('comments on the open guardian issue instead of opening another', async () => {
const calls = await run({
runs: [check(20, {head_sha: sha})],
diff --git a/.github/workflows/main-heavy-lanes.yml b/.github/workflows/main-heavy-lanes.yml
index db8336937e..3fd03fa7e2 100644
--- a/.github/workflows/main-heavy-lanes.yml
+++ b/.github/workflows/main-heavy-lanes.yml
@@ -225,8 +225,9 @@ jobs:
await github.rest.actions.createWorkflowDispatch({...context.repo, workflow_id: 'deploy.yml', ref: 'main', inputs: {sha: tip}});
}
+ const UNIT_ISSUE_TITLE = 'Main unit tests: an hourly run did not complete';
if (incomplete) {
- const title = 'Main unit tests: an hourly run did not complete';
+ const title = UNIT_ISSUE_TITLE;
const note = `The full unit run ${newest.html_url} for ${newest.head_sha.slice(0, 7)} ended ${newest.conclusion}. The next run was dispatched for ${short}.`;
core.warning(note);
const {data: found} = await github.rest.search.issuesAndPullRequests({
@@ -239,3 +240,27 @@ jobs:
await github.rest.issues.create({...context.repo, title, body: `${note}\n\nClose this issue once main's full unit runs complete again (spec:AST-030 FR21).`});
}
}
+
+ // A later full unit run that succeeded closes this job's own open
+ // issue, with a comment naming that run. An issue a person opened
+ // stays open. A failed lookup leaves the issue for the next tick.
+ if (newest?.status === 'completed' && newest.conclusion === 'success') {
+ try {
+ const {data: found} = await github.rest.search.issuesAndPullRequests({
+ q: `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open in:title "${UNIT_ISSUE_TITLE}"`,
+ });
+ const issue = found.items.find(item => item.title === UNIT_ISSUE_TITLE && item.user?.login === BOT);
+ if (issue) {
+ await github.rest.issues.createComment({
+ ...context.repo,
+ issue_number: issue.number,
+ // The commit the run tested: the one it names, or none for an
+ // unnamed run, which tested main's tip when it started (FR21).
+ body: `The full unit run ${newest.html_url}${tested(newest) ? ` for ${tested(newest).slice(0, 7)}` : ''} succeeded, so main's full unit runs complete again. Closing.`,
+ });
+ await github.rest.issues.update({...context.repo, issue_number: issue.number, state: 'closed', state_reason: 'completed'});
+ }
+ } catch (error) {
+ core.warning(`Could not close the unit-run issue: ${error.message}`);
+ }
+ }
diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md
index 13ebd90b3a..ab976637a5 100644
--- a/docs/specs/AST-030/spec.md
+++ b/docs/specs/AST-030/spec.md
@@ -506,7 +506,7 @@ they are separately named.
queues behind it; only a release re-check replaces it (FR22, DEC-18). A unit run that is skipped, cancelled or otherwise does not
complete makes the next one dispatch at once and is reported in the
guardian's issue; a newer run that replaced it, such as a recheck, leaves
- nothing to report. A stable release publishes only from a cut commit with
+ nothing to report. Once main's newest full unit run succeeds, the dispatcher comments on that issue, naming the run and the commit it tested, and closes it; it closes only an issue it opened, and a failed lookup retries on the next tick. A stable release publishes only from a cut commit with
both a passing release-check and a passing full unit run (DEC-15).
- **FR22 — Main's full unit run finishes in minutes.** The Main workflow runs
@@ -677,6 +677,7 @@ The nightly perf lane is the one scheduled measurement outside them (FR18).
| FR19 | `ci-impact.test.mjs`, `pr-preview.test.mjs` and the maintenance template | CI change and non-CI change; standard, non-standard and expression runners; added, removed and changed jobs; trigger change | a CI change reports no impact, a move onto a non-standard runner or a pool or time-to-green rise past its threshold goes unflagged, or the section names a price |
| FR20 | `ci-heavy-deferral.test.mjs` over ci.yml, lint.yml and pr-comment.yml | agent push; marked ready; opened; reopened; re-run; another author; release branch; merge-back; spec-only change; Lab-only change; a release-check and an opt-in label run, where the decision skips; a failed-jobs re-run of a deferred push | a heavy job runs on a deferred push, a required context passes or skips on one, a ready, reopened or re-run pull request defers, a spec-only or Lab-only change defers, the report hides the deferral, or a job below the decision skips because it skipped |
| FR21 | `ci-heavy-lanes.test.mjs` dispatch cases, `main-unit-run.test.mjs` over deploy.yml, `release-check-receipt.test.mjs` | push run; dispatched unit run; tip with the scheduler's or a person's release-check, or a person's maintenance capture; unit run cancelled, skipped or timed out; newer recheck or person's run of the tip; a person's validation of an older commit; cut commit with and without a passing unit run | a push runs the unit suites, a push cancels a unit run, a release-check comes without a unit run of its commit, an incomplete run goes unreported or waits a window, or a cut publishes without a passing unit run |
+| FR21 | `ci-heavy-lanes.test.mjs` issue-closing cases | a newest unit run that succeeded with the bot's issue open; a person's issue with the same title; no open issue; a newest run that did not complete; a failed lookup; a named run whose event commit differs | the bot's issue stays open after a success, a person's issue closes, a call runs with no open issue, the issue closes on an incomplete run, a failed lookup fails the dispatcher, or the comment names the event commit |
| FR22 | `main-validation-workflow.test.mjs` over the Main workflow and its commit resolver; `vitest-shard-sequencer.test.mjs` over the recorded Node times | six UI and six Node legs; dispatch without a commit, with a commit in main's history, with a commit outside it and with a malformed one; a re-check from the workflow token and from a person, and one that names `sha`; a `sha` before the size records, and one of only spaces; four and six Node legs over the recorded suite, a file with no recorded time, a project other than `node` | a hold, a leg past the fifteen-minute budget, a commit outside main's history that validates, a person's dispatch or a person's `sha` run that cancels or replaces a validation of main, a `sha` lane that checks out another commit, or a `sha` run named for main's tip, or two of the slowest Node files in one leg, a file run by no leg or by two, or a split that depends on collection order fails |
| FR23 | `release-check-shape.test.mjs`, `a11y-contract-shard.test.mjs` and the release-check workflow contract | release-check and pull-request legs; a contract file longer than a leg's share, one it cannot name exactly, and a serial one; the recorded suite; a re-check from an admin, a maintainer and a writer, from another branch, with a short SHA and with an older commit; failed-only beside a passed, a running and a missing run | a narrower release-check, a held or over-budget leg, a test selected by no leg or by two, a re-check that a writer can start, that waits for main's running check, or that re-runs jobs of another commit fails |
| FR24 | `ci-heavy-lanes.test.mjs` cadence cases | release-check 170 and 176 minutes old; the unit lane hourly beside it; weekday 06:37 Pacific inside the window in standard and daylight time; the pre-cut check already started; the tip already checked; a weekend morning; before 06:30 and after 07:30 | a release-check starts inside the 175-minute window, the pre-cut check is skipped or starts twice, or it runs on a weekend |