branches: link to Hydra for development branches

Previously, we linked to Hydra jobs for channel updates, but not to
Hydra jobsets for development branches.  Hopefully having both isn't
too confusing, and clicking on a branch name takes people where they'd
expect.
This commit is contained in:
Alyssa Ross 2023-10-28 13:15:03 +02:00
parent e6cafedb0d
commit 6036801dc4
No known key found for this signature in database
GPG key ID: F9DBED4859B271C0

View file

@ -1,5 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> // SPDX-FileCopyrightText: 2021, 2023 Alyssa Ross <hi@alyssa.is>
// SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net> // SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net>
use std::borrow::Cow; use std::borrow::Cow;
@ -23,6 +23,25 @@ const NEXT_BRANCH_TABLE: [(&str, &str); 12] = [
(r"\Astaging-((2[1-9]|[3-90].)\.\d{2})\z", "staging-next-$1"), (r"\Astaging-((2[1-9]|[3-90].)\.\d{2})\z", "staging-next-$1"),
]; ];
const BRANCH_HYDRA_LINK_TABLE: [(&str, &str); 5] = [
(r"\Apython-updates\z", "nixpkgs/python-updates"),
(r"\Astaging-next\z", "nixpkgs/staging-next"),
// There's no staging-next-21.11 for some reason.
(
r"\Astaging-next-([013-9]\d\.\d{2}|2(1\.05|[2-90]\.\d{2}))\z",
"nixpkgs/staging-next-$1",
),
(r"\Ahaskell-updates\z", "nixpkgs/haskell-updates"),
(r"\Amaster\z", "nixpkgs/trunk"),
];
const CHANNEL_HYDRA_LINK_TABLE: [(&str, &str); 4] = [
(r"\Anixpkgs-unstable\z", "nixpkgs/trunk/unstable"),
(r"\Anixos-unstable-small\z", "nixos/unstable-small/tested"),
(r"\Anixos-unstable\z", "nixos/trunk-combined/tested"),
(r"\Anixos-(\d.*)\z", "nixos/release-$1/tested"),
];
static BRANCH_NEXTS: Lazy<BTreeMap<&str, Vec<&str>>> = Lazy::new(|| { static BRANCH_NEXTS: Lazy<BTreeMap<&str, Vec<&str>>> = Lazy::new(|| {
NEXT_BRANCH_TABLE NEXT_BRANCH_TABLE
.iter() .iter()
@ -60,13 +79,6 @@ pub fn next_branches(branch: &str) -> Vec<Cow<str>> {
.collect() .collect()
} }
const BRANCH_HYDRA_LINK_TABLE: [(&str, &str); 4] = [
(r"\Anixpkgs-unstable\z", "nixpkgs/trunk/unstable"),
(r"\Anixos-unstable-small\z", "nixos/unstable-small/tested"),
(r"\Anixos-unstable\z", "nixos/trunk-combined/tested"),
(r"\Anixos-(\d.*)\z", "nixos/release-$1/tested"),
];
static BRANCH_HYDRA_LINK_PATTERNS: Lazy<Vec<Regex>> = Lazy::new(|| { static BRANCH_HYDRA_LINK_PATTERNS: Lazy<Vec<Regex>> = Lazy::new(|| {
BRANCH_HYDRA_LINKS BRANCH_HYDRA_LINKS
.keys() .keys()
@ -76,17 +88,23 @@ static BRANCH_HYDRA_LINK_PATTERNS: Lazy<Vec<Regex>> = Lazy::new(|| {
.collect() .collect()
}); });
static BRANCH_HYDRA_LINKS: Lazy<BTreeMap<&str, &str>> = Lazy::new(|| { static BRANCH_HYDRA_LINKS: Lazy<BTreeMap<&str, String>> = Lazy::new(|| {
BRANCH_HYDRA_LINK_TABLE let branch_links = BRANCH_HYDRA_LINK_TABLE.iter().map(|(pattern, jobset)| {
.iter() (
.fold(BTreeMap::new(), |mut map, (pattern, next)| { *pattern,
// TODO throw an error when this does not return None? format!("https://hydra.nixos.org/jobset/{jobset}#tabs-jobs"),
map.insert(pattern, next); )
map });
}) let channel_links = CHANNEL_HYDRA_LINK_TABLE.iter().map(|(pattern, job)| {
(
*pattern,
format!("https://hydra.nixos.org/job/{job}#tabs-constituents"),
)
});
branch_links.chain(channel_links).collect()
}); });
static BRANCH_HYDRA_LINKS_BY_INDEX: Lazy<Vec<&str>> = static BRANCH_HYDRA_LINKS_BY_INDEX: Lazy<Vec<String>> =
Lazy::new(|| BRANCH_HYDRA_LINKS.values().cloned().collect()); Lazy::new(|| BRANCH_HYDRA_LINKS.values().cloned().collect());
static BRANCH_HYDRA_LINK_REGEXES: Lazy<RegexSet> = static BRANCH_HYDRA_LINK_REGEXES: Lazy<RegexSet> =
@ -101,8 +119,7 @@ pub fn branch_hydra_link(branch: &str) -> Option<String> {
let regex = BRANCH_HYDRA_LINK_PATTERNS.get(index).unwrap(); let regex = BRANCH_HYDRA_LINK_PATTERNS.get(index).unwrap();
BRANCH_HYDRA_LINKS_BY_INDEX BRANCH_HYDRA_LINKS_BY_INDEX
.get(index) .get(index)
.map(move |link| regex.replace(branch, *link)) .map(move |link| regex.replace(branch, link).to_string())
.map(move |l| format!("https://hydra.nixos.org/job/{}#tabs-constituents", l))
}) })
} }
@ -116,6 +133,16 @@ mod tests {
assert_eq!(res, vec!["staging"]); assert_eq!(res, vec!["staging"]);
} }
#[test]
fn staging_next() {
let branch = "staging-next";
let res = next_branches(branch);
assert_eq!(res, vec!["master"]);
let link = branch_hydra_link(branch);
let expected = "https://hydra.nixos.org/jobset/nixpkgs/staging-next#tabs-jobs";
assert_eq!(link.unwrap(), expected);
}
#[test] #[test]
fn staging_18_03() { fn staging_18_03() {
let branch = "staging-18.03"; let branch = "staging-18.03";
@ -151,8 +178,40 @@ mod tests {
#[test] #[test]
fn staging_next_21_05() { fn staging_next_21_05() {
let res = next_branches("staging-next-21.05"); let branch = "staging-next-21.05";
let res = next_branches(branch);
assert_eq!(res, vec!["release-21.05"]); assert_eq!(res, vec!["release-21.05"]);
let link = branch_hydra_link(branch);
let expected = "https://hydra.nixos.org/jobset/nixpkgs/staging-next-21.05#tabs-jobs";
assert_eq!(link.unwrap(), expected);
}
#[test]
fn staging_next_21_11() {
let branch = "staging-next-21.11";
let next = next_branches(branch);
assert_eq!(next, vec!["release-21.11"]);
assert!(branch_hydra_link(branch).is_none());
}
#[test]
fn staging_next_22_05() {
let branch = "staging-next-22.05";
let next = next_branches(branch);
assert_eq!(next, vec!["release-22.05"]);
let link = branch_hydra_link(branch);
let expected = "https://hydra.nixos.org/jobset/nixpkgs/staging-next-22.05#tabs-jobs";
assert_eq!(link.unwrap(), expected);
}
#[test]
fn staging_next_30_05() {
let branch = "staging-next-30.05";
let next = next_branches(branch);
assert_eq!(next, vec!["release-30.05"]);
let link = branch_hydra_link(branch);
let expected = "https://hydra.nixos.org/jobset/nixpkgs/staging-next-30.05#tabs-jobs";
assert_eq!(link.unwrap(), expected);
} }
#[test] #[test]
@ -162,6 +221,16 @@ mod tests {
assert_eq!(next, vec!["master"]); assert_eq!(next, vec!["master"]);
} }
#[test]
fn master() {
let branch = "master";
let next = next_branches(branch);
assert_eq!(next, vec!["nixpkgs-unstable", "nixos-unstable-small"]);
let link = branch_hydra_link(branch);
let expected = "https://hydra.nixos.org/jobset/nixpkgs/trunk#tabs-jobs";
assert_eq!(link.unwrap(), expected);
}
#[test] #[test]
fn release_20_09() { fn release_20_09() {
let res = next_branches("release-20.09"); let res = next_branches("release-20.09");