forge
Explore
Log in

Don't you dare go Hollow

Cancel superseded push runs by default

Browse files at this commit

0d7e1e129a21346bba25d4b5c7ccac08cb31710eAhmet Kaan GümüşParent: 43c3d3a
  • ci
    • cancel superseded push runs by default
Show full message
👷 ci: cancel superseded push runs by default
.forge/ci.tomlmodified+0 -3
@@ -12,9 +12,6 @@ push = ["main"]
12 pull_request = true12 pull_request = true
13 manual = true13 manual = true
14 tags = ["v*"]14 tags = ["v*"]
15-# Each push to main cancels the older runs still building, so pushes in quick succession do not pile
16-# heavy Rust compiles onto the runner at once.
17-cancel_superseded = true
18 15
19 [jobs.test]16 [jobs.test]
20 image = "docker.io/library/rust:1"17 image = "docker.io/library/rust:1"
crates/forge-ci/src/config.rsmodified+15 -4
@@ -150,7 +150,7 @@ pub struct Triggers {
150 pub pull_request: bool,150 pub pull_request: bool,
151 /// Defaults to `true`.151 /// Defaults to `true`.
152 pub manual: bool,152 pub manual: bool,
153- /// Defaults to `false`. When set, a push to a branch cancels the queued and running runs of153+ /// Defaults to `true`. A push to a branch cancels the queued and running runs of
154 /// older commits on that branch.154 /// older commits on that branch.
155 pub cancel_superseded: bool,155 pub cancel_superseded: bool,
156 /// 5-field cron expressions in UTC, e.g. `"0 3 * * *"`. The server queues a run of the default156 /// 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 {
165 tags: Vec::new(),165 tags: Vec::new(),
166 pull_request: false,166 pull_request: false,
167 manual: true,167 manual: true,
168- cancel_superseded: false,168+ cancel_superseded: true,
169 schedule: Vec::new(),169 schedule: Vec::new(),
170 }170 }
171 }171 }
@@ -1019,15 +1019,26 @@ artifacts = ["target/release/forge"]
1019 }1019 }
1020 1020
1021 #[test]1021 #[test]
1022- fn cancel_superseded_is_opt_in() {1022+ fn cancel_superseded_defaults_to_on() {
1023 let cfg = parse_config(&job_toml("")).unwrap();1023 let cfg = parse_config(&job_toml("")).unwrap();
1024- assert!(!cfg.on.cancel_superseded);1024+ assert!(cfg.on.cancel_superseded);
1025 let cfg =1025 let cfg =
1026 parse_config(&format!("[on]\ncancel_superseded = true\n{}", job_toml(""))).unwrap();1026 parse_config(&format!("[on]\ncancel_superseded = true\n{}", job_toml(""))).unwrap();
1027 assert!(cfg.on.cancel_superseded);1027 assert!(cfg.on.cancel_superseded);
1028 assert!(cfg.warnings.is_empty(), "{:?}", cfg.warnings);1028 assert!(cfg.warnings.is_empty(), "{:?}", cfg.warnings);
1029 }1029 }
1030 1030
1031+ #[test]
1032+ fn cancel_superseded_can_be_turned_off() {
1033+ let cfg = parse_config(&format!(
1034+ "[on]\ncancel_superseded = false\n{}",
1035+ job_toml("")
1036+ ))
1037+ .unwrap();
1038+ assert!(!cfg.on.cancel_superseded);
1039+ assert!(cfg.warnings.is_empty(), "{:?}", cfg.warnings);
1040+ }
1041+
1031 #[test]1042 #[test]
1032 fn manual_can_be_disabled() {1043 fn manual_can_be_disabled() {
1033 let cfg = parse_config(&format!("[on]\nmanual = false\n{}", job_toml(""))).unwrap();1044 let cfg = parse_config(&format!("[on]\nmanual = false\n{}", job_toml(""))).unwrap();
crates/forge-web/src/ci/schedule.rsmodified+18 -1
@@ -1147,10 +1147,27 @@ run = "make"
1147 }1147 }
1148 1148
1149 #[tokio::test]1149 #[tokio::test]
1150- async fn older_runs_are_kept_without_the_key() {1150+ async fn a_newer_push_cancels_older_live_runs_by_default() {
1151 let fx = fixture().await;1151 let fx = fixture().await;
1152 push(&fx, &[(CONFIG_PATH, CONFIG_ONE_JOB)], "refs/heads/main").await;1152 push(&fx, &[(CONFIG_PATH, CONFIG_ONE_JOB)], "refs/heads/main").await;
1153 push(&fx, &[("a.txt", "a")], "refs/heads/main").await;1153 push(&fx, &[("a.txt", "a")], "refs/heads/main").await;
1154+ let first = fx
1155+ .state
1156+ .store
1157+ .run_by_number(&fx.repo.id, 1)
1158+ .await
1159+ .unwrap()
1160+ .unwrap();
1161+ assert_eq!(first.state, RunState::Cancelled);
1162+ }
1163+
1164+ #[tokio::test]
1165+ async fn older_runs_are_kept_when_cancel_superseded_is_false() {
1166+ let fx = fixture().await;
1167+ let config =
1168+ CONFIG_SUPERSEDE.replace("cancel_superseded = true", "cancel_superseded = false");
1169+ push(&fx, &[(CONFIG_PATH, &config)], "refs/heads/main").await;
1170+ push(&fx, &[("a.txt", "a")], "refs/heads/main").await;
1154 let first = fx1171 let first = fx
1155 .state1172 .state
1156 .store1173 .store
docs/ci.mdmodified+3 -3
@@ -37,7 +37,7 @@ page and a `ci/config` status set to `error`.
37 | `tags` | array of string | `[]` | Tag globs. A push of a matching `refs/tags/*` starts a run. |37 | `tags` | array of string | `[]` | Tag globs. A push of a matching `refs/tags/*` starts a run. |
38 | `pull_request` | bool | `false` | Start a run when a pull request is opened, updated or reopened. The config is read at the **head** commit. |38 | `pull_request` | bool | `false` | Start a run when a pull request is opened, updated or reopened. The config is read at the **head** commit. |
39 | `manual` | bool | `true` | Writers can start a run on an existing branch from the CI tab. |39 | `manual` | bool | `true` | Writers can start a run on an existing branch from the CI tab. |
40-| `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)). |40+| `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)). |
41 | `schedule` | array of string | `[]` | Cron expressions (5 fields, UTC). See [Scheduled runs](#scheduled-runs). Max 8. |41 | `schedule` | array of string | `[]` | Cron expressions (5 fields, UTC). See [Scheduled runs](#scheduled-runs). Max 8. |
42 42
43 ### `[jobs.<name>]`43 ### `[jobs.<name>]`
@@ -182,11 +182,11 @@ is published and no self-update happens. A long `build` does not keep compiling
182 182
183 ### Superseded runs183 ### Superseded runs
184 184
185-With `[on] cancel_superseded = true`, a push to a branch cancels the runs that are still queued or running for185+By default (`[on] cancel_superseded = true`), a push to a branch cancels the runs that are still queued or running for
186 older commits of the **same branch** when its own run is created. Queued and blocked jobs become `cancelled`186 older commits of the **same branch** when its own run is created. Queued and blocked jobs become `cancelled`
187 at once and running jobs are told to stop through their heartbeat, as with the run's Cancel button. Only runs187 at once and running jobs are told to stop through their heartbeat, as with the run's Cancel button. Only runs
188 that were started by a push are cancelled: manual, tag and pull request runs are left alone, and so are runs188 that were started by a push are cancelled: manual, tag and pull request runs are left alone, and so are runs
189-that have already finished. The key is read from the new commit's `ci.toml`, and it is off by default.189+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.
190 190
191 ### Re-running191 ### Re-running
192 192