-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial support for listing test artifacts
- Loading branch information
1 parent
742b6bd
commit 5ec59a2
Showing
13 changed files
with
848 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use leptos::*; | ||
use leptos_router::*; | ||
|
||
use crate::components::list::*; | ||
|
||
#[derive(Debug, Clone)] | ||
#[allow(dead_code)] | ||
struct UndeclaredOutput { | ||
pub name: String, | ||
pub size: String, | ||
pub kind: String, | ||
pub uri: String, | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
#[component] | ||
pub fn TestArtifactList() -> impl IntoView { | ||
let test_run = expect_context::<Memo<Option<state::TestRun>>>(); | ||
let manifest = create_local_resource( | ||
move || test_run.with(|test_run| test_run.as_ref().map(|test_run| test_run.files.clone())), | ||
move |files| async move { | ||
let files = files?; | ||
let uri = files.get("test.outputs_manifest__MANIFEST")?.uri.clone(); | ||
let zip_uri = &files.get("test.outputs__outputs.zip")?.uri; | ||
crate::routes::test::get_artifact(uri) | ||
.await | ||
.ok() | ||
.as_ref() | ||
.and_then(|v| { | ||
let manifest = String::from_utf8_lossy(v); | ||
let lines = manifest.split('\n').collect::<Vec<_>>(); | ||
let mut out = vec![]; | ||
for l in lines { | ||
if l.is_empty() { | ||
continue; | ||
} | ||
let items = l.split('\t').collect::<Vec<_>>(); | ||
let name = items.first()?; | ||
let size = items.get(1)?; | ||
let kind = items.get(2)?; | ||
out.push(UndeclaredOutput { | ||
name: name.to_string(), | ||
size: size.to_string(), | ||
kind: kind.to_string(), | ||
uri: zip_uri.clone(), | ||
}); | ||
} | ||
if out.is_empty() { | ||
return None; | ||
} | ||
Some(out) | ||
}) | ||
}, | ||
); | ||
|
||
view! { | ||
<Suspense> | ||
{move || match manifest.with(|manifest| manifest.as_ref().map(|o| o.is_some())) { | ||
Some(true) => { | ||
view! { | ||
<h1 class="font-bold text-lg">Undeclared Outputs</h1> | ||
<List> | ||
<For | ||
each=move || { | ||
manifest.with(|manifest| manifest.clone().flatten().unwrap()) | ||
} | ||
|
||
key=move |r| r.name.clone() | ||
children=move |r| { | ||
let query = format!( | ||
"../artifact?{}", | ||
url_escape::encode_query( | ||
&format!("uri={}&zip={}", r.uri, r.name), | ||
), | ||
); | ||
view! { | ||
<ListItem hide=Signal::derive(|| false)> | ||
<A href=query> | ||
{format!("{} -- ({} bytes)", r.name, r.size)} | ||
</A> | ||
</ListItem> | ||
} | ||
} | ||
/> | ||
|
||
</List> | ||
} | ||
.into_view() | ||
} | ||
_ => view! {}.into_view(), | ||
}} | ||
|
||
</Suspense> | ||
|
||
<h1 class="font-bold text-lg">Artifacts</h1> | ||
<List> | ||
<For | ||
each=move || { | ||
test_run | ||
.with(|test_run| { | ||
test_run.as_ref().map(|tr| tr.files.clone()).unwrap_or_default() | ||
}) | ||
} | ||
|
||
key=move |r| r.1.uri.clone() | ||
children=move |r| { | ||
let query = format!( | ||
"../artifact?{}", | ||
url_escape::encode_query(&format!("uri={}", r.1.uri)), | ||
); | ||
view! { | ||
<ListItem hide=Signal::derive(|| false)> | ||
<A href=query>{r.0.clone()}</A> | ||
</ListItem> | ||
} | ||
} | ||
/> | ||
|
||
</List> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod empty; | |
pub mod invocation; | ||
pub mod summary; | ||
pub mod test; | ||
pub mod artifact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::io::{Cursor, prelude::Read}; | ||
|
||
use leptos::*; | ||
use leptos_router::*; | ||
|
||
use crate::components::shellout::ShellOut; | ||
|
||
#[derive(PartialEq, Params, Debug, Clone)] | ||
struct ArtifactParams { | ||
uri: Option<String>, | ||
zip: Option<String>, | ||
} | ||
|
||
fn stringify(e: impl std::fmt::Debug) -> String { | ||
format!("{e:#?}") | ||
} | ||
|
||
#[component] | ||
pub fn Artifact() -> impl IntoView { | ||
let params = use_query::<ArtifactParams>(); | ||
let artifact = create_local_resource(move || params.get(), | ||
move |params| async move { | ||
let uri = params.as_ref().map_err(stringify)?.uri.clone().ok_or("missing params".to_string())?; | ||
let zip = params.as_ref().map_err(stringify)?.zip.as_ref(); | ||
let bytes = crate::routes::test::get_artifact(uri).await.map_err(stringify)?; | ||
if let Some(zip) = zip { | ||
let cur = Cursor::new(bytes); | ||
let mut arc = zip::ZipArchive::new(cur).map_err(stringify)?; | ||
let mut file = arc.by_name(zip).map_err(stringify)?; | ||
let mut out = "".to_string(); | ||
file.read_to_string(&mut out).map_err(stringify)?; | ||
log::info!("{}", out); | ||
return Ok::<String, String>(out); | ||
} | ||
Ok(String::from_utf8_lossy(&bytes).to_string()) | ||
}); | ||
view! { | ||
<div class="h-[80vh] flex items-start justify-start justify-items-center overflow-auto overflow-x-auto"> | ||
<Suspense fallback=move || view! { <div>Loading...</div> }> | ||
<ShellOut text=match artifact.get() { | ||
Some(Ok(t)) => t, | ||
Some(Err(t)) => t, | ||
None => "RIP".into(), | ||
}/> | ||
</Suspense> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.