1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
//! Actions for Ambient CI.
//!
//! Actual action implementations are in the [`action_impl`](crate::action_impl) module.
//! Actions are divided into [pre-plan](PrePlanAction), [plan](UnsafeAction), and [post-plan](PostPlanAction) actions.
//! These are turned into [runnable actions](RunnableAction).
#![allow(clippy::result_large_err)]
use std::{
collections::HashMap,
ffi::OsString,
os::unix::ffi::OsStringExt,
path::{Path, PathBuf},
};
use clingwrap::runner::CommandError;
use serde::{Deserialize, Serialize};
use crate::{action_impl::*, envs::EnvVars, plan::RunnablePlan, runlog::RunLog};
/// A context for running an action.
///
/// The context holds state between actions getting executiong,
/// as well as configuration for a specific CI run. The context
/// is created at the start of a CI run and can be modified by
/// actions.
#[derive(Debug)]
pub struct Context<'a> {
envs: HashMap<OsString, OsString>,
source_dir: PathBuf,
deps_dir: PathBuf,
artifacts_dir: PathBuf,
// These environment variables will be carried over to the runnable plan
// that is given to the VM.
plan_envs: EnvVars,
#[allow(dead_code)]
runlog: &'a mut RunLog,
}
impl<'a> Context<'a> {
/// Create a new `Context`.
pub fn new(runlog: &'a mut RunLog) -> Self {
Self {
envs: HashMap::new(),
source_dir: PathBuf::default(),
deps_dir: PathBuf::default(),
artifacts_dir: PathBuf::default(),
plan_envs: EnvVars::default(),
runlog,
}
}
/// Return a mutable reference to the current run log.
pub fn runlog(&mut self) -> &mut RunLog {
self.runlog
}
/// Set environment variables from a [`RunnablePlan`].
pub fn set_envs_from_plan(&mut self, plan: &RunnablePlan) -> Result<(), ActionError> {
self.source_dir = plan
.source_dir()
.ok_or(ActionError::Missing("source_dir"))?
.into();
self.deps_dir = plan
.deps_dir()
.ok_or(ActionError::Missing("deps_dir"))?
.into();
self.artifacts_dir = plan
.artifacts_dir()
.ok_or(ActionError::Missing("artifacts_dir"))?
.into();
if let Some(path) = plan.cache_dir() {
self.set_env("CARGO_TARGET_DIR", &format!("{path}/cargo-target"));
}
if let Some(path) = plan.deps_dir() {
self.set_env("CARGO_HOME", path);
}
let path = std::env::var("PATH").unwrap_or("/bin".into());
self.set_env("PATH", &format!("/root/.cargo/bin:{path}"));
for (k, v) in plan.envs().iter() {
let k = OsString::from(k);
let v = OsString::from_vec(v.to_vec());
self.set_env(k, v);
}
Ok(())
}
/// Return environment variables meant to be carried over from pre-plan to plan.
pub fn plan_envs(&self) -> &EnvVars {
&self.plan_envs
}
/// Return all environment variables set in the context.
/// Note that this only incoludes the once explicitly set.
/// It does not include ones inherited when Ambient (`ambient-execute-plan`)
/// starts.
pub fn env(&self) -> Vec<(OsString, OsString)> {
self.envs
.iter()
.map(|(k, v)| (k.into(), v.into()))
.collect()
}
/// Set environment variable for execution of future actions.
pub fn set_env<S: Into<OsString>>(&mut self, name: S, value: S) {
self.envs.insert(name.into(), value.into());
}
/// Set environment variable that will be added to the runnable plan
/// for the VM. This only happens in pre-plan. This method is a NO-OP
/// for any other phase.
pub fn set_plan_env<S: Into<String>, T: Into<OsString>>(&mut self, name: S, value: T) {
let name = name.into();
let value = value.into();
self.plan_envs.set(name, value.as_encoded_bytes());
}
/// Return source directory for this context.
pub fn source_dir(&self) -> &Path {
&self.source_dir
}
/// Return dependencies directory for this context.
pub fn deps_dir(&self) -> &Path {
&self.deps_dir
}
/// Return artifacts directory for this context.
pub fn artifacts_dir(&self) -> &Path {
&self.artifacts_dir
}
}
/// A pair of URL and basename, for an item in a `http_get` action.
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct Pair {
/// URL where the file is.
pub url: String,
/// File in the depenendencies directory where to store the
/// downloaded file.
pub filename: PathBuf,
}
impl Pair {
/// Return the URL.
pub fn url(&self) -> &str {
&self.url
}
/// Return the filename.
pub fn filename(&self) -> &Path {
&self.filename
}
}
/// An action that is ready to be executed. These can be executed in any kind of
/// plan, including a runnable plan.
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[serde(tag = "action")]
#[serde(rename_all = "snake_case")]
pub enum RunnableAction {
/// A dummy action that does nothing. Useful for trouble-shooting.
Dummy(Dummy),
/// Print current working directory. Useful for trouble-shooting.
Pwd(Pwd),
/// Run `cargo fetch` in a safe and secure manner.
CargoFetch(CargoFetch),
/// Download files via HTTP.
HttpGet(HttpGet),
/// Download Debian packages and their dependencies.
DebGet(DebGet),
/// Install downloaded Debian packages.
DebInstall(DebInstall),
/// Download `npm` packages.
NpmGet(NpmGet),
/// Upload files via `rsync`.
Rsync(Rsync),
/// Upload built Debian packages.
Dput(Dput),
/// Create a directory.
Mkdir(Mkdir),
/// Create a tar archive from a directory.
TarCreate(TarCreate),
/// Extract a tar archive into a directory.
TarExtract(TarExtract),
/// Execute a shell script snippet with `bash`.
Shell(Shell),
/// Run `cargo fmt --check`.
CargoFmt(CargoFmt),
/// Run `cargo clippy`.
CargoClippy(CargoClippy),
/// Run `cargo deny`.
CargoDeny(CargoDeny),
/// Run `cargo doc`.
CargoDoc(CargoDoc),
/// Run `cargo build`.
CargoBuild(CargoBuild),
/// Run `cargo test`.
CargoTest(CargoTest),
/// Run `cargo install`.
CargoInstall(CargoInstall),
/// Build a Debian `deb` package.
Deb(Deb),
/// Execute a custom action.
Custom(Custom),
/// Set environment variables.
Setenv(Setenv),
/// Download a Rust toolchain into the `$DEPENDENCIES/rustup` directory.
Rustup(Rustup),
}
impl RunnableAction {
/// Name of the action.
pub fn name(&self) -> &'static str {
match self {
Self::Dummy(_) => "dummy",
Self::Pwd(_) => "pwd",
Self::CargoFetch(_) => "cargo_fetch",
Self::CargoFmt(_) => "cargo_fmt",
Self::CargoClippy(_) => "cargo_clippy",
Self::CargoDoc(_) => "cargo_doc",
Self::CargoDeny(_) => "cargo_deny",
Self::CargoBuild(_) => "cargo_build",
Self::CargoTest(_) => "cargo_test",
Self::CargoInstall(_) => "cargo_install",
Self::HttpGet(_) => "http_get",
Self::DebGet(_) => "deb_get",
Self::DebInstall(_) => "deb_install",
Self::NpmGet(_) => "npm_get",
Self::Rsync(_) => "rsync",
Self::Dput(_) => "dput",
Self::Mkdir(_) => "mkdir",
Self::TarCreate(_) => "tar_create",
Self::TarExtract(_) => "tar_extract",
Self::Shell(_) => "shell",
Self::Custom(_) => "custom",
Self::Deb(_) => "deb",
Self::Setenv(_) => "setenv",
Self::Rustup(_) => "rustup",
}
}
/// Summarize action: name and the most salient detals.
pub fn summary(&self) -> String {
let mut summary = self.name().to_string();
match self {
Self::Mkdir(mkdir) => summary.push_str(&format!(": {}", mkdir.pathname().display())),
Self::Shell(shell) => summary.push_str(&format!(": {}", shell.shell())),
Self::Custom(custom) => summary.push_str(&format!(": {}", custom.name)),
_ => (),
}
summary
}
/// Execute a runnable action.
pub fn execute(&self, context: &mut Context) -> Result<(), ActionError> {
match self {
Self::Dummy(x) => x.execute(context),
Self::Pwd(x) => x.execute(context),
Self::CargoFetch(x) => x.execute(context),
Self::HttpGet(x) => x.execute(context),
Self::DebGet(x) => x.execute(context),
Self::DebInstall(x) => x.execute(context),
Self::NpmGet(x) => x.execute(context),
Self::Rsync(x) => x.execute(context),
Self::Dput(x) => x.execute(context),
Self::Mkdir(x) => x.execute(context),
Self::TarCreate(x) => x.execute(context),
Self::TarExtract(x) => x.execute(context),
Self::Shell(x) => x.execute(context),
Self::CargoFmt(x) => x.execute(context),
Self::CargoClippy(x) => x.execute(context),
Self::CargoDeny(x) => x.execute(context),
Self::CargoDoc(x) => x.execute(context),
Self::CargoBuild(x) => x.execute(context),
Self::CargoTest(x) => x.execute(context),
Self::CargoInstall(x) => x.execute(context),
Self::Deb(x) => x.execute(context),
Self::Custom(x) => x.execute(context),
Self::Setenv(x) => x.execute(context),
Self::Rustup(x) => x.execute(context),
}
}
/// Create a runnable action from a pre-plan action.
pub fn from_pre_plan_action(action: &PrePlanAction) -> Self {
match action {
PrePlanAction::Dummy => Self::Dummy(Dummy),
PrePlanAction::Pwd => Self::Pwd(Pwd),
PrePlanAction::CargoFetch => Self::CargoFetch(CargoFetch),
PrePlanAction::HttpGet { items } => {
let items: Vec<Pair> = items.to_vec();
Self::HttpGet(HttpGet::new(items))
}
PrePlanAction::DebGet {
packages,
suite,
cert,
} => Self::DebGet(DebGet::new(suite, cert, packages)),
PrePlanAction::NpmGet => Self::NpmGet(NpmGet::default()),
PrePlanAction::Rustup {
channel,
target,
components,
profile,
} => Self::Rustup(Rustup::new(channel, target, components, profile)),
}
}
/// Create a runnable action from a post-plan action.
pub fn from_post_plan_action(
action: &PostPlanAction,
rsync_target: Option<&str>,
dput_target: Option<&str>,
) -> Self {
match action {
PostPlanAction::Dummy => Self::Dummy(Dummy),
PostPlanAction::Pwd => Self::Pwd(Pwd),
PostPlanAction::Rsync => {
Self::Rsync(Rsync::new(".", rsync_target.map(|s| s.to_string())))
}
PostPlanAction::Rsync2 => {
Self::Rsync(Rsync::new("rsync", rsync_target.map(|s| s.to_string())))
}
PostPlanAction::Dput => Self::Dput(Dput::new(".", dput_target.map(|s| s.into()))),
PostPlanAction::Dput2 => Self::Dput(Dput::new("debian", dput_target.map(|s| s.into()))),
}
}
/// Create a runnable action from a plan (or unsafe) action.
pub fn from_unsafe_action(action: &UnsafeAction) -> Self {
match action {
UnsafeAction::Mkdir { pathname } => Self::Mkdir(Mkdir::new(pathname.to_path_buf())),
UnsafeAction::TarCreate { archive, directory } => {
Self::TarCreate(TarCreate::new(archive.clone(), directory.clone()))
}
UnsafeAction::TarExtract { archive, directory } => {
Self::TarExtract(TarExtract::new(archive.clone(), directory.clone()))
}
UnsafeAction::Shell { shell } => Self::Shell(Shell::new(shell.clone())),
UnsafeAction::DebInstall => Self::DebInstall(DebInstall::default()),
UnsafeAction::CargoFmt => Self::CargoFmt(CargoFmt),
UnsafeAction::CargoClippy => Self::CargoClippy(CargoClippy),
UnsafeAction::CargoDeny => Self::CargoDeny(CargoDeny),
UnsafeAction::CargoDoc => Self::CargoDoc(CargoDoc),
UnsafeAction::CargoBuild => Self::CargoBuild(CargoBuild),
UnsafeAction::CargoTest => Self::CargoTest(CargoTest),
UnsafeAction::CargoInstall => Self::CargoInstall(CargoInstall),
UnsafeAction::Deb => Self::Deb(Deb::new(".")),
UnsafeAction::Deb2 => Self::Deb(Deb::new("debian")),
UnsafeAction::Custom(x) => Self::Custom(x.clone()),
UnsafeAction::Setenv(setenv) => Self::Setenv(setenv.clone()),
}
}
}
/// Actions that can be used in a pre-plan.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "action")]
#[serde(rename_all = "snake_case")]
pub enum PrePlanAction {
/// Do nothing. This is only really useful for testing pre-plans.
Dummy,
/// Write out the current working directory. This is only really
/// useful for troubleshooting.
Pwd,
/// Fetch Rust language crate dependencies using `cargo fetch`.
CargoFetch,
/// Download files from the given URLs, if they've changed or are
/// missing.
HttpGet {
/// List of URL/filename pairs to retrieve.
items: Vec<Pair>,
},
/// Download Debian packages and their dependencies.
DebGet {
/// List of packages to download. Dependencies are found automatically.
packages: Vec<String>,
/// Which suite (release) to use. Defaults to "stable".
suite: Option<String>,
/// Certificate (public key) for archive signing key. Defaults to the Debian trixie one.
cert: Option<String>,
},
/// Download `npm` packages listed in a package lock file.
NpmGet,
/// Install Rust toolchains and components with `rustup`.
Rustup {
/// Channel, defaults to `stable`.
channel: Option<String>,
/// Target platform for toolchain to install.
target: Option<String>,
/// Components to install with the toolchain.
components: Option<Vec<String>>,
/// Profile: `minimal`, `default`, or `complete` are currently
/// supported by `rustup`. Defaults to `minimal`.
profile: Option<String>,
},
}
impl PrePlanAction {
/// Names of all pre-plan actions.
pub fn names() -> &'static [&'static str] {
&["dummy", "pwd", "cargo_fetch"]
}
}
/// Actions that can be used in a post-plan.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "action")]
#[serde(rename_all = "snake_case")]
pub enum PostPlanAction {
/// Do nothing. This is only really useful for testing post-plans.
Dummy,
/// Write out the current working directory. This is only really
/// useful for troubleshooting.
Pwd,
/// Upload, with `rsync`, the artifacts directory to the server
/// configured for Ambient ([`Config::rsync_target`](crate::config::StoredConfig#structfield.rsync_target)).
Rsync,
/// Upload, with `rsync`, the `rsync` subdirectory of the artifacts
/// directory to the server configured for Ambient
/// ([`Config::rsync_target`](crate::config::StoredConfig#structfield.rsync_target)).
/// The difference with the `Rsync` variant is that only the `rsync`
/// subdirectory is uploaded.
Rsync2,
/// Upload, with `dput`, the Debian (`deb`) packages in the artifacts
/// directory to the server configured for Ambient
/// ([`Config::dput_target`](crate::config::StoredConfig#structfield.dput_target)).
Dput,
/// Upload, with `dput`, the Debian (`deb`) packages in the `debian`
/// subdirectory of the artifacts directory to the server configured
/// for Ambient
/// ([`Config::dput_target`](crate::config::StoredConfig#structfield.dput_target)).
/// The difference with the `Dput` variant is that only the `debian`
/// subdirectory is searched for packages.
Dput2,
}
impl PostPlanAction {
/// Return names of all post-plan actions.
pub fn names() -> &'static [&'static str] {
&["dummy", "pwd", "cargo_fetch", "rsync", "dput"]
}
}
/// Untrusted actions that are run in a virtual machine, where they can't
/// do any damage.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "action")]
#[serde(rename_all = "snake_case")]
pub enum UnsafeAction {
/// Create a directory if it doesn't exist.
Mkdir {
/// Path to directory.
pathname: PathBuf,
},
/// Create a tar archive from a directory.
/// This is meant to be used in a [`RunnablePlan`] to new cache or
/// artifacts.
TarCreate {
/// Location of the tar archive to be created.
archive: PathBuf,
/// Directory to package in a tar archive.
directory: PathBuf,
},
/// Extract a tar archive from a directory.
/// This is meant to be used in a [`RunnablePlan`] to extract
/// source code, dependencies, etc.
TarExtract {
/// Location of the tar archive to be extracted.
archive: PathBuf,
/// Directory where the archive is to be unpacked.
directory: PathBuf,
},
/// Execute a shell script snippet. It is run with `bash` with
/// `set -xeuo pipefail` to catch problems as early as possible.
Shell {
/// Shell snippet.
shell: String,
},
/// Install `deb` packages download by the `deb_get` pre-plan action.
/// Really, all packages in `/ci/deps/debian`.
DebInstall,
/// Check that Rust source code is formatted in the idiomatic way,
/// by running `cargo fmt --check`.
CargoFmt,
/// Check that Rust source code is correct and idiomatic, by
/// running `cargo clippy`. No warnings are allowed.
CargoClippy,
/// Check that Rust source code lacks dependencies, licenses, and
/// other things that are unwanted, by running `cargo deny`.
CargoDeny,
/// Format documentation from Rust source code, by running `cargo doc`.
CargoDoc,
/// Build a Rust project by running `cargo build`.
CargoBuild,
/// Run the test suite of a Rust project, by running `cargo test`.
CargoTest,
/// Build and install a Rust project by running `cargo install`.
/// The installed files go into the artifacts directory.
CargoInstall,
/// Build a Debian `deb` package. The built files go into the
/// artifacts directory.
Deb,
/// Build a Debian `deb` package. The built files go into the
/// `debian` subdirectory of the artifacts directory.
Deb2,
/// Run a custom Ambient action from the `.ambient` directory in
/// the root of the source tree.
Custom(Custom),
/// Set enviornment variables for later actions.
Setenv(Setenv),
}
impl UnsafeAction {
/// Names of all plan actions.
pub fn names() -> &'static [&'static str] {
&[
"mkdir",
"tar_create",
"tar_extract",
"shell",
"cargo_fmt",
"cargo_clippy",
"cargo_build",
"cargo_test",
"cargo_install",
"deb",
"custom",
]
}
/// Construct a `Mkdir` action.
pub fn mkdir<P: AsRef<Path>>(pathname: P) -> Self {
Self::Mkdir {
pathname: pathname.as_ref().into(),
}
}
/// Construct a `TarCreate` action.
pub fn tar_create<P: AsRef<Path>>(archive: P, directory: P) -> Self {
Self::TarCreate {
archive: archive.as_ref().into(),
directory: directory.as_ref().into(),
}
}
/// Construct a `TarExtract` action.
pub fn tar_extract<P: AsRef<Path>>(archive: P, directory: P) -> Self {
Self::TarExtract {
archive: archive.as_ref().into(),
directory: directory.as_ref().into(),
}
}
/// Construct a `Shell` action.
pub fn shell(shell: &str) -> Self {
Self::Shell {
shell: shell.into(),
}
}
}
/// Errors returned from handling actions.
#[derive(Debug, thiserror::Error)]
pub enum ActionError {
/// Problem in a Cargo action.
#[error("cargo action failed")]
Cargo(#[source] crate::action_impl::CargoError),
/// Problem in a HttpGet action.
#[error("http_get action failed")]
HttpGet(#[source] crate::action_impl::HttpGetError),
/// Problem in a Dput action.
#[error("dput action failed")]
Dput(#[source] crate::action_impl::DputError),
/// Problem in an Rsync action.
#[error("rsync action failed")]
Rsync(#[source] crate::action_impl::RsyncError),
/// Problem in a tar action.
#[error("tar action failed")]
Tar(#[source] crate::action_impl::TarError),
/// Problem in a custom action.
#[error("custom action failed")]
Custom(#[source] crate::action_impl::CustomError),
/// Problem in a pwd action.
#[error("pwd action failed")]
Pwd(#[source] crate::action_impl::PwdError),
/// Problem with `rustup` action.
#[error("rustup action failed")]
Rustup(#[source] crate::action_impl::RustupError),
/// Problem in an mkdir action.
#[error("failed to create directory")]
Mkdir(#[source] crate::action_impl::MkdirError),
/// Problem in a deb action.
#[error("deb action failed")]
Deb(#[source] crate::action_impl::DebError),
/// Probelm with `npm` action.
#[error("npm action failed")]
Npm(#[source] crate::action_impl::NpmError),
/// Can't execute a command.
#[error("failed to execute {0}")]
Execute(String, #[source] CommandError),
/// Internal error: can't spawn a program.
#[error("failed to invoke command: empty argv")]
SpawnNoArgv0,
/// Programming error: [`RunnablePlan`] is missing a field.
#[error("runnable plan does not have field {0} set")]
Missing(&'static str),
}
#[cfg(test)]
mod test {
use super::*;
use tempfile::tempdir;
fn plan() -> RunnablePlan {
let mut plan = RunnablePlan::default();
plan.set_cache_dir("/tmp");
plan.set_deps_dir("/tmp");
plan.set_source_dir("/tmp");
plan.set_artifacts_dir("/tmp");
plan
}
#[test]
fn mkdir_action() -> Result<(), Box<dyn std::error::Error>> {
let tmp = tempdir()?;
let path = tmp.path().join("testdir");
let action = RunnableAction::from_unsafe_action(&UnsafeAction::mkdir(&path));
let plan = plan();
let mut runlog = RunLog::default();
let mut context = Context::new(&mut runlog);
context.set_envs_from_plan(&plan)?;
assert!(!path.exists());
assert!(action.execute(&mut context).is_ok());
assert!(path.exists());
Ok(())
}
}