java/updater/src/main.rs

101 lines
3.1 KiB
Rust

use std::collections::BTreeMap;
use api::OutputReleases;
use color_eyre::eyre::{Context, Result};
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
use crate::api::AdoptiumAPI;
/// API Abstraction
pub mod api;
#[async_std::main]
async fn main() -> Result<()> {
color_eyre::install()?;
tracing_subscriber::registry()
.with(fmt::layer().pretty().with_writer(std::io::stderr))
.with(EnvFilter::from_default_env())
.init();
let mut output: BTreeMap<String, BTreeMap<String, OutputReleases>> = BTreeMap::new();
// Create the api instances
let adoptium = AdoptiumAPI::adoptium().context("Creating api")?;
let semeru = AdoptiumAPI::semeru().context("Creating api")?;
// Fill in x86_64-linux first
{
let x86_64 = output.entry("x86_64-linux".to_string()).or_default();
x86_64.insert(
"temurin".to_string(),
adoptium
.get_all("x64", "linux")
.await
.context("Failed getting x86_64 temurin releases")?,
);
x86_64.insert(
"semeru".to_string(),
semeru
.get_all("x64", "linux")
.await
.context("Failed getting x86_64 semeru releases")?,
);
}
// Then aarch64-linux
{
let aarch64 = output.entry("aarch64-linux".to_string()).or_default();
aarch64.insert(
"temurin".to_string(),
adoptium
.get_all("aarch64", "linux")
.await
.context("Failed getting aarch64 temurin releases")?,
);
aarch64.insert(
"semeru".to_string(),
semeru
.get_all("aarch64", "linux")
.await
.context("Failed getting aarch64 semeru releases")?,
);
}
// Then x86_64-darwin
{
let x86_64 = output.entry("x86_64-darwin".to_string()).or_default();
x86_64.insert(
"temurin".to_string(),
adoptium
.get_all("x64", "mac")
.await
.context("Failed getting x86_64-darwin temurin releases")?,
);
x86_64.insert(
"semeru".to_string(),
semeru
.get_all("x64", "mac")
.await
.context("Failed getting x86_64-darwin semeru releases")?,
);
}
// Then aarch64-darwin
{
let aarch64 = output.entry("aarch64-darwin".to_string()).or_default();
aarch64.insert(
"temurin".to_string(),
adoptium
.get_all("aarch64", "mac")
.await
.context("Failed getting aarch64-darwin temurin releases")?,
);
aarch64.insert(
"semeru".to_string(),
semeru
.get_all("aarch64", "mac")
.await
.context("Failed getting aarch64-darwin semeru releases")?,
);
}
let output = serde_json::to_string_pretty(&output).context("Failed to serialize output")?;
println!("{output}");
Ok(())
}