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