Skip to content

Commit a3c0858

Browse files
authored
Retention: keep the current baselines of a branch pull requests target, however old (release branches) (#223)
1 parent 46dbe21 commit a3c0858

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎app/src/domain/retention.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
//! - the newest completed CI build of each project and build name on the default branch,
99
//! - every build a kept build reads groups from (`build_groups.source_build_id`): their rows are the kept build's
1010
//! unchanged snapshots,
11-
//! - every current baseline: the newest baseline row per snapshot name on the default branch, and on each branch with
12-
//! a build in the window,
11+
//! - every current baseline: the newest baseline row per snapshot name on the default branch, on each branch with a
12+
//! build in the window, and on each branch a pull request has targeted (a build's `base_branch`, such as a release
13+
//! branch), however long ago: the next pull request into it compares with those, not an older build or the
14+
//! default branch's. A feature branch's baselines go 90 days after its last build,
1315
//! - the snapshots those builds compared against (`base_snapshot_id`),
1416
//! - renders those snapshots use, and any render made in the window or not finished,
1517
//! - variants' images, and any blob created in the window (an upload a build hasn't claimed yet),
@@ -111,6 +113,8 @@ async fn keep_sets(days: i32) -> laravel::Result<()> {
111113
WHERE bl.branch = p.default_branch OR EXISTS ( \
112114
SELECT 1 FROM builds b WHERE b.project_id = bl.project_id AND b.branch = bl.branch \
113115
AND b.created_at > now() - make_interval(days => {days})) \
116+
OR (bl.project_id, bl.branch) IN (SELECT DISTINCT project_id, base_branch FROM builds \
117+
WHERE base_branch IS NOT NULL) \
114118
ORDER BY bl.project_id, bl.build_name, bl.name, bl.platform, bl.environment, bl.branch, bl.id DESC \
115119
) current WHERE snapshot_id IS NOT NULL \
116120
ON CONFLICT DO NOTHING"

‎app/tests/retention.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,36 @@ async fn no_mark_outlives(app: Application) -> laravel::Result<()> {
343343
assert!(Blob::query().filter(Blob::sha256.eq(registered)).first().await?.is_some(), "registered just now: kept");
344344
Ok(())
345345
}
346+
347+
/// A release branch with no builds in the window keeps its current baselines while a pull request has ever targeted it:
348+
/// the next pull request into it compares with them, not an older build or the default branch's. A feature branch's go.
349+
#[laravel::test]
350+
async fn retention_keeps_the_baselines_of_a_branch_pull_requests_target(app: Application) -> laravel::Result<()> {
351+
fixtures::blob_store().await?;
352+
let token = project_token().await?;
353+
let release = build(&app, &token, "release-1", [255, 0, 0]).await;
354+
let feature = build(&app, &token, "old-feature", [0, 0, 255]).await;
355+
let pull = build(&app, &token, "fix-for-release", [0, 255, 0]).await;
356+
for b in [&release, &feature, &pull] {
357+
age(b).await?;
358+
}
359+
// Each branch's approved snapshot is its current baseline; the old pull request targeted release-1.
360+
for b in [&release, &feature] {
361+
let (project_id, build_id, branch, sha) = (b.project_id, b.id, b.branch.clone(), b.commit_sha.clone());
362+
db::query!(
363+
"INSERT INTO baselines (project_id, build_name, name, platform, environment, branch, commit_sha, build_id, \
364+
snapshot_id, approval, created_at) \
365+
SELECT {project_id}, 'default', name, platform, environment, {branch}, {sha}, {build_id}, id, 'approved', \
366+
now() - interval '200 days' FROM snapshots WHERE build_id = {build_id}"
367+
)
368+
.insert()
369+
.await?;
370+
}
371+
let pull_id = pull.id;
372+
db::query!("UPDATE builds SET base_branch = 'release-1', pr_number = 3 WHERE id = {pull_id}").update().await?;
373+
374+
retention::prune(None, retention::RETENTION_DAYS, false).await?;
375+
assert!(blob_of(&release).await.is_some(), "the release branch's baseline stays");
376+
assert!(blob_of(&feature).await.is_none(), "a feature branch's baseline goes with its last build");
377+
Ok(())
378+
}

0 commit comments

Comments
 (0)