Skip to content

Commit 00a2101

Browse files
andreiborzaclaude
andauthored
ci: Show an unknown status for optional E2E jobs without a final result (#25660)
## What The optional E2E report no longer shows a job as failing when its result is not known. Such jobs now show "Status unknown", and a job without a valid start or end time shows no duration. ## Why Jobs with other results (for example neutral or no result yet) showed "Failing after" with a wrong duration. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5521cfc commit 00a2101

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

‎dev-packages/optional-e2e-gh-action/index.mjs‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async function reportInComment(octokit, repo, prNumber, workflowRun) {
118118
);
119119

120120
const counts = [
121-
failing.length && `${failing.length} failing`,
121+
failing.length && `${failing.length} not successful`,
122122
successful.length && `${successful.length} successful`,
123123
].filter(Boolean);
124124
const runLink = `[See the run](${workflowRun.html_url})`;
@@ -162,16 +162,33 @@ function formatJobs(jobs) {
162162
}
163163

164164
function formatStatus({ conclusion, started_at, completed_at }) {
165-
const seconds = Math.round((new Date(completed_at) - new Date(started_at)) / 1000);
166-
const duration = seconds >= 60 ? `${Math.floor(seconds / 60)}m` : `${seconds}s`;
165+
const duration = formatDuration(started_at, completed_at);
166+
const withDuration = (status, preposition) => (duration ? `${status} ${preposition} ${duration}` : status);
167+
168+
switch (conclusion) {
169+
case 'success':
170+
return withDuration('Successful', 'in');
171+
case 'failure':
172+
return withDuration('Failing', 'after');
173+
case 'timed_out':
174+
return withDuration('Timed out', 'after');
175+
case 'cancelled':
176+
return withDuration('Cancelled', 'after');
177+
default:
178+
return 'Status unknown';
179+
}
180+
}
167181

168-
if (conclusion === 'success') {
169-
return `Successful in ${duration}`;
182+
// A job that never started has no `started_at`, and `new Date(null)` is the epoch, which gives a wrong duration.
183+
function formatDuration(startedAt, completedAt) {
184+
if (!startedAt || !completedAt) {
185+
return undefined;
170186
}
171-
if (conclusion === 'cancelled') {
172-
return `Cancelled after ${duration}`;
187+
const seconds = Math.round((new Date(completedAt) - new Date(startedAt)) / 1000);
188+
if (!Number.isFinite(seconds) || seconds < 0) {
189+
return undefined;
173190
}
174-
return `Failing after ${duration}`;
191+
return seconds >= 60 ? `${Math.floor(seconds / 60)}m` : `${seconds}s`;
175192
}
176193

177194
run().catch(error => core.setFailed(error.message));

0 commit comments

Comments
 (0)