Restore [release] and v* trigger
Browse files at this commitd30dc313abe8ad05354715c291125cd71011504aParent: d000946- ci
- restore [release] and v* trigger
- ⚡ live-updating CI runs page
5 changed files +328 -59
- .forge/ci.toml +4 -0
- crates/forge-web/assets/nav.js +91 -1
- crates/forge-web/src/ci/api.rs +5 -0
- crates/forge-web/src/pages/ci_runs.rs +151 -57
- crates/forge-web/src/pages/ci_tests.rs +77 -1
.forge/ci.tomlmodified+4 -0
| @@ -7,6 +7,7 @@ | |||
| 7 | push = ["main"] | 7 | push = ["main"] |
| 8 | pull_request = true | 8 | pull_request = true |
| 9 | manual = true | 9 | manual = true |
| 10 | +tags = ["v*"] | ||
| 10 | 11 | ||
| 11 | [jobs.test] | 12 | [jobs.test] |
| 12 | image = "docker.io/library/rust:1" | 13 | image = "docker.io/library/rust:1" |
| @@ -34,3 +35,6 @@ mkdir -p dist && cp target/dist/forge dist/forge | |||
| 34 | artifacts = ["dist/forge", "forge-*-linux", "SHA256SUMS"] | 35 | artifacts = ["dist/forge", "forge-*-linux", "SHA256SUMS"] |
| 35 | cache = ["target"] | 36 | cache = ["target"] |
| 36 | timeout_minutes = 120 | 37 | timeout_minutes = 120 |
| 38 | + | ||
| 39 | +[release] | ||
| 40 | +assets = ["build:forge-*-linux", "build:SHA256SUMS"] | ||
crates/forge-web/assets/nav.jsmodified+91 -1
| @@ -153,6 +153,7 @@ | |||
| 153 | followTail(); | 153 | followTail(); |
| 154 | syncUnread(); | 154 | syncUnread(); |
| 155 | syncLive(); | 155 | syncLive(); |
| 156 | + syncTick(); | ||
| 156 | } | 157 | } |
| 157 | 158 | ||
| 158 | // The log tail is a terminal: it opens at its end. A reader who scrolls up keeps their place. | 159 | // The log tail is a terminal: it opens at its end. A reader who scrolls up keeps their place. |
| @@ -487,12 +488,14 @@ | |||
| 487 | // the stream once the status is terminal, and the swap that shows that page (no data-live) closes it. | 488 | // the stream once the status is terminal, and the swap that shows that page (no data-live) closes it. |
| 488 | var liveStream = null; | 489 | var liveStream = null; |
| 489 | var liveUrl = null; | 490 | var liveUrl = null; |
| 491 | + var liveTimer = null; // a run list's pending refresh: bursts of events (log lines) share one | ||
| 490 | 492 | ||
| 491 | function closeLive() { | 493 | function closeLive() { |
| 492 | if (liveStream) { liveStream.close(); } | 494 | if (liveStream) { liveStream.close(); } |
| 493 | liveStream = null; | 495 | liveStream = null; |
| 494 | liveUrl = null; | 496 | liveUrl = null; |
| 495 | liveDirty = false; | 497 | liveDirty = false; |
| 498 | + if (liveTimer) { clearTimeout(liveTimer); liveTimer = null; } | ||
| 496 | } | 499 | } |
| 497 | 500 | ||
| 498 | function syncLive() { | 501 | function syncLive() { |
| @@ -511,7 +514,10 @@ | |||
| 511 | // A job page's stream opens with the status the page already shows: nothing to re-render then. | 514 | // A job page's stream opens with the status the page already shows: nothing to re-render then. |
| 512 | var wrap = document.querySelector('[data-live]'); | 515 | var wrap = document.querySelector('[data-live]'); |
| 513 | if (document.querySelector('[data-live-log]') && wrap && wrap.getAttribute('data-live-state') === e.data) { return; } | 516 | if (document.querySelector('[data-live-log]') && wrap && wrap.getAttribute('data-live-state') === e.data) { return; } |
| 514 | - refreshLive(); | 517 | + // The run list changes on every log chunk of every job: refresh at most once a second. |
| 518 | + if (document.querySelector('[data-live-log]')) { refreshLive(); return; } | ||
| 519 | + if (liveTimer) { return; } | ||
| 520 | + liveTimer = setTimeout(function () { liveTimer = null; refreshLive(); }, 1000); | ||
| 515 | }); | 521 | }); |
| 516 | liveStream.addEventListener('log', function (e) { appendLog(e.data); }); | 522 | liveStream.addEventListener('log', function (e) { appendLog(e.data); }); |
| 517 | } | 523 | } |
| @@ -536,8 +542,92 @@ | |||
| 536 | load({ target: withoutHash(here), dest: here, init: GET_INIT, how: 'live', keep: true, post: false, form: null }); | 542 | load({ target: withoutHash(here), dest: here, init: GET_INIT, how: 'live', keep: true, post: false, form: null }); |
| 537 | } | 543 | } |
| 538 | 544 | ||
| 545 | + // Local clock for what runs. Server-rendered [data-since] (unix seconds) is the start of a duration | ||
| 546 | + // still counting: its text is rewritten each second. [data-tick] boxes of the run list's bars and | ||
| 547 | + // the run timeline grow with the clock. This is a display clock only: no request is made. The | ||
| 548 | + // timer lives while such elements are on the page and stops when a swap removes the last one. The | ||
| 549 | + // server's next event brings the true state. [data-now] on the page root gives the server's clock. | ||
| 550 | + var tickTimer = null; | ||
| 551 | + var tickSkew = 0; // server clock minus the browser's, in ms | ||
| 552 | + | ||
| 553 | + function stopTick() { | ||
| 554 | + if (tickTimer) { clearInterval(tickTimer); } | ||
| 555 | + tickTimer = null; | ||
| 556 | + } | ||
| 557 | + | ||
| 558 | + function syncTick() { | ||
| 559 | + var root = document.querySelector('[data-now]'); | ||
| 560 | + if (!root || !document.querySelector('[data-since], [data-tick]')) { stopTick(); return; } | ||
| 561 | + tickSkew = (parseInt(root.getAttribute('data-now'), 10) || 0) * 1000 - Date.now(); | ||
| 562 | + if (!tickTimer) { tickTimer = setInterval(tickAll, 1000); } | ||
| 563 | + tickAll(); | ||
| 564 | + } | ||
| 565 | + | ||
| 566 | + function fmtDuration(secs, root) { | ||
| 567 | + secs = Math.max(0, Math.floor(secs)); | ||
| 568 | + if (secs >= 60) { | ||
| 569 | + return (root.getAttribute('data-fm') || '{m}m {s}s') | ||
| 570 | + .replace('{m}', Math.floor(secs / 60)).replace('{s}', secs % 60); | ||
| 571 | + } | ||
| 572 | + return (root.getAttribute('data-fs') || '{s}s').replace('{s}', secs); | ||
| 573 | + } | ||
| 574 | + | ||
| 575 | + function place(offset, span, width) { | ||
| 576 | + if (span <= 0) { return 0; } | ||
| 577 | + return Math.round(Math.min(Math.max(offset, 0), span) * width / span); | ||
| 578 | + } | ||
| 579 | + | ||
| 580 | + // Geometry shared with the server: the timeline's track and the list bar's width. | ||
| 581 | + var TRACK_X = 100, TRACK_W = 530, LIST_W = 1000; | ||
| 582 | + | ||
| 583 | + function tickAll() { | ||
| 584 | + var root = document.querySelector('[data-now]'); | ||
| 585 | + var live = document.querySelectorAll('[data-since], [data-tick]'); | ||
| 586 | + if (!root || !live.length) { stopTick(); return; } | ||
| 587 | + if (document.hidden) { return; } | ||
| 588 | + var now = (Date.now() + tickSkew) / 1000; | ||
| 589 | + Array.prototype.forEach.call(live, function (el) { | ||
| 590 | + var since = el.getAttribute('data-since'); | ||
| 591 | + if (since !== null) { | ||
| 592 | + var text = fmtDuration(now - parseInt(since, 10), root); | ||
| 593 | + var pre = el.getAttribute('data-pre'); | ||
| 594 | + if (pre !== null) { text = pre + text + (el.getAttribute('data-post') || ''); } | ||
| 595 | + if (el.textContent !== text) { el.textContent = text; } | ||
| 596 | + return; | ||
| 597 | + } | ||
| 598 | + var svg = el.ownerSVGElement; | ||
| 599 | + var how = el.getAttribute('data-tick'); | ||
| 600 | + if (!svg || !how) { return; } | ||
| 601 | + var origin = parseInt(svg.getAttribute('data-origin'), 10) || 0; | ||
| 602 | + var xn, min, right; | ||
| 603 | + if (svg.hasAttribute('data-len')) { | ||
| 604 | + xn = TRACK_X + place(now - origin, parseInt(svg.getAttribute('data-len'), 10), TRACK_W); | ||
| 605 | + min = 3; right = TRACK_X + TRACK_W; | ||
| 606 | + } else { | ||
| 607 | + xn = place(now - origin, parseInt(svg.getAttribute('data-scale'), 10), LIST_W); | ||
| 608 | + min = 2; right = LIST_W; | ||
| 609 | + } | ||
| 610 | + var x = parseFloat(el.getAttribute('x')) || 0; | ||
| 611 | + if (how === 'grow') { el.setAttribute('width', Math.max(min, xn - x)); } | ||
| 612 | + else if (how === 'edge') { el.setAttribute('x', Math.max(0, xn - 3)); } | ||
| 613 | + else if (how === 'follow' || how === 'rest') { | ||
| 614 | + el.setAttribute('x', xn); | ||
| 615 | + el.setAttribute('width', Math.max(0, right - xn)); | ||
| 616 | + } | ||
| 617 | + }); | ||
| 618 | + // Labels that sit at the moving edge (a waiting job's "waiting"). | ||
| 619 | + Array.prototype.forEach.call(document.querySelectorAll('text[data-follow]'), function (t) { | ||
| 620 | + var svg = t.ownerSVGElement; | ||
| 621 | + if (!svg || !svg.hasAttribute('data-len')) { return; } | ||
| 622 | + var xn = TRACK_X + place(now - (parseInt(svg.getAttribute('data-origin'), 10) || 0), | ||
| 623 | + parseInt(svg.getAttribute('data-len'), 10), TRACK_W); | ||
| 624 | + t.setAttribute('x', xn + (parseInt(t.getAttribute('data-follow'), 10) || 0)); | ||
| 625 | + }); | ||
| 626 | + } | ||
| 627 | + | ||
| 539 | followTail(); | 628 | followTail(); |
| 540 | syncLive(); | 629 | syncLive(); |
| 630 | + syncTick(); | ||
| 541 | 631 | ||
| 542 | window.__forgeQuery = function (href) { | 632 | window.__forgeQuery = function (href) { |
| 543 | var url = pageUrl(href); | 633 | var url = pageUrl(href); |
crates/forge-web/src/ci/api.rsmodified+5 -0
| @@ -497,6 +497,11 @@ async fn write_log( | |||
| 497 | .await | 497 | .await |
| 498 | .map_err(api::internal)?; | 498 | .map_err(api::internal)?; |
| 499 | state.ci_live.bump_job(&job.id); | 499 | state.ci_live.bump_job(&job.id); |
| 500 | + // The run page shows the last log lines, so its streams wake too. The page debounces. | ||
| 501 | + state.ci_live.bump_run(&job.run_id); | ||
| 502 | + if let Ok(Some(run)) = state.store.run_by_id(&job.run_id).await { | ||
| 503 | + state.ci_live.bump_repo(&run.repo_id); | ||
| 504 | + } | ||
| 500 | Ok(LogWrite::Stored(size + len)) | 505 | Ok(LogWrite::Stored(size + len)) |
| 501 | } | 506 | } |
| 502 | 507 | ||
crates/forge-web/src/pages/ci_runs.rsmodified+151 -57
| @@ -196,6 +196,17 @@ fn duration_text(lang: Lang, started: Option<&str>, finished: Option<&str>) -> S | |||
| 196 | } | 196 | } |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | +/// The duration formats of `lang` with `{m}` and `{s}` where the numbers go, for the client ticker: | ||
| 200 | +/// the one with minutes and the seconds-only one. | ||
| 201 | +fn duration_templates(lang: Lang) -> (String, String) { | ||
| 202 | + ( | ||
| 203 | + g::duration_minutes(lang, 111_111, 222_222) | ||
| 204 | + .replace("111111", "{m}") | ||
| 205 | + .replace("222222", "{s}"), | ||
| 206 | + g::duration_seconds(lang, 222_222).replace("222222", "{s}"), | ||
| 207 | + ) | ||
| 208 | +} | ||
| 209 | + | ||
| 199 | /// Words for a state name, as the pages show it: `waiting_approval` reads "waiting approval". | 210 | /// Words for a state name, as the pages show it: `waiting_approval` reads "waiting approval". |
| 200 | /// A state this build does not know is shown with its underscores as spaces. | 211 | /// A state this build does not know is shown with its underscores as spaces. |
| 201 | pub fn state_text(lang: Lang, state: &str) -> String { | 212 | pub fn state_text(lang: Lang, state: &str) -> String { |
| @@ -290,6 +301,11 @@ struct RunRow { | |||
| 290 | title: String, | 301 | title: String, |
| 291 | bar: Vec<Rect>, | 302 | bar: Vec<Rect>, |
| 292 | duration: String, | 303 | duration: String, |
| 304 | + /// Unix seconds the duration counts from while the run is live, for the client's local ticker. | ||
| 305 | + since: Option<String>, | ||
| 306 | + /// The run's start and the list's scale, which the ticker needs to grow the running segments. | ||
| 307 | + origin: String, | ||
| 308 | + scale: String, | ||
| 293 | meta: String, | 309 | meta: String, |
| 294 | } | 310 | } |
| 295 | 311 | ||
| @@ -327,6 +343,8 @@ struct JobLine { | |||
| 327 | detail: String, | 343 | detail: String, |
| 328 | runner: String, | 344 | runner: String, |
| 329 | duration: String, | 345 | duration: String, |
| 346 | + /// Unix seconds a running job's duration counts from. | ||
| 347 | + since: Option<String>, | ||
| 330 | } | 348 | } |
| 331 | 349 | ||
| 332 | /// The last lines of the log of the job the run page points at. | 350 | /// The last lines of the log of the job the run page points at. |
| @@ -348,6 +366,8 @@ struct RunDetail { | |||
| 348 | actor: String, | 366 | actor: String, |
| 349 | when: String, | 367 | when: String, |
| 350 | duration: String, | 368 | duration: String, |
| 369 | + /// Unix seconds the header duration counts from while the run is not finished. | ||
| 370 | + since: Option<String>, | ||
| 351 | config_error: Option<String>, | 371 | config_error: Option<String>, |
| 352 | action_base: String, | 372 | action_base: String, |
| 353 | can_approve: bool, | 373 | can_approve: bool, |
| @@ -365,6 +385,8 @@ struct Rect { | |||
| 365 | y: String, | 385 | y: String, |
| 366 | w: String, | 386 | w: String, |
| 367 | h: String, | 387 | h: String, |
| 388 | + /// How the client's ticker moves this box with the clock: `grow`, `edge`, `follow` or `rest`. | ||
| 389 | + tick: Option<String>, | ||
| 368 | } | 390 | } |
| 369 | 391 | ||
| 370 | impl Rect { | 392 | impl Rect { |
| @@ -375,22 +397,39 @@ impl Rect { | |||
| 375 | y: y.to_string(), | 397 | y: y.to_string(), |
| 376 | w: w.to_string(), | 398 | w: w.to_string(), |
| 377 | h: h.to_string(), | 399 | h: h.to_string(), |
| 400 | + tick: None, | ||
| 378 | } | 401 | } |
| 379 | } | 402 | } |
| 403 | + | ||
| 404 | + fn ticking(mut self, how: &str) -> Rect { | ||
| 405 | + self.tick = Some(how.to_owned()); | ||
| 406 | + self | ||
| 407 | + } | ||
| 380 | } | 408 | } |
| 381 | 409 | ||
| 382 | /// A text label of the timeline. | 410 | /// A text label of the timeline. |
| 411 | +#[derive(Default)] | ||
| 383 | struct Label { | 412 | struct Label { |
| 384 | class: &'static str, | 413 | class: &'static str, |
| 385 | x: String, | 414 | x: String, |
| 386 | y: String, | 415 | y: String, |
| 387 | anchor: &'static str, | 416 | anchor: &'static str, |
| 388 | text: String, | 417 | text: String, |
| 418 | + /// Unix seconds of a running job's start: the ticker writes `pre` + duration + `post` as the text. | ||
| 419 | + since: Option<String>, | ||
| 420 | + pre: Option<String>, | ||
| 421 | + post: Option<String>, | ||
| 422 | + /// Set when the label sits at the moving edge `now`, with this offset from it. | ||
| 423 | + follow: Option<String>, | ||
| 389 | } | 424 | } |
| 390 | 425 | ||
| 391 | /// The timeline of a run: its SVG viewBox, its boxes, its connectors and its labels, in draw order. | 426 | /// The timeline of a run: its SVG viewBox, its boxes, its connectors and its labels, in draw order. |
| 392 | struct Gantt { | 427 | struct Gantt { |
| 393 | view_box: String, | 428 | view_box: String, |
| 429 | + /// The axis start and length in seconds, for the ticker. | ||
| 430 | + origin: String, | ||
| 431 | + len: String, | ||
| 432 | + live: bool, | ||
| 394 | rects: Vec<Rect>, | 433 | rects: Vec<Rect>, |
| 395 | links: Vec<String>, | 434 | links: Vec<String>, |
| 396 | labels: Vec<Label>, | 435 | labels: Vec<Label>, |
| @@ -551,17 +590,21 @@ fn row_bar(jobs: &[Timing], origin: i64, scale: i64, now: i64, running: bool) -> | |||
| 551 | }; | 590 | }; |
| 552 | let x = place(start - origin, scale, LIST_BAR_W); | 591 | let x = place(start - origin, scale, LIST_BAR_W); |
| 553 | let to = place(end - origin, scale, LIST_BAR_W); | 592 | let to = place(end - origin, scale, LIST_BAR_W); |
| 554 | - bar.push(Rect::new( | 593 | + let mut seg = Rect::new( |
| 555 | format!("ci-seg {}", tone(job.state)), | 594 | format!("ci-seg {}", tone(job.state)), |
| 556 | x, | 595 | x, |
| 557 | 0, | 596 | 0, |
| 558 | (to - x).max(2), | 597 | (to - x).max(2), |
| 559 | 6, | 598 | 6, |
| 560 | - )); | 599 | + ); |
| 600 | + if job.finished.is_none() { | ||
| 601 | + seg = seg.ticking("grow"); | ||
| 602 | + } | ||
| 603 | + bar.push(seg); | ||
| 561 | } | 604 | } |
| 562 | if running { | 605 | if running { |
| 563 | let x = place(now - origin, scale, LIST_BAR_W); | 606 | let x = place(now - origin, scale, LIST_BAR_W); |
| 564 | - bar.push(Rect::new("ci-seg ci-rest", x, 0, LIST_BAR_W - x, 6)); | 607 | + bar.push(Rect::new("ci-seg ci-rest", x, 0, LIST_BAR_W - x, 6).ticking("rest")); |
| 565 | } | 608 | } |
| 566 | bar | 609 | bar |
| 567 | } | 610 | } |
| @@ -599,6 +642,11 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 599 | let height = AXIS_H + jobs.len() as i64 * ROW_H; | 642 | let height = AXIS_H + jobs.len() as i64 * ROW_H; |
| 600 | let mut g = Gantt { | 643 | let mut g = Gantt { |
| 601 | view_box: format!("0 0 {GANTT_W} {height}"), | 644 | view_box: format!("0 0 {GANTT_W} {height}"), |
| 645 | + origin: origin.to_string(), | ||
| 646 | + len: len.to_string(), | ||
| 647 | + live: jobs | ||
| 648 | + .iter() | ||
| 649 | + .any(|job| job.started.is_some() && job.finished.is_none()), | ||
| 602 | rects: Vec::new(), | 650 | rects: Vec::new(), |
| 603 | links: Vec::new(), | 651 | links: Vec::new(), |
| 604 | labels: Vec::new(), | 652 | labels: Vec::new(), |
| @@ -619,6 +667,7 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 619 | y: (AXIS_H - 8).to_string(), | 667 | y: (AXIS_H - 8).to_string(), |
| 620 | anchor, | 668 | anchor, |
| 621 | text: tick_label(at), | 669 | text: tick_label(at), |
| 670 | + ..Default::default() | ||
| 622 | }); | 671 | }); |
| 623 | } | 672 | } |
| 624 | for (i, job) in jobs.iter().enumerate() { | 673 | for (i, job) in jobs.iter().enumerate() { |
| @@ -631,6 +680,7 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 631 | y: (row_mid(i) - 3).to_string(), | 680 | y: (row_mid(i) - 3).to_string(), |
| 632 | anchor: "start", | 681 | anchor: "start", |
| 633 | text: job.name.clone(), | 682 | text: job.name.clone(), |
| 683 | + ..Default::default() | ||
| 634 | }); | 684 | }); |
| 635 | if let Some(sub) = row_sub(job, lang) { | 685 | if let Some(sub) = row_sub(job, lang) { |
| 636 | g.labels.push(Label { | 686 | g.labels.push(Label { |
| @@ -639,6 +689,7 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 639 | y: (row_mid(i) + 11).to_string(), | 689 | y: (row_mid(i) + 11).to_string(), |
| 640 | anchor: "start", | 690 | anchor: "start", |
| 641 | text: sub, | 691 | text: sub, |
| 692 | + ..Default::default() | ||
| 642 | }); | 693 | }); |
| 643 | } | 694 | } |
| 644 | match (job.started, job.end(now)) { | 695 | match (job.started, job.end(now)) { |
| @@ -655,23 +706,41 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 655 | )); | 706 | )); |
| 656 | } | 707 | } |
| 657 | let width = (x(end) - left).max(MIN_BOX_W); | 708 | let width = (x(end) - left).max(MIN_BOX_W); |
| 658 | - g.rects.push(Rect::new( | 709 | + let live = job.finished.is_none(); |
| 710 | + let mut bar = Rect::new( | ||
| 659 | format!("ci-gbar {}", tone(job.state)), | 711 | format!("ci-gbar {}", tone(job.state)), |
| 660 | left, | 712 | left, |
| 661 | bar_y, | 713 | bar_y, |
| 662 | width, | 714 | width, |
| 663 | BAR_H, | 715 | BAR_H, |
| 664 | - )); | 716 | + ); |
| 717 | + if live { | ||
| 718 | + bar = bar.ticking("grow"); | ||
| 719 | + } | ||
| 720 | + g.rects.push(bar); | ||
| 665 | if job.state == JobState::Running { | 721 | if job.state == JobState::Running { |
| 666 | - g.rects | 722 | + g.rects.push( |
| 667 | - .push(Rect::new("ci-gedge", left + width - 3, bar_y, 3, BAR_H)); | 723 | + Rect::new("ci-gedge", left + width - 3, bar_y, 3, BAR_H).ticking("edge"), |
| 724 | + ); | ||
| 668 | } | 725 | } |
| 669 | let candidates = [ | 726 | let candidates = [ |
| 670 | format!("{} \u{b7} {} \u{b7} {}", job.name, job.duration, job.runner), | 727 | format!("{} \u{b7} {} \u{b7} {}", job.name, job.duration, job.runner), |
| 671 | format!("{} \u{b7} {}", job.name, job.duration), | 728 | format!("{} \u{b7} {}", job.name, job.duration), |
| 672 | job.duration.clone(), | 729 | job.duration.clone(), |
| 673 | ]; | 730 | ]; |
| 674 | - if let Some(text) = bar_text(width, &candidates) { | 731 | + let chosen = bar_text(width, &candidates); |
| 732 | + let affixes = chosen.as_ref().and_then(|_| { | ||
| 733 | + let position = candidates.iter().position(|c| Some(c) == chosen.as_ref())?; | ||
| 734 | + Some(match position { | ||
| 735 | + 0 => ( | ||
| 736 | + format!("{} \u{b7} ", job.name), | ||
| 737 | + format!(" \u{b7} {}", job.runner), | ||
| 738 | + ), | ||
| 739 | + 1 => (format!("{} \u{b7} ", job.name), String::new()), | ||
| 740 | + _ => (String::new(), String::new()), | ||
| 741 | + }) | ||
| 742 | + }); | ||
| 743 | + if let Some(text) = chosen { | ||
| 675 | g.labels.push(Label { | 744 | g.labels.push(Label { |
| 676 | class: if tone(job.state) == "ci-muted" { | 745 | class: if tone(job.state) == "ci-muted" { |
| 677 | "ci-goff" | 746 | "ci-goff" |
| @@ -682,6 +751,10 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 682 | y: label_y, | 751 | y: label_y, |
| 683 | anchor: "start", | 752 | anchor: "start", |
| 684 | text, | 753 | text, |
| 754 | + since: live.then(|| job.started.unwrap_or(start).to_string()), | ||
| 755 | + pre: affixes.as_ref().map(|(pre, _)| pre.clone()), | ||
| 756 | + post: affixes.as_ref().map(|(_, post)| post.clone()), | ||
| 757 | + ..Default::default() | ||
| 685 | }); | 758 | }); |
| 686 | } | 759 | } |
| 687 | } | 760 | } |
| @@ -691,7 +764,7 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 691 | let from = x(queued); | 764 | let from = x(queued); |
| 692 | let width = (x(now) - from).max(MIN_BOX_W); | 765 | let width = (x(now) - from).max(MIN_BOX_W); |
| 693 | g.rects | 766 | g.rects |
| 694 | - .push(Rect::new("ci-glead", from, bar_y, width, BAR_H)); | 767 | + .push(Rect::new("ci-glead", from, bar_y, width, BAR_H).ticking("grow")); |
| 695 | } | 768 | } |
| 696 | } | 769 | } |
| 697 | JobState::Blocked => { | 770 | JobState::Blocked => { |
| @@ -706,35 +779,40 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 706 | .max() | 779 | .max() |
| 707 | .unwrap_or(origin); | 780 | .unwrap_or(origin); |
| 708 | let left = x(from); | 781 | let left = x(from); |
| 709 | - g.rects.push(Rect::new( | 782 | + // The wait starts when the last needed job ends. While that job runs, it starts now. |
| 710 | - "ci-gbar ci-wait", | 783 | + let following = job.needs.iter().any(|need| { |
| 711 | - left, | 784 | + jobs.iter().any(|other| { |
| 712 | - bar_y, | 785 | + other.name == *need |
| 713 | - track_end - left, | 786 | + && other.started.is_some() |
| 714 | - BAR_H, | 787 | + && other.finished.is_none() |
| 715 | - )); | 788 | + }) |
| 789 | + }); | ||
| 790 | + let mut wait = | ||
| 791 | + Rect::new("ci-gbar ci-wait", left, bar_y, track_end - left, BAR_H); | ||
| 792 | + if following { | ||
| 793 | + wait = wait.ticking("follow"); | ||
| 794 | + } | ||
| 795 | + g.rects.push(wait); | ||
| 716 | g.labels.push(Label { | 796 | g.labels.push(Label { |
| 717 | class: "ci-goff", | 797 | class: "ci-goff", |
| 718 | x: (left + 8).to_string(), | 798 | x: (left + 8).to_string(), |
| 719 | y: label_y, | 799 | y: label_y, |
| 720 | anchor: "start", | 800 | anchor: "start", |
| 721 | text: g::t(lang, K::Waiting).to_owned(), | 801 | text: g::t(lang, K::Waiting).to_owned(), |
| 802 | + follow: following.then(|| "8".to_owned()), | ||
| 803 | + ..Default::default() | ||
| 722 | }); | 804 | }); |
| 723 | } | 805 | } |
| 724 | JobState::Skipped | JobState::Cancelled => { | 806 | JobState::Skipped | JobState::Cancelled => { |
| 725 | - g.rects.push(Rect::new( | 807 | + g.rects |
| 726 | - "ci-gbar ci-wait", | 808 | + .push(Rect::new("ci-gbar ci-wait", TRACK_X, bar_y, TRACK_W, BAR_H)); |
| 727 | - TRACK_X, | ||
| 728 | - bar_y, | ||
| 729 | - TRACK_W, | ||
| 730 | - BAR_H, | ||
| 731 | - )); | ||
| 732 | g.labels.push(Label { | 809 | g.labels.push(Label { |
| 733 | class: "ci-goff", | 810 | class: "ci-goff", |
| 734 | x: (TRACK_X + 8).to_string(), | 811 | x: (TRACK_X + 8).to_string(), |
| 735 | y: label_y, | 812 | y: label_y, |
| 736 | anchor: "start", | 813 | anchor: "start", |
| 737 | text: state_text(lang, job.state.as_str()), | 814 | text: state_text(lang, job.state.as_str()), |
| 815 | + ..Default::default() | ||
| 738 | }); | 816 | }); |
| 739 | } | 817 | } |
| 740 | _ => {} | 818 | _ => {} |
| @@ -806,11 +884,7 @@ fn timing_of(job: &CiJob, runner: String, lang: Lang) -> Timing { | |||
| 806 | 884 | ||
| 807 | /// "test OOM" for a failed run: the first failed job's message, or its name and state. | 885 | /// "test OOM" for a failed run: the first failed job's message, or its name and state. |
| 808 | fn row_meta(run: &CiRun, jobs: &[Timing], actor: &str, lang: Lang) -> String { | 886 | fn row_meta(run: &CiRun, jobs: &[Timing], actor: &str, lang: Lang) -> String { |
| 809 | - let mut meta = format!( | 887 | + let mut meta = format!("#{} \u{b7} {}", run.number, short_oid(&run.commit_oid)); |
| 810 | - "#{} \u{b7} {}", | ||
| 811 | - run.number, | ||
| 812 | - short_oid(&run.commit_oid) | ||
| 813 | - ); | ||
| 814 | if !actor.is_empty() { | 888 | if !actor.is_empty() { |
| 815 | meta.push_str(&format!(" \u{b7} {actor}")); | 889 | meta.push_str(&format!(" \u{b7} {actor}")); |
| 816 | } | 890 | } |
| @@ -839,8 +913,7 @@ async fn log_last_lines(path: &Path) -> Vec<String> { | |||
| 839 | }; | 913 | }; |
| 840 | let start = len.saturating_sub(LOG_TAIL_BYTES); | 914 | let start = len.saturating_sub(LOG_TAIL_BYTES); |
| 841 | let mut buf = Vec::new(); | 915 | let mut buf = Vec::new(); |
| 842 | - if file.seek(SeekFrom::Start(start)).await.is_err() | 916 | + if file.seek(SeekFrom::Start(start)).await.is_err() || file.read_to_end(&mut buf).await.is_err() |
| 843 | - || file.read_to_end(&mut buf).await.is_err() | ||
| 844 | { | 917 | { |
| 845 | return Vec::new(); | 918 | return Vec::new(); |
| 846 | } | 919 | } |
| @@ -851,7 +924,10 @@ async fn log_last_lines(path: &Path) -> Vec<String> { | |||
| 851 | lines.remove(0); | 924 | lines.remove(0); |
| 852 | } | 925 | } |
| 853 | let skip = lines.len().saturating_sub(LOG_LINES); | 926 | let skip = lines.len().saturating_sub(LOG_LINES); |
| 854 | - lines[skip..].iter().map(|line| (*line).to_owned()).collect() | 927 | + lines[skip..] |
| 928 | + .iter() | ||
| 929 | + .map(|line| (*line).to_owned()) | ||
| 930 | + .collect() | ||
| 855 | } | 931 | } |
| 856 | 932 | ||
| 857 | /// Maps each user id in `ids` to a display name. A user that no longer exists shows as "deleted user". | 933 | /// Maps each user id in `ids` to a display name. A user that no longer exists shows as "deleted user". |
| @@ -926,7 +1002,9 @@ async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> { | |||
| 926 | let names = usernames( | 1002 | let names = usernames( |
| 927 | state, | 1003 | state, |
| 928 | lang, | 1004 | lang, |
| 929 | - runs.iter().chain(selected.iter()).map(|run| run.actor_id.as_str()), | 1005 | + runs.iter() |
| 1006 | + .chain(selected.iter()) | ||
| 1007 | + .map(|run| run.actor_id.as_str()), | ||
| 930 | ) | 1008 | ) |
| 931 | .await?; | 1009 | .await?; |
| 932 | // Commit subjects are the run titles. A commit that cannot be read leaves the trigger as the title. | 1010 | // Commit subjects are the run titles. A commit that cannot be read leaves the trigger as the title. |
| @@ -985,6 +1063,10 @@ async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> { | |||
| 985 | now, | 1063 | now, |
| 986 | run.state == RunState::Running, | 1064 | run.state == RunState::Running, |
| 987 | ), | 1065 | ), |
| 1066 | + since: (run.state == RunState::Running && run.finished_at.is_none()) | ||
| 1067 | + .then(|| origin_of(run, now).to_string()), | ||
| 1068 | + origin: origin_of(run, now).to_string(), | ||
| 1069 | + scale: scale.to_string(), | ||
| 988 | // Only a run that has started or finished has a duration. A queued run has none yet. | 1070 | // Only a run that has started or finished has a duration. A queued run has none yet. |
| 989 | duration: if run_finished(&run.state) || run.state == RunState::Running { | 1071 | duration: if run_finished(&run.state) || run.state == RunState::Running { |
| 990 | duration_text( | 1072 | duration_text( |
| @@ -1095,15 +1177,8 @@ async fn run_detail( | |||
| 1095 | now: i64, | 1177 | now: i64, |
| 1096 | ) -> Result<RunDetail> { | 1178 | ) -> Result<RunDetail> { |
| 1097 | let jobs = timings_of(state, &run.id, runners, lang).await?; | 1179 | let jobs = timings_of(state, &run.id, runners, lang).await?; |
| 1098 | - let gantt = (!jobs.is_empty()).then(|| { | 1180 | + let gantt = |
| 1099 | - gantt( | 1181 | + (!jobs.is_empty()).then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang)); |
| 1100 | - &jobs, | ||
| 1101 | - origin_of(run, now), | ||
| 1102 | - run_end(run, now), | ||
| 1103 | - now, | ||
| 1104 | - lang, | ||
| 1105 | - ) | ||
| 1106 | - }); | ||
| 1107 | let mut lines = Vec::with_capacity(jobs.len()); | 1182 | let mut lines = Vec::with_capacity(jobs.len()); |
| 1108 | for job in jobs.iter() { | 1183 | for job in jobs.iter() { |
| 1109 | let mut parts = Vec::new(); | 1184 | let mut parts = Vec::new(); |
| @@ -1121,6 +1196,9 @@ async fn run_detail( | |||
| 1121 | detail: parts.join(" \u{b7} "), | 1196 | detail: parts.join(" \u{b7} "), |
| 1122 | runner: job.runner.clone(), | 1197 | runner: job.runner.clone(), |
| 1123 | duration: job.duration.clone(), | 1198 | duration: job.duration.clone(), |
| 1199 | + since: (job.finished.is_none() && job.state == JobState::Running) | ||
| 1200 | + .then(|| job.started.map(|at| at.to_string())) | ||
| 1201 | + .flatten(), | ||
| 1124 | }); | 1202 | }); |
| 1125 | } | 1203 | } |
| 1126 | let focus = jobs | 1204 | let focus = jobs |
| @@ -1154,6 +1232,9 @@ async fn run_detail( | |||
| 1154 | Some(run.created_at.as_str()), | 1232 | Some(run.created_at.as_str()), |
| 1155 | run.finished_at.as_deref(), | 1233 | run.finished_at.as_deref(), |
| 1156 | ), | 1234 | ), |
| 1235 | + since: (!run_finished(&run.state) && run.finished_at.is_none()) | ||
| 1236 | + .then(|| unix_of(&run.created_at).map(|at| at.to_string())) | ||
| 1237 | + .flatten(), | ||
| 1157 | config_error: run.config_error.clone(), | 1238 | config_error: run.config_error.clone(), |
| 1158 | action_base: run_href(title, run.number), | 1239 | action_base: run_href(title, run.number), |
| 1159 | can_approve: header.writer_csrf.is_some() && run.state == RunState::WaitingApproval, | 1240 | can_approve: header.writer_csrf.is_some() && run.state == RunState::WaitingApproval, |
| @@ -1186,6 +1267,7 @@ async fn runs_body( | |||
| 1186 | older_href, | 1267 | older_href, |
| 1187 | page_label, | 1268 | page_label, |
| 1188 | } = list; | 1269 | } = list; |
| 1270 | + let (fm, fs) = duration_templates(lang); | ||
| 1189 | Ok(view! { | 1271 | Ok(view! { |
| 1190 | repo_head(head: head) | 1272 | repo_head(head: head) |
| 1191 | if let Some((text, is_error)) = notice { | 1273 | if let Some((text, is_error)) = notice { |
| @@ -1195,7 +1277,7 @@ async fn runs_body( | |||
| 1195 | <section class="card notice" role="status">(text)</section> | 1277 | <section class="card notice" role="status">(text)</section> |
| 1196 | } | 1278 | } |
| 1197 | } | 1279 | } |
| 1198 | - <div data-live=(live.as_deref()) class="ci-split"> | 1280 | + <div data-live=(live.as_deref()) class="ci-split" data-now=(now_unix().to_string()) data-fm=(fm.as_str()) data-fs=(fs.as_str())> |
| 1199 | <svg class="ci-defs" width="0" height="0" focusable="false" aria-hidden="true"> | 1281 | <svg class="ci-defs" width="0" height="0" focusable="false" aria-hidden="true"> |
| 1200 | <defs> | 1282 | <defs> |
| 1201 | <pattern id="ci-hatch" width="6" height="6" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"> | 1283 | <pattern id="ci-hatch" width="6" height="6" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"> |
| @@ -1253,12 +1335,12 @@ async fn runs_body( | |||
| 1253 | <a class="ci-row" href=(row.href.as_str()) aria-current=(row.current)> | 1335 | <a class="ci-row" href=(row.href.as_str()) aria-current=(row.current)> |
| 1254 | <span class="ci-row-title">(row.title.as_str())</span> | 1336 | <span class="ci-row-title">(row.title.as_str())</span> |
| 1255 | <span class="ci-row-line"> | 1337 | <span class="ci-row-line"> |
| 1256 | - <svg class="ci-bar" viewBox="0 0 1000 6" preserveAspectRatio="none" aria-hidden="true"> | 1338 | + <svg class="ci-bar" viewBox="0 0 1000 6" preserveAspectRatio="none" aria-hidden="true" data-origin=(row.origin.as_str()) data-scale=(row.scale.as_str())> |
| 1257 | for seg in row.bar.iter() { | 1339 | for seg in row.bar.iter() { |
| 1258 | - <rect class=(seg.class.as_str()) x=(seg.x.as_str()) y=(seg.y.as_str()) width=(seg.w.as_str()) height=(seg.h.as_str())/> | 1340 | + <rect class=(seg.class.as_str()) x=(seg.x.as_str()) y=(seg.y.as_str()) width=(seg.w.as_str()) height=(seg.h.as_str()) data-tick=(seg.tick.as_deref())/> |
| 1259 | } | 1341 | } |
| 1260 | </svg> | 1342 | </svg> |
| 1261 | - <span class="ci-row-dur">(row.duration.as_str())</span> | 1343 | + <span class="ci-row-dur" data-since=(row.since.as_deref())>(row.duration.as_str())</span> |
| 1262 | </span> | 1344 | </span> |
| 1263 | <span class="ci-row-meta">(row.meta.as_str())</span> | 1345 | <span class="ci-row-meta">(row.meta.as_str())</span> |
| 1264 | </a> | 1346 | </a> |
| @@ -1302,7 +1384,7 @@ async fn runs_body( | |||
| 1302 | } | 1384 | } |
| 1303 | " \u{b7} " (run.when.as_str()) | 1385 | " \u{b7} " (run.when.as_str()) |
| 1304 | if !run.duration.is_empty() { | 1386 | if !run.duration.is_empty() { |
| 1305 | - " \u{b7} " (run.duration.as_str()) | 1387 | + " \u{b7} " <span data-since=(run.since.as_deref())>(run.duration.as_str())</span> |
| 1306 | } | 1388 | } |
| 1307 | </span> | 1389 | </span> |
| 1308 | </p> | 1390 | </p> |
| @@ -1311,15 +1393,15 @@ async fn runs_body( | |||
| 1311 | } | 1393 | } |
| 1312 | if let Some(g) = run.gantt.as_ref() { | 1394 | if let Some(g) = run.gantt.as_ref() { |
| 1313 | <div class="ci-gantt-scroll"> | 1395 | <div class="ci-gantt-scroll"> |
| 1314 | - <svg class="ci-gantt" viewBox=(g.view_box.as_str()) role="img" aria-label=(g::t(lang, K::Timeline))> | 1396 | + <svg class="ci-gantt" viewBox=(g.view_box.as_str()) role="img" aria-label=(g::t(lang, K::Timeline)) data-origin=(g.origin.as_str()) data-len=(g.len.as_str()) data-live-gantt=(g.live.then_some("true"))> |
| 1315 | for r in g.rects.iter() { | 1397 | for r in g.rects.iter() { |
| 1316 | - <rect class=(r.class.as_str()) x=(r.x.as_str()) y=(r.y.as_str()) width=(r.w.as_str()) height=(r.h.as_str())/> | 1398 | + <rect class=(r.class.as_str()) x=(r.x.as_str()) y=(r.y.as_str()) width=(r.w.as_str()) height=(r.h.as_str()) data-tick=(r.tick.as_deref())/> |
| 1317 | } | 1399 | } |
| 1318 | for d in g.links.iter() { | 1400 | for d in g.links.iter() { |
| 1319 | <path class="ci-glink" d=(d.as_str())/> | 1401 | <path class="ci-glink" d=(d.as_str())/> |
| 1320 | } | 1402 | } |
| 1321 | for t in g.labels.iter() { | 1403 | for t in g.labels.iter() { |
| 1322 | - <text class=(t.class) x=(t.x.as_str()) y=(t.y.as_str()) text-anchor=(t.anchor)>(t.text.as_str())</text> | 1404 | + <text class=(t.class) x=(t.x.as_str()) y=(t.y.as_str()) text-anchor=(t.anchor) data-since=(t.since.as_deref()) data-pre=(t.pre.as_deref()) data-post=(t.post.as_deref()) data-follow=(t.follow.as_deref())>(t.text.as_str())</text> |
| 1323 | } | 1405 | } |
| 1324 | </svg> | 1406 | </svg> |
| 1325 | </div> | 1407 | </div> |
| @@ -1339,7 +1421,7 @@ async fn runs_body( | |||
| 1339 | } | 1421 | } |
| 1340 | </span> | 1422 | </span> |
| 1341 | <span class="ci-job-runner">(job.runner.as_str())</span> | 1423 | <span class="ci-job-runner">(job.runner.as_str())</span> |
| 1342 | - <span class="ci-job-dur">(job.duration.as_str())</span> | 1424 | + <span class="ci-job-dur" data-since=(job.since.as_deref())>(job.duration.as_str())</span> |
| 1343 | <span class="ci-chev" aria-hidden="true"></span> | 1425 | <span class="ci-chev" aria-hidden="true"></span> |
| 1344 | </a> | 1426 | </a> |
| 1345 | </li> | 1427 | </li> |
| @@ -1762,13 +1844,16 @@ mod tests { | |||
| 1762 | fn list_bars_share_the_page_scale() { | 1844 | fn list_bars_share_the_page_scale() { |
| 1763 | let jobs = [ | 1845 | let jobs = [ |
| 1764 | timing("test", JobState::Success, Some(0), Some(0), Some(2160)), | 1846 | timing("test", JobState::Success, Some(0), Some(0), Some(2160)), |
| 1765 | - timing("build", JobState::Failure, Some(2160), Some(2160), Some(4692)), | 1847 | + timing( |
| 1848 | + "build", | ||
| 1849 | + JobState::Failure, | ||
| 1850 | + Some(2160), | ||
| 1851 | + Some(2160), | ||
| 1852 | + Some(4692), | ||
| 1853 | + ), | ||
| 1766 | ]; | 1854 | ]; |
| 1767 | let bar = row_bar(&jobs, 0, 4692, 4692, false); | 1855 | let bar = row_bar(&jobs, 0, 4692, 4692, false); |
| 1768 | - let spans: Vec<(&str, &str)> = bar | 1856 | + let spans: Vec<(&str, &str)> = bar.iter().map(|r| (r.x.as_str(), r.w.as_str())).collect(); |
| 1769 | - .iter() | ||
| 1770 | - .map(|r| (r.x.as_str(), r.w.as_str())) | ||
| 1771 | - .collect(); | ||
| 1772 | assert_eq!(spans, vec![("0", "460"), ("460", "540")]); | 1857 | assert_eq!(spans, vec![("0", "460"), ("460", "540")]); |
| 1773 | assert_eq!(bar[1].class, "ci-seg ci-bad"); | 1858 | assert_eq!(bar[1].class, "ci-seg ci-bad"); |
| 1774 | // A running run adds the hatched rest of the scale after its jobs. | 1859 | // A running run adds the hatched rest of the scale after its jobs. |
| @@ -1801,7 +1886,13 @@ mod tests { | |||
| 1801 | fn timeline_boxes_sit_at_the_real_times() { | 1886 | fn timeline_boxes_sit_at_the_real_times() { |
| 1802 | // The run starts at 0. Test runs to 2160 seconds, then build starts and runs to 4692. | 1887 | // The run starts at 0. Test runs to 2160 seconds, then build starts and runs to 4692. |
| 1803 | let test = timing("test", JobState::Success, Some(0), Some(0), Some(2160)); | 1888 | let test = timing("test", JobState::Success, Some(0), Some(0), Some(2160)); |
| 1804 | - let mut build = timing("build", JobState::Success, Some(2160), Some(2160), Some(4692)); | 1889 | + let mut build = timing( |
| 1890 | + "build", | ||
| 1891 | + JobState::Success, | ||
| 1892 | + Some(2160), | ||
| 1893 | + Some(2160), | ||
| 1894 | + Some(4692), | ||
| 1895 | + ); | ||
| 1805 | build.needs = vec!["test".to_owned()]; | 1896 | build.needs = vec!["test".to_owned()]; |
| 1806 | let g = gantt(&[test, build], 0, Some(4692), 4692, Lang::En); | 1897 | let g = gantt(&[test, build], 0, Some(4692), 4692, Lang::En); |
| 1807 | assert_eq!(g.view_box, "0 0 640 104"); | 1898 | assert_eq!(g.view_box, "0 0 640 104"); |
| @@ -1838,7 +1929,10 @@ mod tests { | |||
| 1838 | "42m 9s".to_owned(), | 1929 | "42m 9s".to_owned(), |
| 1839 | ]; | 1930 | ]; |
| 1840 | assert_eq!(bar_text(400, &labels).as_deref(), Some(labels[0].as_str())); | 1931 | assert_eq!(bar_text(400, &labels).as_deref(), Some(labels[0].as_str())); |
| 1841 | - assert_eq!(bar_text(120, &labels).as_deref(), Some("build \u{b7} 42m 9s")); | 1932 | + assert_eq!( |
| 1933 | + bar_text(120, &labels).as_deref(), | ||
| 1934 | + Some("build \u{b7} 42m 9s") | ||
| 1935 | + ); | ||
| 1842 | assert_eq!(bar_text(40, &labels), None); | 1936 | assert_eq!(bar_text(40, &labels), None); |
| 1843 | } | 1937 | } |
| 1844 | 1938 | ||
crates/forge-web/src/pages/ci_tests.rsmodified+77 -1
| @@ -492,7 +492,10 @@ async fn run_list_is_live_on_page_one_only() { | |||
| 492 | Some(&cookie_for("tahinli-token")), | 492 | Some(&cookie_for("tahinli-token")), |
| 493 | ) | 493 | ) |
| 494 | .await; | 494 | .await; |
| 495 | - assert!(!run.text().contains("data-live="), "a run on page 2 is not live"); | 495 | + assert!( |
| 496 | + !run.text().contains("data-live="), | ||
| 497 | + "a run on page 2 is not live" | ||
| 498 | + ); | ||
| 496 | } | 499 | } |
| 497 | 500 | ||
| 498 | /// The href of the list row marked as current, from the markup of the runs page. | 501 | /// The href of the list row marked as current, from the markup of the runs page. |
| @@ -1317,3 +1320,76 @@ async fn badge_without_any_run_uses_the_label_or_build() { | |||
| 1317 | assert!(labelled.contains(">Nightly</text>"), "{labelled}"); | 1320 | assert!(labelled.contains(">Nightly</text>"), "{labelled}"); |
| 1318 | assert!(labelled.contains(">no status</text>")); | 1321 | assert!(labelled.contains(">no status</text>")); |
| 1319 | } | 1322 | } |
| 1323 | + | ||
| 1324 | +/// A running run carries what the client's local clock needs: the start of each duration that is | ||
| 1325 | +/// still counting, the growing boxes of the list bar and the timeline, and the server's clock. A | ||
| 1326 | +/// finished run carries none of it, so the ticker stops. | ||
| 1327 | +#[tokio::test] | ||
| 1328 | +async fn running_runs_carry_ticker_attributes_and_finished_ones_do_not() { | ||
| 1329 | + let dir = tempfile::tempdir().expect("tempdir"); | ||
| 1330 | + let fx = fixture(dir.path()).await; | ||
| 1331 | + run_with(&fx, &["test"], false).await; | ||
| 1332 | + let token = fx | ||
| 1333 | + .store | ||
| 1334 | + .create_registration_token(&fx.tahinli, 24) | ||
| 1335 | + .await | ||
| 1336 | + .expect("token"); | ||
| 1337 | + let (runner, _) = fx | ||
| 1338 | + .store | ||
| 1339 | + .register_runner(&token, "runner-1", &["linux".to_owned()]) | ||
| 1340 | + .await | ||
| 1341 | + .expect("runner"); | ||
| 1342 | + let (job, _, _) = fx | ||
| 1343 | + .store | ||
| 1344 | + .claim_job(&runner) | ||
| 1345 | + .await | ||
| 1346 | + .expect("claim") | ||
| 1347 | + .expect("a queued job"); | ||
| 1348 | + let cookie = cookie_for("tahinli-token"); | ||
| 1349 | + let html = get(&fx.app, RUN_BASE, Some(&cookie)) | ||
| 1350 | + .await | ||
| 1351 | + .text() | ||
| 1352 | + .to_owned(); | ||
| 1353 | + assert!( | ||
| 1354 | + html.contains("data-now=\""), | ||
| 1355 | + "the server clock is on the page" | ||
| 1356 | + ); | ||
| 1357 | + assert!( | ||
| 1358 | + html.contains("data-fm=\"{m}m {s}s\""), | ||
| 1359 | + "the duration format is on the page" | ||
| 1360 | + ); | ||
| 1361 | + assert!( | ||
| 1362 | + html.contains("class=\"ci-row-dur\" data-since=\""), | ||
| 1363 | + "the list duration counts" | ||
| 1364 | + ); | ||
| 1365 | + assert!(html.contains("data-tick=\"grow\""), "a running bar grows"); | ||
| 1366 | + assert!( | ||
| 1367 | + html.contains("data-tick=\"rest\""), | ||
| 1368 | + "the hatched remainder follows the clock" | ||
| 1369 | + ); | ||
| 1370 | + assert!( | ||
| 1371 | + html.contains("data-live-gantt=\"true\""), | ||
| 1372 | + "the timeline is live" | ||
| 1373 | + ); | ||
| 1374 | + assert!( | ||
| 1375 | + html.contains("class=\"ci-job-dur\" data-since=\""), | ||
| 1376 | + "the job duration counts" | ||
| 1377 | + ); | ||
| 1378 | + | ||
| 1379 | + fx.store | ||
| 1380 | + .finish_job(&job.id, JobState::Success, Some(0), None) | ||
| 1381 | + .await | ||
| 1382 | + .expect("finish"); | ||
| 1383 | + let html = get(&fx.app, RUN_BASE, Some(&cookie)) | ||
| 1384 | + .await | ||
| 1385 | + .text() | ||
| 1386 | + .to_owned(); | ||
| 1387 | + assert!( | ||
| 1388 | + !html.contains("data-since="), | ||
| 1389 | + "nothing counts once the run is done" | ||
| 1390 | + ); | ||
| 1391 | + assert!( | ||
| 1392 | + !html.contains("data-tick="), | ||
| 1393 | + "nothing grows once the run is done" | ||
| 1394 | + ); | ||
| 1395 | +} | ||