Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support bash as 4th language (#865)
* bash support * bash backend working * frontend part * bash backend working
- Loading branch information
1 parent
3333713
commit 3c09275
Showing
35 changed files
with
475 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- Add down migration script here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Add up migration script here | ||
ALTER TYPE SCRIPT_LANG ADD VALUE 'bash'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "windmill-parser-bash" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
|
||
[lib] | ||
name = "windmill_parser_bash" | ||
path = "./src/lib.rs" | ||
|
||
[dependencies] | ||
windmill-parser.workspace = true | ||
windmill-common.workspace = true | ||
phf.workspace = true | ||
unicode-general-category.workspace = true | ||
itertools.workspace = true | ||
anyhow.workspace = true | ||
regex.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#![allow(non_snake_case)] // TODO: switch to parse_* function naming | ||
|
||
use regex::Regex; | ||
|
||
use std::collections::HashMap; | ||
use windmill_parser::{Arg, MainArgSignature, Typ}; | ||
|
||
pub fn parse_bash_sig(code: &str) -> windmill_common::error::Result<MainArgSignature> { | ||
let parsed = parse_file(&code)?; | ||
if let Some(x) = parsed { | ||
let args = x; | ||
Ok(MainArgSignature { star_args: false, star_kwargs: false, args }) | ||
} else { | ||
Err(windmill_common::error::Error::BadRequest( | ||
"Error parsing bash script".to_string(), | ||
)) | ||
} | ||
} | ||
|
||
fn parse_file(code: &str) -> anyhow::Result<Option<Vec<Arg>>> { | ||
let mut hm = HashMap::new(); | ||
let re = Regex::new(r#"(?m)^(\w+)="\$(\d+)"$"#).unwrap(); | ||
for cap in re.captures_iter(code) { | ||
hm.insert(cap[2].parse::<i32>()?, cap[1].to_string()); | ||
} | ||
let mut args = vec![]; | ||
for i in 1..20 { | ||
if hm.contains_key(&i) { | ||
args.push(Arg { | ||
name: hm[&i].clone(), | ||
typ: Typ::Str(None), | ||
default: None, | ||
otyp: None, | ||
has_default: false, | ||
}); | ||
} else { | ||
break; | ||
} | ||
} | ||
Ok(Some(args)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_parse_bash_sig() -> anyhow::Result<()> { | ||
let code = r#" | ||
token="$1" | ||
image="$2" | ||
digest="${3:-latest}" | ||
foo="$4" | ||
"#; | ||
//println!("{}", serde_json::to_string()?); | ||
assert_eq!( | ||
parse_bash_sig(code)?, | ||
MainArgSignature { | ||
star_args: false, | ||
star_kwargs: false, | ||
args: vec![ | ||
Arg { | ||
otyp: None, | ||
name: "token".to_string(), | ||
typ: Typ::Str(None), | ||
default: None, | ||
has_default: false | ||
}, | ||
Arg { | ||
otyp: None, | ||
name: "image".to_string(), | ||
typ: Typ::Str(None), | ||
default: None, | ||
has_default: false | ||
} | ||
] | ||
} | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.