From 1438be42319dcbaab662a286a3af8eb145b12269 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 30 Sep 2023 15:11:01 +0530 Subject: [PATCH] feat: make use of actions inputs --- package/action/src/download.rs | 26 +++++++++++++++++++++----- package/action/src/fmt.rs | 15 +++++---------- package/action/src/lib.rs | 6 +++--- package/action/src/main.rs | 9 +++++++-- package/action/src/types.rs | 6 +++--- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/package/action/src/download.rs b/package/action/src/download.rs index 599da59..0a08146 100644 --- a/package/action/src/download.rs +++ b/package/action/src/download.rs @@ -68,19 +68,35 @@ fn parse_release_data(data: &LuneReleaseData) -> LuneReleaseFetched { version, download, artifact_name, - raw: data.clone(), + raw: Some(data.clone()), } } -pub fn download_release() -> Result<(PathBuf, LuneReleaseFetched)> { +pub fn download_release(version: Option) -> Result<(PathBuf, LuneReleaseFetched)> { const TARGET: &str = "download::download_release"; tracing::info!(target: TARGET, "Initializing routine"); - let parsed_release_data = - parse_release_data(&GitHub::new(("filiptibell", "lune")).fetch_releases()?); + let parsed_release_data: LuneReleaseFetched; + + if let Some(ver) = version { + let artifact_name = format!("lune-{ver}-{}-{}.zip", env::consts::OS, env::consts::ARCH); + + parsed_release_data = LuneReleaseFetched { + version: ver.to_string(), + download: format!( + "https://github.com/filiptibell/lune/releases/download/v{ver}/{artifact_name}" + ), + artifact_name, + raw: None, + } + } else { + parsed_release_data = + parse_release_data(&GitHub::new(("filiptibell", "lune")).fetch_releases()?); + + tracing::info!(target: TARGET, "Received API resp and parsed release data"); + } - tracing::info!(target: TARGET, "Received API resp and parsed release data"); tracing::info!(target: TARGET, "Got lune {}", parsed_release_data.version); let fetcher = Fetcher::new(); diff --git a/package/action/src/fmt.rs b/package/action/src/fmt.rs index e92b572..536041b 100644 --- a/package/action/src/fmt.rs +++ b/package/action/src/fmt.rs @@ -1,12 +1,11 @@ +use colored::Colorize; use std::fmt; -use tracing_core::{Subscriber, Event, Level}; +use tracing_core::{Event, Level, Subscriber}; use tracing_subscriber::fmt::{ format::{self, FormatEvent, FormatFields}, - FmtContext, - FormattedFields, + FmtContext, FormattedFields, }; use tracing_subscriber::registry::LookupSpan; -use colored::Colorize; pub struct LogFormatter; @@ -21,7 +20,6 @@ where mut writer: format::Writer<'_>, event: &Event<'_>, ) -> fmt::Result { - let meta = event.metadata(); let scope = match meta.level() { @@ -47,10 +45,7 @@ where for span in scope.from_root() { write!(writer, "{}", span.name())?; let ext = span.extensions(); - let fields = &ext - .get::>() - .unwrap(); - + let fields = &ext.get::>().unwrap(); if !fields.is_empty() { write!(writer, "{{{}}}", fields)?; @@ -63,4 +58,4 @@ where writeln!(writer) } -} \ No newline at end of file +} diff --git a/package/action/src/lib.rs b/package/action/src/lib.rs index 7c5e7f6..66ea238 100644 --- a/package/action/src/lib.rs +++ b/package/action/src/lib.rs @@ -1,4 +1,4 @@ -pub mod types; -pub mod github; pub mod download; -pub mod fmt; \ No newline at end of file +pub mod fmt; +pub mod github; +pub mod types; diff --git a/package/action/src/main.rs b/package/action/src/main.rs index a8e7c04..fe037e3 100644 --- a/package/action/src/main.rs +++ b/package/action/src/main.rs @@ -1,14 +1,19 @@ use std::fs::File; +use actions_core as core; use setup_lune::{ download::{download_release, install_lune}, fmt::LogFormatter, }; -use actions_core as core; use tracing::Level; use tracing_unwrap::ResultExt; fn main() { + let version = match core::input("version") { + Ok(val) => Some(val), + Err(_) => None, + }; + if cfg!(debug_assertions) { better_panic::install(); } @@ -22,7 +27,7 @@ fn main() { .init(); let (zip_path, meta) = - download_release().expect_or_log("failed to download latest lune release"); + download_release(version).expect_or_log("failed to download latest lune release"); install_lune( File::open(&zip_path).expect( diff --git a/package/action/src/types.rs b/package/action/src/types.rs index adcaaac..71497a8 100644 --- a/package/action/src/types.rs +++ b/package/action/src/types.rs @@ -3,7 +3,7 @@ use serde::Deserialize; #[derive(Deserialize, Debug, Clone)] pub struct LuneReleaseData { pub name: String, - pub assets: Vec + pub assets: Vec, } #[derive(Deserialize, Debug, Clone)] @@ -17,5 +17,5 @@ pub struct LuneReleaseFetched { pub version: String, pub download: String, pub artifact_name: String, - pub raw: LuneReleaseData, -} \ No newline at end of file + pub raw: Option, +}