shrub_rs/models/
task.rs

1//! An Evergreen task is a single unit of work that Evergreen performs. Tasks are frequently
2//! mapped to test suites, but can task be used for other purposes (like builds or linting).
3//!
4//! Tasks are build from a list of commands that are either
5//! [built-in evergreen commands](https://github.com/evergreen-ci/evergreen/wiki/Project-Commands)
6//! or
7//! [functions](https://github.com/evergreen-ci/evergreen/wiki/Project-Configuration-Files#functions)
8//! unique to the landscape.
9use crate::models::commands::EvgCommand;
10use serde::{Deserialize, Serialize};
11
12/// Description of a depedency for a task.
13#[derive(Serialize, Deserialize, Debug, Clone)]
14pub struct TaskDependency {
15    /// Name of task that needs to be run.
16    pub name: String,
17    /// Build variant where dependent task is run.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub variant: Option<String>,
20}
21
22/// Reference to a task that is being added to a build variant.
23#[derive(Serialize, Deserialize, Debug, Clone)]
24pub struct TaskRef {
25    /// Name of task.
26    pub name: String,
27    /// List of other tasks that need to be completed before this is done.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub depends_on: Option<Vec<TaskDependency>>,
30    /// List of distros that task should be run on.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub distros: Option<Vec<String>>,
33    /// Should task be scheduled when created.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub activate: Option<bool>,
36}
37
38/// Definition of an Evergreen task.
39#[derive(Serialize, Deserialize, Debug, Clone)]
40pub struct EvgTask {
41    /// Name of task being defined.
42    pub name: String,
43    /// List of command that make up the task.
44    pub commands: Option<Vec<EvgCommand>>,
45    /// List of other tasks that need to be completed before this is done.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub depends_on: Option<Vec<TaskDependency>>,
48    /// How long this task can run before timing out (in seconds).
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub exec_timeout_secs: Option<u64>,
51    /// List of tags describing this task.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub tags: Option<Vec<String>>,
54    /// Describe if this patch should be runnable in patch builds.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub patchable: Option<bool>,
57    /// Describe if previously skipped versions of this task should be run on failure.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub stepback: Option<bool>,
60}
61
62impl EvgTask {
63    /// Get a reference of this task to include in a build variant.
64    ///
65    /// * `distros`: List of distros this task should run on.
66    pub fn get_reference(&self, distros: Option<Vec<String>>, activate: Option<bool>) -> TaskRef {
67        TaskRef {
68            name: self.name.clone(),
69            depends_on: None,
70            distros,
71            activate,
72        }
73    }
74}
75
76impl Default for EvgTask {
77    fn default() -> Self {
78        EvgTask {
79            name: "".to_string(),
80            commands: Some(vec![]),
81            depends_on: None,
82            exec_timeout_secs: None,
83            tags: None,
84            patchable: None,
85            stepback: None,
86        }
87    }
88}