Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/src/domain/retention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
//! - the newest completed CI build of each project and build name on the default branch,
//! - every build a kept build reads groups from (`build_groups.source_build_id`): their rows are the kept build's
//! unchanged snapshots,
//! - every current baseline: the newest baseline row per snapshot name on the default branch, and on each branch with
//! a build in the window,
//! - every current baseline: the newest baseline row per snapshot name on the default branch, on each branch with a
//! build in the window, and on each branch a pull request has targeted (a build's `base_branch`, such as a release
//! branch), however long ago: the next pull request into it compares with those, not an older build or the
//! default branch's. A feature branch's baselines go 90 days after its last build,
//! - the snapshots those builds compared against (`base_snapshot_id`),
//! - renders those snapshots use, and any render made in the window or not finished,
//! - variants' images, and any blob created in the window (an upload a build hasn't claimed yet),
Expand Down Expand Up @@ -111,6 +113,8 @@ async fn keep_sets(days: i32) -> laravel::Result<()> {
WHERE bl.branch = p.default_branch OR EXISTS ( \
SELECT 1 FROM builds b WHERE b.project_id = bl.project_id AND b.branch = bl.branch \
AND b.created_at > now() - make_interval(days => {days})) \
OR (bl.project_id, bl.branch) IN (SELECT DISTINCT project_id, base_branch FROM builds \
WHERE base_branch IS NOT NULL) \
ORDER BY bl.project_id, bl.build_name, bl.name, bl.platform, bl.environment, bl.branch, bl.id DESC \
) current WHERE snapshot_id IS NOT NULL \
ON CONFLICT DO NOTHING"
Expand Down
33 changes: 33 additions & 0 deletions app/tests/retention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,36 @@ async fn no_mark_outlives(app: Application) -> laravel::Result<()> {
assert!(Blob::query().filter(Blob::sha256.eq(registered)).first().await?.is_some(), "registered just now: kept");
Ok(())
}

/// A release branch with no builds in the window keeps its current baselines while a pull request has ever targeted it:
/// the next pull request into it compares with them, not an older build or the default branch's. A feature branch's go.
#[laravel::test]
async fn retention_keeps_the_baselines_of_a_branch_pull_requests_target(app: Application) -> laravel::Result<()> {
fixtures::blob_store().await?;
let token = project_token().await?;
let release = build(&app, &token, "release-1", [255, 0, 0]).await;
let feature = build(&app, &token, "old-feature", [0, 0, 255]).await;
let pull = build(&app, &token, "fix-for-release", [0, 255, 0]).await;
for b in [&release, &feature, &pull] {
age(b).await?;
}
// Each branch's approved snapshot is its current baseline; the old pull request targeted release-1.
for b in [&release, &feature] {
let (project_id, build_id, branch, sha) = (b.project_id, b.id, b.branch.clone(), b.commit_sha.clone());
db::query!(
"INSERT INTO baselines (project_id, build_name, name, platform, environment, branch, commit_sha, build_id, \
snapshot_id, approval, created_at) \
SELECT {project_id}, 'default', name, platform, environment, {branch}, {sha}, {build_id}, id, 'approved', \
now() - interval '200 days' FROM snapshots WHERE build_id = {build_id}"
)
.insert()
.await?;
}
let pull_id = pull.id;
db::query!("UPDATE builds SET base_branch = 'release-1', pr_number = 3 WHERE id = {pull_id}").update().await?;

retention::prune(None, retention::RETENTION_DAYS, false).await?;
assert!(blob_of(&release).await.is_some(), "the release branch's baseline stays");
assert!(blob_of(&feature).await.is_none(), "a feature branch's baseline goes with its last build");
Ok(())
}
Loading