feat: support partial go dependency pinning

This commit is contained in:
Ruben Fiszel
2023-08-31 22:12:47 +02:00
parent 16fa99a4ea
commit 41107c7cfa
6 changed files with 36 additions and 5 deletions
+2
View File
@@ -7243,6 +7243,8 @@ dependencies = [
"anyhow",
"gosyn",
"itertools 0.11.0",
"lazy_static",
"regex",
"windmill-parser",
]
@@ -12,4 +12,6 @@ path = "./src/lib.rs"
windmill-parser.workspace = true
itertools.workspace = true
anyhow.workspace = true
gosyn.workspace = true
gosyn.workspace = true
lazy_static.workspace = true
regex.workspace = true
+13 -1
View File
@@ -6,8 +6,13 @@ use gosyn::{
};
use itertools::Itertools;
use regex::Regex;
use windmill_parser::{Arg, MainArgSignature, ObjectProperty, Typ};
lazy_static::lazy_static! {
pub static ref REQUIRE_PARSE: Regex = Regex::new(r"//require (.*)\n").unwrap();
}
pub fn parse_go_sig(code: &str) -> anyhow::Result<MainArgSignature> {
let filtered_code = filter_non_main(code);
let file = parse_source(&filtered_code).map_err(|x| anyhow::anyhow!(x.to_string()))?;
@@ -46,7 +51,14 @@ pub fn parse_go_imports(code: &str) -> anyhow::Result<Vec<String>> {
})
.collect();
imports.sort();
Ok(imports)
Ok([
imports,
REQUIRE_PARSE
.captures_iter(code)
.map(|x| x[1].to_string())
.collect_vec(),
]
.concat())
}
fn get_name(param: &Field) -> String {
+14 -1
View File
@@ -12,7 +12,7 @@ use windmill_common::{
jobs::QueuedJob,
utils::calculate_hash,
};
use windmill_parser_go::parse_go_imports;
use windmill_parser_go::{parse_go_imports, REQUIRE_PARSE};
use crate::{
common::{
@@ -296,6 +296,9 @@ async fn gen_go_mod(
}
}
use std::fs::OpenOptions;
use std::io::prelude::*;
pub async fn install_go_dependencies(
job_id: &Uuid,
code: &str,
@@ -329,6 +332,16 @@ pub async fn install_go_dependencies(
None,
)
.await?;
for x in REQUIRE_PARSE.captures_iter(code) {
let mut file = OpenOptions::new()
.write(true)
.append(true)
.open(format!("{job_dir}/go.mod"))
.unwrap();
writeln!(file, "require {}\n", &x[1])?;
}
}
let mut new_lockfile = false;
+1 -2
View File
@@ -67,6 +67,7 @@ impl TimersPermission for PermissionsContainer {
()
}
}
pub struct OptAuthedClient(Option<AuthedClient>);
pub async fn eval_timeout(
expr: String,
@@ -122,8 +123,6 @@ pub async fn eval_timeout(
.enable_all()
.build()?;
let re = Regex::new(r"import (.*)\n").unwrap();
let expr = re.replace_all(&expr, "").to_string();
// pretty frail but this it to make the expr more user friendly and not require the user to write await
let expr = ["variable", "step", "resource", "result_by_id"]
.into_iter()
+3
View File
@@ -81,6 +81,9 @@ import (
// wmill "github.com/windmill-labs/windmill-go-client"
)
// Pin dependencies partially in go.mod with a comment starting with "//require":
//require rsc.io/quote v1.5.1
// the main must return (interface{}, error)
func main(x string, nested struct {