microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
flowey/flowey_lib_common/src/ado_task_npm_authenticate.rs
63lines · modecode
| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | |
| 3 | //! ADO Task Wrapper: `npmAuthenticate@0` |
| 4 | |
| 5 | use flowey::node::prelude::*; |
| 6 | |
| 7 | flowey_request! { |
| 8 | pub enum Request { |
| 9 | /// Register a `.npmrc` file which includes authentication info |
| 10 | UsingNpmrc(ReadVar<PathBuf>), |
| 11 | /// Ensure authentication has been performed |
| 12 | Done(WriteVar<SideEffect>), |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | new_flow_node!(struct Node); |
| 17 | |
| 18 | impl FlowNode for Node { |
| 19 | type Request = Request; |
| 20 | |
| 21 | fn imports(_ctx: &mut ImportCtx<'_>) {} |
| 22 | |
| 23 | fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> { |
| 24 | let mut npmrcs = Vec::new(); |
| 25 | let mut done = Vec::new(); |
| 26 | |
| 27 | for req in requests { |
| 28 | match req { |
| 29 | Request::UsingNpmrc(v) => npmrcs.push(v), |
| 30 | Request::Done(v) => done.push(v), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | let did_run = npmrcs |
| 35 | .into_iter() |
| 36 | .map(|npmrc| { |
| 37 | let npmrc = npmrc.map(ctx, |x| x.display().to_string()); |
| 38 | let (did_run, claim_did_run) = ctx.new_var(); |
| 39 | ctx.emit_ado_step("Authenticate npm", move |ctx| { |
| 40 | claim_did_run.claim(ctx); |
| 41 | let npmrc = npmrc.claim(ctx); |
| 42 | move |rt| { |
| 43 | let npmrc = rt.get_var(npmrc); |
| 44 | let npmrc = npmrc.as_raw_var_name(); |
| 45 | |
| 46 | format!( |
| 47 | r#" |
| 48 | - task: npmAuthenticate@0 |
| 49 | inputs: |
| 50 | workingFile: $({npmrc}) |
| 51 | "# |
| 52 | ) |
| 53 | } |
| 54 | }); |
| 55 | did_run |
| 56 | }) |
| 57 | .collect::<Vec<_>>(); |
| 58 | |
| 59 | ctx.emit_side_effect_step(did_run, done); |
| 60 | |
| 61 | Ok(()) |
| 62 | } |
| 63 | } |
| 64 | |