Skip to content

Commit 5d8fbc6

Browse files
committed
Merge branch 'unstable' into stable
2 parents d9f0670 + d25d352 commit 5d8fbc6

File tree

13 files changed

+96
-16
lines changed

13 files changed

+96
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "deployer"
3-
version = "1.5.0-1"
3+
version = "1.5.0-2"
44
edition = "2024"
55

66
[dependencies]
@@ -22,6 +22,7 @@ nix = { optional = true, version = "0.29", features = ["signal", "user"] }
2222
notify = "8.0"
2323
regex = "1.11"
2424
russh = { optional = true, version = "0.49" }
25+
semver = "1.0"
2526
serde = { version = "1.0", features = ["derive"] }
2627
serde_json = "1.0"
2728
serde_yaml = { git = "https://github.com/markcda/serde-yaml.git", tag = "0.9.36" }

TODO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# `deployer`'s TODO list
22

33
- [ ] TUI for editing containered & Ansible options for Pipelines
4+
- [ ] Replace complete `RemoteHost` definitions from `ansible_opts` for their shortnames
5+
- [ ] Add `deployer cd` command to change current directory to one of run directories
6+
- [ ] Make `deployer export` command:
7+
1. [ ] for exporting Pipelines to `bash` scripts
8+
2. [ ] for exporting (and importing with merging) Actions & Pipelines Registries
9+
3. [ ] for exporting Pipelines to CI (GitHub Actions, GitLab CI, Jenkins (? maybe ?)) configurations
10+
- [x] Add `--skip N` argument to skip N Actions inside selected Pipelines, if you exactly know that they have no need to re-run after changes
11+
- [x] Add `--no-clear` argument to disable screen clear on `run`/`watch`

src/cmd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ pub struct RunArgs {
270270
/// Run in specified folder
271271
#[arg(short('o'), long)]
272272
pub run_at: Option<PathBuf>,
273+
/// Skip N Actions inside selected Pipelines
274+
#[arg(short('p'), long)]
275+
pub skip: Option<usize>,
273276

274277
/// Run remotely on specified hosts
275278
#[arg(short('R'), long, value_delimiter(','))]
@@ -291,4 +294,7 @@ pub struct RunArgs {
291294
/// Don't pipe I/O channels
292295
#[arg(short('t'), long)]
293296
pub no_pipe: bool,
297+
/// Don't clear terminal
298+
#[arg(short('k'), long)]
299+
pub no_clear: bool,
294300
}

src/containered.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async fn run_simple(env: &RunEnvironment<'_>, bash_c: String) -> anyhow::Result<
6868
.execute(&RunEnvironment {
6969
no_pipe: true,
7070
daemons: env.daemons.clone(),
71+
skipper: env.skipper.clone(),
7172
..(*env)
7273
})
7374
.await?

src/entities.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ pub mod placements;
1616
pub mod programming_languages;
1717
pub mod remote_host;
1818
pub mod requirements;
19+
pub mod skipper;
1920
pub mod targets;
2021
pub mod variables;

src/entities/environment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::entities::observe_executor::ObserveClient;
1515
use crate::entities::placements::Placement;
1616
#[cfg(feature = "ssh-remotes")]
1717
use crate::entities::remote_host::RemoteHost;
18+
use crate::entities::skipper::Skipper;
1819

1920
/// Run environment.
2021
pub struct RunEnvironment<'a> {
@@ -60,4 +61,6 @@ pub struct RunEnvironment<'a> {
6061
pub daemons: Daemons,
6162
/// Observe Actions executor client.
6263
pub observe_cli: &'a Option<ObserveClient>,
64+
/// Skipper to count Actions to skip (see `--skip` option for `deployer run/watch`).
65+
pub skipper: Skipper,
6366
}

src/entities/info.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,14 @@ impl Serialize for Info {
117117

118118
static SHORT_NAME_VALIDATOR: LazyLock<Regex> = LazyLock::new(|| Regex::new("^[a-zA-Z_0-9-_]*$").unwrap());
119119

120-
static VERSION_VALIDATOR: LazyLock<Regex> = LazyLock::new(|| {
121-
Regex::new(r#"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"#).unwrap()
122-
});
123-
124120
/// Validates the short name.
125121
pub fn validate_short_name(short_name: &str) -> bool {
126122
SHORT_NAME_VALIDATOR.is_match(short_name)
127123
}
128124

129125
/// Validates the version.
130126
pub fn validate_version(version: &str) -> bool {
131-
if !VERSION_VALIDATOR.is_match(version) {
127+
if semver::Version::parse(version).is_err() {
132128
log(format!(
133129
"Version `{version}` is invalid! You should specify `SemVer 2.0` version."
134130
));

src/entities/observe_executor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ impl OwnedEnvironment {
6868
master_pipeline: &self._empty_str,
6969
#[cfg(feature = "ansible")]
7070
ansible_run: false,
71-
daemons: Daemons::default(),
71+
daemons: Default::default(),
7272
observe_cli: &None,
73+
skipper: Default::default(),
7374
}
7475
}
7576
}

src/entities/skipper.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Skipper module.
2+
3+
use std::sync::Arc;
4+
use tokio::sync::Mutex;
5+
6+
/// Utility to skip N Actions over chosen Pipelines,
7+
/// when you exactly know that they have no need to re-run after changes
8+
#[derive(Clone)]
9+
pub struct Skipper(Arc<Mutex<usize>>);
10+
11+
impl Default for Skipper {
12+
fn default() -> Self {
13+
Self(Arc::new(Mutex::new(0usize)))
14+
}
15+
}
16+
17+
impl Skipper {
18+
/// Creates a new skipper.
19+
pub fn new(skip: usize) -> Self {
20+
Self(Arc::new(Mutex::new(skip)))
21+
}
22+
23+
/// Checks if skipper has non-empty counter. It also decreases the counter, if has.
24+
pub async fn skip(&self) -> bool {
25+
let mut guard = self.0.lock().await;
26+
if *guard != 0 {
27+
*guard -= 1;
28+
true
29+
} else {
30+
false
31+
}
32+
}
33+
}

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub use deployer::*;
2929
use crate::actions::{cat_action, edit_action, list_actions, new_action, remove_action};
3030
use crate::cmd::{CatType, Cli, DeployerExecType, EditType, ListType, NewType, RemoveType};
3131
use crate::configs::{DeployerGlobalConfig, DeployerProjectOptions};
32+
use crate::entities::skipper::Skipper;
3233
use crate::pipelines::{
3334
assign_pipeline_to_project, cat_pipeline, cat_project, edit_pipeline, list_pipelines, new_pipeline, remove_pipeline,
3435
};
@@ -194,7 +195,10 @@ async fn main() {
194195
write(get_current_working_dir().unwrap(), conf_file, &config);
195196
}
196197
DeployerExecType::Run(args) => {
197-
clearscreen::clear().expect("Failed to clear screen");
198+
if !args.no_clear {
199+
clearscreen::clear().expect("Failed to clear screen");
200+
}
201+
let skipper = Skipper::new(args.skip.unwrap_or(0usize));
198202
let success = run(
199203
&mut config,
200204
&globals,
@@ -204,6 +208,7 @@ async fn main() {
204208
&storage_folder,
205209
&args,
206210
None,
211+
skipper,
207212
)
208213
.await
209214
.unwrap();

0 commit comments

Comments
 (0)