Skip to content

Commit

Permalink
feat(main): add json for kube version (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu authored Dec 29, 2024
1 parent 6e092f0 commit e56d8e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ anyhow = "1.0.95"
reqwest = "0.12.9"
pulldown-cmark = "0.12.2"
serde_json = "1.0"
linked-hash-map = "0.5.6"
[build-dependencies]
reqwest = "0.12.5"
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
anyhow = "1.0.95"
pulldown-cmark = "0.12.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
linked-hash-map = "0.5"
[profile.release]
lto = true
strip = true
Expand Down
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pulldown_cmark::HeadingLevel::H1;
use pulldown_cmark::{Event, Options, Parser, Tag};
#[allow(clippy::single_component_path_imports)]
use reqwest;
use serde_json as json;
use std::collections::BTreeMap;
use std::fs::File;

#[tokio::main]
Expand All @@ -12,7 +12,7 @@ async fn main() -> anyhow::Result<(), Error> {
"1.16", "1.17", "1.18", "1.19", "1.20", "1.21", "1.22", "1.23", "1.24", "1.25", "1.26",
"1.27", "1.28", "1.29", "1.30", "1.31",
];
let mut versions = Vec::new();
let mut versions = BTreeMap::new();
for version in _support_versions {
let url = format!(
"https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/CHANGELOG/CHANGELOG-{}.md",
Expand All @@ -23,10 +23,10 @@ async fn main() -> anyhow::Result<(), Error> {
let body = resp.text().await?;
let h1 = parse_md(&body)?;
println!("cargo:warning=fetch version is {:?}", h1);
versions.push(h1);
versions.insert(version.to_string(), h1);
}
let file = File::create("files/kube_versions.json")?;
json::to_writer(&file, &versions)?;
serde_json::to_writer_pretty(file, &versions)?;
Ok(())
}
#[allow(clippy::redundant_guards)]
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ async fn main() -> anyhow::Result<()> {

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

#[test]
fn test_file() -> anyhow::Result<()> {
let asset = super::Asset::get("kube_versions.json").unwrap();
let s = serde_json::from_slice::<Vec<Vec<String>>>(&asset.data)?;
for v in s {
assert_ne!(v.len(), 0);
let s = serde_json::from_slice::<BTreeMap<String, Vec<String>>>(&asset.data)?;
for (_key, value) in s {
assert_ne!(value.len(), 0);
}
Ok(())
}
Expand Down

0 comments on commit e56d8e8

Please sign in to comment.