diff --git a/.forge/ci.toml b/.forge/ci.toml index 7da85a7..36073a7 100644 --- a/.forge/ci.toml +++ b/.forge/ci.toml @@ -12,9 +12,6 @@ push = ["main"] pull_request = true manual = true tags = ["v*"] -# Each push to main cancels the older runs still building, so pushes in quick succession do not pile -# heavy Rust compiles onto the runner at once. -cancel_superseded = true [jobs.test] image = "docker.io/library/rust:1" diff --git a/crates/forge-ci/src/config.rs b/crates/forge-ci/src/config.rs index d960852..3036dbe 100644 --- a/crates/forge-ci/src/config.rs +++ b/crates/forge-ci/src/config.rs @@ -150,7 +150,7 @@ pub struct Triggers { pub pull_request: bool, /// Defaults to `true`. pub manual: bool, - /// Defaults to `false`. When set, a push to a branch cancels the queued and running runs of + /// Defaults to `true`. A push to a branch cancels the queued and running runs of /// older commits on that branch. pub cancel_superseded: bool, /// 5-field cron expressions in UTC, e.g. `"0 3 * * *"`. The server queues a run of the default @@ -165,7 +165,7 @@ impl Default for Triggers { tags: Vec::new(), pull_request: false, manual: true, - cancel_superseded: false, + cancel_superseded: true, schedule: Vec::new(), } } @@ -1019,15 +1019,26 @@ artifacts = ["target/release/forge"] } #[test] - fn cancel_superseded_is_opt_in() { + fn cancel_superseded_defaults_to_on() { let cfg = parse_config(&job_toml("")).unwrap(); - assert!(!cfg.on.cancel_superseded); + assert!(cfg.on.cancel_superseded); let cfg = parse_config(&format!("[on]\ncancel_superseded = true\n{}", job_toml(""))).unwrap(); assert!(cfg.on.cancel_superseded); assert!(cfg.warnings.is_empty(), "{:?}", cfg.warnings); } + #[test] + fn cancel_superseded_can_be_turned_off() { + let cfg = parse_config(&format!( + "[on]\ncancel_superseded = false\n{}", + job_toml("") + )) + .unwrap(); + assert!(!cfg.on.cancel_superseded); + assert!(cfg.warnings.is_empty(), "{:?}", cfg.warnings); + } + #[test] fn manual_can_be_disabled() { let cfg = parse_config(&format!("[on]\nmanual = false\n{}", job_toml(""))).unwrap(); diff --git a/crates/forge-web/src/ci/schedule.rs b/crates/forge-web/src/ci/schedule.rs index dd9b74a..95f368b 100644 --- a/crates/forge-web/src/ci/schedule.rs +++ b/crates/forge-web/src/ci/schedule.rs @@ -1147,10 +1147,27 @@ run = "make" } #[tokio::test] - async fn older_runs_are_kept_without_the_key() { + async fn a_newer_push_cancels_older_live_runs_by_default() { let fx = fixture().await; push(&fx, &[(CONFIG_PATH, CONFIG_ONE_JOB)], "refs/heads/main").await; push(&fx, &[("a.txt", "a")], "refs/heads/main").await; + let first = fx + .state + .store + .run_by_number(&fx.repo.id, 1) + .await + .unwrap() + .unwrap(); + assert_eq!(first.state, RunState::Cancelled); + } + + #[tokio::test] + async fn older_runs_are_kept_when_cancel_superseded_is_false() { + let fx = fixture().await; + let config = + CONFIG_SUPERSEDE.replace("cancel_superseded = true", "cancel_superseded = false"); + push(&fx, &[(CONFIG_PATH, &config)], "refs/heads/main").await; + push(&fx, &[("a.txt", "a")], "refs/heads/main").await; let first = fx .state .store diff --git a/docs/ci.md b/docs/ci.md index 9e6e59d..66746e4 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -37,7 +37,7 @@ page and a `ci/config` status set to `error`. | `tags` | array of string | `[]` | Tag globs. A push of a matching `refs/tags/*` starts a run. | | `pull_request` | bool | `false` | Start a run when a pull request is opened, updated or reopened. The config is read at the **head** commit. | | `manual` | bool | `true` | Writers can start a run on an existing branch from the CI tab. | -| `cancel_superseded` | bool | `false` | A push to a branch cancels the queued and running runs for older commits on that branch (see [Superseded runs](#superseded-runs)). | +| `cancel_superseded` | bool | `true` | A push to a branch cancels the queued and running runs for older commits on that branch (see [Superseded runs](#superseded-runs)). | | `schedule` | array of string | `[]` | Cron expressions (5 fields, UTC). See [Scheduled runs](#scheduled-runs). Max 8. | ### `[jobs.]` @@ -182,11 +182,11 @@ is published and no self-update happens. A long `build` does not keep compiling ### Superseded runs -With `[on] cancel_superseded = true`, a push to a branch cancels the runs that are still queued or running for +By default (`[on] cancel_superseded = true`), a push to a branch cancels the runs that are still queued or running for older commits of the **same branch** when its own run is created. Queued and blocked jobs become `cancelled` at once and running jobs are told to stop through their heartbeat, as with the run's Cancel button. Only runs that were started by a push are cancelled: manual, tag and pull request runs are left alone, and so are runs -that have already finished. The key is read from the new commit's `ci.toml`, and it is off by default. +that have already finished. The key is read from the new commit's `ci.toml`, and it is on by default. Set `cancel_superseded = false` to keep every run. ### Re-running