1 //! Helper script used by `.github/workflows/ci-cron-trigger.yml`
2
3 use std::process::Command;
4
main()5 fn main() {
6 let output = Command::new("git")
7 .arg("for-each-ref")
8 .arg("refs/remotes/origin")
9 .arg("--format")
10 .arg("%(refname)")
11 .output()
12 .unwrap();
13 assert!(output.status.success());
14 let mut releases = std::str::from_utf8(&output.stdout)
15 .unwrap()
16 .lines()
17 .filter_map(|l| l.strip_prefix("refs/remotes/origin/release-"))
18 .filter_map(|l| {
19 let mut parts = l.split('.');
20 let major = parts.next()?.parse::<u32>().ok()?;
21 let minor = parts.next()?.parse::<u32>().ok()?;
22 let patch = parts.next()?.parse::<u32>().ok()?;
23 Some((major, minor, patch))
24 })
25 .collect::<Vec<_>>();
26 releases.sort();
27
28 let mut to_trigger: Vec<(u32, u32, u32)> = Vec::new();
29 let mut iter = releases.iter().rev();
30
31 // Pick the latest 3 release branches to keep up-to-date. Although we
32 // only promise the last 2 are going to be released with security fixes when
33 // a new release branch is made that means there's one "pending" release
34 // branch and two "active" release branches. In that situation we want to
35 // update 3 branches. If there's no "pending" branch then we'll just be
36 // keeping some older branch's CI working, which shouldn't be too hard.
37 to_trigger.extend(iter.by_ref().take(3));
38
39 // We support two LTS channels 12 versions apart. If one is already included
40 // in the above set of 3 latest releases, however, then we're only picking
41 // one historical LTS release.
42 let mut lts_channels = 2;
43 if to_trigger.iter().any(|(major, _, _)| *major % 12 == 0) {
44 lts_channels -= 1;
45 }
46
47 // Look for LTS releases, defined by every-12-versions which are after v24.
48 to_trigger.extend(
49 iter.filter(|(major, _, _)| *major % 12 == 0 && *major > 20)
50 .take(lts_channels),
51 );
52
53 println!("{to_trigger:?}");
54
55 for (major, minor, patch) in to_trigger {
56 dbg!(major, minor, patch);
57 let status = Command::new("gh")
58 .arg("workflow")
59 .arg("run")
60 .arg("main.yml")
61 .arg("--ref")
62 .arg(format!("release-{major}.{minor}.{patch}"))
63 .status()
64 .unwrap();
65 assert!(status.success());
66 }
67 }
68