From 8cf92ce8edd29efaf0a2bb1b53f1788ee2d8b309 Mon Sep 17 00:00:00 2001 From: Ariady Putra Date: Thu, 17 Aug 2023 02:19:54 +0700 Subject: [PATCH] `aiken new`: Try to get the latest tag of stdlib --- crates/aiken-project/Cargo.toml | 2 +- crates/aiken-project/src/config.rs | 7 +++++-- crates/aiken-project/src/github/mod.rs | 1 + crates/aiken-project/src/github/repo.rs | 22 ++++++++++++++++++++++ crates/aiken-project/src/lib.rs | 1 + 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 crates/aiken-project/src/github/mod.rs create mode 100644 crates/aiken-project/src/github/repo.rs diff --git a/crates/aiken-project/Cargo.toml b/crates/aiken-project/Cargo.toml index bbc41684..f9a443d9 100644 --- a/crates/aiken-project/Cargo.toml +++ b/crates/aiken-project/Cargo.toml @@ -32,7 +32,7 @@ petgraph = "0.6.3" pulldown-cmark = { version = "0.9.2", default-features = false } rayon = "1.7.0" regex = "1.7.1" -reqwest = "0.11.14" +reqwest = { version = "0.11.14", features = ["blocking", "json"] } serde = { version = "1.0.152", features = ["derive"] } serde_json = { version = "1.0.94", features = ["preserve_order"] } strip-ansi-escapes = "0.1.1" diff --git a/crates/aiken-project/src/config.rs b/crates/aiken-project/src/config.rs index ac09d8b0..916adda1 100644 --- a/crates/aiken-project/src/config.rs +++ b/crates/aiken-project/src/config.rs @@ -1,4 +1,4 @@ -use crate::{package_name::PackageName, paths, Error}; +use crate::{github::repo::LatestRelease, package_name::PackageName, paths, Error}; use aiken_lang::ast::Span; use miette::NamedSource; use serde::{Deserialize, Serialize}; @@ -65,7 +65,10 @@ impl Config { owner: "aiken-lang".to_string(), repo: "stdlib".to_string(), }, - version: "1.5.0".to_string(), + version: match LatestRelease::of("aiken-lang/stdlib") { + Ok(stdlib) => stdlib.tag_name, + _ => "1.5.0".to_string(), + }, source: Platform::Github, }], } diff --git a/crates/aiken-project/src/github/mod.rs b/crates/aiken-project/src/github/mod.rs new file mode 100644 index 00000000..c426b23e --- /dev/null +++ b/crates/aiken-project/src/github/mod.rs @@ -0,0 +1 @@ +pub mod repo; diff --git a/crates/aiken-project/src/github/repo.rs b/crates/aiken-project/src/github/repo.rs new file mode 100644 index 00000000..e96c5110 --- /dev/null +++ b/crates/aiken-project/src/github/repo.rs @@ -0,0 +1,22 @@ +use reqwest::{blocking::Client, header::USER_AGENT, Error}; +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct LatestRelease { + pub tag_name: String, +} + +impl LatestRelease { + pub fn of>(repo: Repo) -> Result { + Ok({ + Client::new() + .get(format!( + "https://api.github.com/repos/{}/releases/latest", + repo.as_ref() + )) + .header(USER_AGENT, "aiken") + .send()? + .json::()? + }) + } +} diff --git a/crates/aiken-project/src/lib.rs b/crates/aiken-project/src/lib.rs index 1d1cd62b..72711b0d 100644 --- a/crates/aiken-project/src/lib.rs +++ b/crates/aiken-project/src/lib.rs @@ -4,6 +4,7 @@ pub mod deps; pub mod docs; pub mod error; pub mod format; +pub mod github; pub mod module; pub mod options; pub mod package_name;