forked from github-starred/komodo
1.15.4 (#114)
* stack destroy before deploy option * add timestamps. Fix log polling even when poll not selected * Add build [[$VERSION]] support. VERSION build arg default * fix clippy lint * initialize `first_builder` * run_komodo_command uses parse_multiline_command * comment UI for $VERSION and new command feature * bump some deps * support multiline commands in pre_deploy / pre_build
This commit is contained in:
@@ -1,12 +1,57 @@
|
||||
use std::path::Path;
|
||||
|
||||
use komodo_client::entities::{komodo_timestamp, update::Log};
|
||||
use run_command::{async_run_command, CommandOutput};
|
||||
|
||||
pub async fn run_komodo_command(stage: &str, command: String) -> Log {
|
||||
/// Parses commands out of multiline string
|
||||
/// and chains them together with '&&'
|
||||
///
|
||||
/// Supports full line and end of line comments. See [parse_multiline_command].
|
||||
pub async fn run_komodo_command(
|
||||
stage: &str,
|
||||
path: impl Into<Option<&Path>>,
|
||||
command: impl AsRef<str>,
|
||||
) -> Log {
|
||||
let command = parse_multiline_command(command);
|
||||
let command = if let Some(path) = path.into() {
|
||||
format!("cd {} && {command}", path.display(),)
|
||||
} else {
|
||||
command
|
||||
};
|
||||
let start_ts = komodo_timestamp();
|
||||
let output = async_run_command(&command).await;
|
||||
output_into_log(stage, command, start_ts, output)
|
||||
}
|
||||
|
||||
/// Parses commands out of multiline string
|
||||
/// and chains them together with '&&'
|
||||
///
|
||||
/// Supports full line and end of line comments.
|
||||
///
|
||||
/// ## Example:
|
||||
/// ```sh
|
||||
/// # comments supported
|
||||
/// sh ./shell1.sh # end of line supported
|
||||
/// sh ./shell2.sh
|
||||
/// # print done
|
||||
/// echo done
|
||||
/// ```
|
||||
/// becomes
|
||||
/// ```sh
|
||||
/// sh ./shell1.sh && sh ./shell2.sh && echo done
|
||||
/// ```
|
||||
pub fn parse_multiline_command(command: impl AsRef<str>) -> String {
|
||||
command
|
||||
.as_ref()
|
||||
.split('\n')
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.is_empty() && !line.starts_with('#'))
|
||||
.filter_map(|line| line.split(" #").next())
|
||||
.map(str::trim)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" && ")
|
||||
}
|
||||
|
||||
pub fn output_into_log(
|
||||
stage: &str,
|
||||
command: String,
|
||||
|
||||
@@ -39,8 +39,7 @@ where
|
||||
{
|
||||
let args: CloneArgs = clone_args.into();
|
||||
let repo_dir = args.path(repo_dir);
|
||||
let repo_url =
|
||||
args.remote_url(access_token.as_ref().map(String::as_str))?;
|
||||
let repo_url = args.remote_url(access_token.as_deref())?;
|
||||
|
||||
let mut logs = clone_inner(
|
||||
&repo_url,
|
||||
@@ -116,7 +115,8 @@ where
|
||||
replacers.extend(core_replacers.to_owned());
|
||||
let mut on_clone_log = run_komodo_command(
|
||||
"on clone",
|
||||
format!("cd {} && {full_command}", on_clone_path.display()),
|
||||
on_clone_path.as_ref(),
|
||||
full_command,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -137,11 +137,8 @@ where
|
||||
} else {
|
||||
let on_clone_log = run_komodo_command(
|
||||
"on clone",
|
||||
format!(
|
||||
"cd {} && {}",
|
||||
on_clone_path.display(),
|
||||
command.command
|
||||
),
|
||||
on_clone_path.as_ref(),
|
||||
&command.command,
|
||||
)
|
||||
.await;
|
||||
tracing::debug!(
|
||||
@@ -170,7 +167,8 @@ where
|
||||
replacers.extend(core_replacers.to_owned());
|
||||
let mut on_pull_log = run_komodo_command(
|
||||
"on pull",
|
||||
format!("cd {} && {full_command}", on_pull_path.display()),
|
||||
on_pull_path.as_ref(),
|
||||
&full_command,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -191,11 +189,8 @@ where
|
||||
} else {
|
||||
let on_pull_log = run_komodo_command(
|
||||
"on pull",
|
||||
format!(
|
||||
"cd {} && {}",
|
||||
on_pull_path.display(),
|
||||
command.command
|
||||
),
|
||||
on_pull_path.as_ref(),
|
||||
&command.command,
|
||||
)
|
||||
.await;
|
||||
tracing::debug!(
|
||||
@@ -256,10 +251,8 @@ async fn clone_inner(
|
||||
if let Some(commit) = commit {
|
||||
let reset_log = run_komodo_command(
|
||||
"set commit",
|
||||
format!(
|
||||
"cd {} && git reset --hard {commit}",
|
||||
destination.display()
|
||||
),
|
||||
destination,
|
||||
format!("git reset --hard {commit}",),
|
||||
)
|
||||
.await;
|
||||
logs.push(reset_log);
|
||||
|
||||
@@ -38,16 +38,13 @@ where
|
||||
{
|
||||
let args: CloneArgs = clone_args.into();
|
||||
let path = args.path(repo_dir);
|
||||
let path_display = path.display();
|
||||
let repo_url =
|
||||
args.remote_url(access_token.as_ref().map(String::as_str))?;
|
||||
let repo_url = args.remote_url(access_token.as_deref())?;
|
||||
|
||||
// Set remote url
|
||||
let mut set_remote = run_komodo_command(
|
||||
"set git remote",
|
||||
format!(
|
||||
"cd {path_display} && git remote set-url origin {repo_url}"
|
||||
),
|
||||
path.as_ref(),
|
||||
format!("git remote set-url origin {repo_url}"),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -70,7 +67,8 @@ where
|
||||
|
||||
let checkout = run_komodo_command(
|
||||
"checkout branch",
|
||||
format!("cd {path_display} && git checkout -f {}", args.branch),
|
||||
path.as_ref(),
|
||||
format!("git checkout -f {}", args.branch),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -83,12 +81,12 @@ where
|
||||
});
|
||||
}
|
||||
|
||||
let command = format!(
|
||||
"cd {path_display} && git pull --rebase --force origin {}",
|
||||
args.branch
|
||||
);
|
||||
|
||||
let pull_log = run_komodo_command("git pull", command).await;
|
||||
let pull_log = run_komodo_command(
|
||||
"git pull",
|
||||
path.as_ref(),
|
||||
format!("git pull --rebase --force origin {}", args.branch),
|
||||
)
|
||||
.await;
|
||||
|
||||
let mut logs = vec![pull_log];
|
||||
|
||||
@@ -104,7 +102,8 @@ where
|
||||
if let Some(commit) = args.commit {
|
||||
let reset_log = run_komodo_command(
|
||||
"set commit",
|
||||
format!("cd {path_display} && git reset --hard {commit}"),
|
||||
path.as_ref(),
|
||||
format!("git reset --hard {commit}"),
|
||||
)
|
||||
.await;
|
||||
logs.push(reset_log);
|
||||
@@ -144,7 +143,7 @@ where
|
||||
};
|
||||
|
||||
if let Some(command) = args.on_pull {
|
||||
if !command.path.is_empty() && !command.command.is_empty() {
|
||||
if !command.command.is_empty() {
|
||||
let on_pull_path = path.join(&command.path);
|
||||
if let Some(secrets) = secrets {
|
||||
let (full_command, mut replacers) =
|
||||
@@ -174,7 +173,8 @@ where
|
||||
replacers.extend(core_replacers.to_owned());
|
||||
let mut on_pull_log = run_komodo_command(
|
||||
"on pull",
|
||||
format!("cd {} && {full_command}", on_pull_path.display()),
|
||||
on_pull_path.as_ref(),
|
||||
&full_command,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -195,11 +195,8 @@ where
|
||||
} else {
|
||||
let on_pull_log = run_komodo_command(
|
||||
"on pull",
|
||||
format!(
|
||||
"cd {} && {}",
|
||||
on_pull_path.display(),
|
||||
command.command
|
||||
),
|
||||
on_pull_path.as_ref(),
|
||||
&command.command,
|
||||
)
|
||||
.await;
|
||||
tracing::debug!(
|
||||
|
||||
Reference in New Issue
Block a user