flowey_lib_common/
ado_task_publish_test_results.rs1use flowey::node::prelude::*;
7
8#[derive(Serialize, Deserialize)]
9pub enum AdoTestResultsFormat {
10 JUnit,
11 NUnit,
12 VSTest,
13 XUnit,
14 CTest,
15}
16
17impl std::fmt::Display for AdoTestResultsFormat {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 AdoTestResultsFormat::JUnit => write!(f, "JUnit"),
21 AdoTestResultsFormat::NUnit => write!(f, "NUnit"),
22 AdoTestResultsFormat::VSTest => write!(f, "VSTest"),
23 AdoTestResultsFormat::XUnit => write!(f, "XUnit"),
24 AdoTestResultsFormat::CTest => write!(f, "CTest"),
25 }
26 }
27}
28
29flowey_request! {
30 pub struct Request {
31 pub step_name: String,
32 pub format: AdoTestResultsFormat,
33 pub results_file: ReadVar<PathBuf>,
34 pub test_title: String,
35 pub condition: Option<ReadVar<bool>>,
36 pub done: WriteVar<SideEffect>,
37 }
38}
39
40new_flow_node!(struct Node);
41
42impl FlowNode for Node {
43 type Request = Request;
44
45 fn imports(_ctx: &mut ImportCtx<'_>) {}
46
47 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
48 for Request {
49 step_name,
50 format,
51 results_file,
52 test_title,
53 condition,
54 done,
55 } in requests
56 {
57 let results_file = results_file.map(ctx, |f| {
58 f.absolute().expect("invalid path").display().to_string()
59 });
60 ctx.emit_ado_step_with_condition_optional(step_name, condition, |ctx| {
61 done.claim(ctx);
62 let results_file = results_file.claim(ctx);
63 move |rt| {
64 let results_file = rt.get_var(results_file).as_raw_var_name();
65 format!(
66 r#"
67 - task: PublishTestResults@2
68 inputs:
69 testResultsFormat: '{format}'
70 testResultsFiles: '$({results_file})'
71 testRunTitle: '{test_title}'
72 "#
73 )
74 }
75 });
76 }
77
78 Ok(())
79 }
80}