Compare commits
3 Commits
2adb756cbc
...
6b3781b746
Author | SHA1 | Date |
---|---|---|
R Tyler Croy | 6b3781b746 | |
R Tyler Croy | d054fdf7ea | |
R Tyler Croy | 74ee25aa1a |
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
steps {
|
||||||
|
sh 'pwd'
|
||||||
|
// branch needed until #45 is addressed
|
||||||
|
git url: 'https://git.brokenco.de/rtyler/otto', branch: 'main', into: '.'
|
||||||
|
}
|
||||||
|
|
||||||
|
stage {
|
||||||
|
name = 'Build'
|
||||||
|
steps {
|
||||||
|
sh 'cargo test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// vim: sw=2 et ts=2 ft=groovy
|
|
@ -63,7 +63,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
mkdir_if_not_exists(&work_dir)?;
|
mkdir_if_not_exists(&work_dir)?;
|
||||||
mkdir_if_not_exists(&cache_dir)?;
|
mkdir_if_not_exists(&cache_dir)?;
|
||||||
|
|
||||||
std::env::set_var("CACHES_DIR", cache_dir);
|
std::env::set_var("CACHES_DIR", cache_dir.canonicalize().expect("Failed to canonicalize cache directory"));
|
||||||
std::env::set_current_dir(work_dir)?;
|
std::env::set_current_dir(work_dir)?;
|
||||||
|
|
||||||
let (sender, receiver) = channel(MAX_CONTROL_MSGS);
|
let (sender, receiver) = channel(MAX_CONTROL_MSGS);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub use serde_json::Value;
|
||||||
pub mod osp;
|
pub mod osp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'json'
|
||||||
|
require 'net/http'
|
||||||
|
|
||||||
|
pipeline = nil
|
||||||
|
|
||||||
|
# Parse it
|
||||||
|
Net::HTTP.start('localhost', 7672) do |http|
|
||||||
|
otto = File.read('Ottofile')
|
||||||
|
response = http.post('/v1/parse', otto)
|
||||||
|
|
||||||
|
if response.code.to_i != 200
|
||||||
|
puts 'Failed to parse file'
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline = JSON.parse(response.read_body)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Hit the local-orchestrator
|
||||||
|
Net::HTTP.start('localhost', 7673) do |http|
|
||||||
|
contexts = []
|
||||||
|
pipeline['batches'].each do |batch|
|
||||||
|
contexts += (batch['contexts'])
|
||||||
|
end
|
||||||
|
|
||||||
|
payload = JSON.dump({
|
||||||
|
:pipeline => pipeline['uuid'],
|
||||||
|
:contexts => contexts,
|
||||||
|
})
|
||||||
|
|
||||||
|
puts payload
|
||||||
|
res = http.post('/v1/run', payload)
|
||||||
|
|
||||||
|
if res.code.to_i != 200
|
||||||
|
puts "Failed to orchestrate! #{res.code} #{res.read_body}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
puts 'Enqueued'
|
||||||
|
end
|
|
@ -69,28 +69,86 @@ fn parse_str(parser: &mut pest::iterators::Pair<Rule>) -> String {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a pair of keyword arguments (kwarg rule) into a tuple
|
||||||
|
* of the string and value
|
||||||
|
*/
|
||||||
|
fn parse_kwarg(parser: &mut Pairs<Rule>) -> Option<(String, Value)> {
|
||||||
|
let mut key: Option<String> = None;
|
||||||
|
let mut value: Option<Value> = None;
|
||||||
|
|
||||||
|
while let Some(mut parsed) = parser.next() {
|
||||||
|
match parsed.as_rule() {
|
||||||
|
Rule::IDENT => {
|
||||||
|
key = Some(parsed.as_str().to_string());
|
||||||
|
},
|
||||||
|
Rule::STR => {
|
||||||
|
value = Some(Value::String(parse_str(&mut parsed)));
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if key.is_some() && value.is_some() {
|
||||||
|
return Some((key.unwrap(), value.unwrap()));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the steps
|
* Parse the steps
|
||||||
*
|
*
|
||||||
* In the case of orphan steps, the uuid should be the pipeline's uuid
|
* In the case of orphan steps, the uuid should be the pipeline's uuid
|
||||||
*/
|
*/
|
||||||
fn parse_steps(parser: &mut Pairs<Rule>, uuid: Uuid) -> Vec<Step> {
|
fn parse_steps(parser: &mut Pairs<Rule>, uuid: Uuid) -> Vec<Step> {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
let mut steps = vec![];
|
let mut steps = vec![];
|
||||||
|
|
||||||
while let Some(parsed) = parser.next() {
|
while let Some(parsed) = parser.next() {
|
||||||
if Rule::step == parsed.as_rule() {
|
if Rule::step == parsed.as_rule() {
|
||||||
|
let mut symbol: Option<String> = None;
|
||||||
|
let mut kwargs: HashMap<String, Value> = HashMap::new();
|
||||||
|
let mut args: Vec<Value> = vec![];
|
||||||
|
|
||||||
// Grab the step components
|
// Grab the step components
|
||||||
let mut parts: Vec<Pair<Rule>> = parsed.into_inner().collect();
|
for part in parsed.into_inner() {
|
||||||
// We need at least two parts here!
|
match part.as_rule() {
|
||||||
assert!(parts.len() > 1);
|
Rule::IDENT => {
|
||||||
|
symbol = Some(part.as_str().to_string());
|
||||||
|
},
|
||||||
|
Rule::kwarg => {
|
||||||
|
if let Some((key, value)) = parse_kwarg(&mut part.into_inner()) {
|
||||||
|
kwargs.insert(key, value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Rule::args => {
|
||||||
|
let mut pairs: Vec<Pair<Rule>> = part.into_inner().collect();
|
||||||
|
for mut pair in pairs.iter_mut() {
|
||||||
|
if Rule::STR == pair.as_rule() {
|
||||||
|
args.push(Value::String(parse_str(&mut pair)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let symbol = parts[0].as_str().to_string();
|
if let Some(symbol) = symbol {
|
||||||
let command = parse_str(&mut parts.pop().unwrap());
|
if kwargs.len() > 0 {
|
||||||
|
if args.len() > 0 {
|
||||||
let parameters = serde_json::Value::String(command);
|
error!("Parsed keyword and positional arguments out, discarding positionals");
|
||||||
let parameters = StepParameters::Positional(vec![parameters]);
|
}
|
||||||
let step = Step::new(uuid, symbol, parameters);
|
let parameters = StepParameters::Keyword(kwargs);
|
||||||
steps.push(step);
|
let step = Step::new(uuid, symbol, parameters);
|
||||||
|
steps.push(step);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let parameters = StepParameters::Positional(args);
|
||||||
|
let step = Step::new(uuid, symbol, parameters);
|
||||||
|
steps.push(step);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
steps
|
steps
|
||||||
|
@ -276,4 +334,58 @@ mod tests {
|
||||||
assert!(!pipeline.uuid.is_nil());
|
assert!(!pipeline.uuid.is_nil());
|
||||||
assert_eq!(pipeline.batches.len(), 1);
|
assert_eq!(pipeline.batches.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_kwargs() {
|
||||||
|
let buf = r#"
|
||||||
|
pipeline {
|
||||||
|
steps {
|
||||||
|
git url: 'https://example.com', branch: 'main'
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
let pipeline = parse_pipeline_string(&buf).expect("Failed to parse");
|
||||||
|
assert!(!pipeline.uuid.is_nil());
|
||||||
|
assert_eq!(pipeline.batches.len(), 1);
|
||||||
|
|
||||||
|
let context = &pipeline.batches[0].contexts[0];
|
||||||
|
assert_eq!(context.steps.len(), 1);
|
||||||
|
let step = &context.steps[0];
|
||||||
|
assert_eq!(step.symbol, "git");
|
||||||
|
|
||||||
|
match &step.parameters {
|
||||||
|
StepParameters::Positional(_args) => assert!(false, "Shouldn't have positional arguments"),
|
||||||
|
StepParameters::Keyword(kwargs) => {
|
||||||
|
assert_eq!(kwargs.get("url").unwrap(), "https://example.com");
|
||||||
|
assert_eq!(kwargs.get("branch").unwrap(), "main");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_multiple_pos_args() {
|
||||||
|
let buf = r#"
|
||||||
|
pipeline {
|
||||||
|
steps {
|
||||||
|
git 'https://example.com', 'main'
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
let pipeline = parse_pipeline_string(&buf).expect("Failed to parse");
|
||||||
|
assert!(!pipeline.uuid.is_nil());
|
||||||
|
assert_eq!(pipeline.batches.len(), 1);
|
||||||
|
|
||||||
|
let context = &pipeline.batches[0].contexts[0];
|
||||||
|
assert_eq!(context.steps.len(), 1);
|
||||||
|
let step = &context.steps[0];
|
||||||
|
assert_eq!(step.symbol, "git");
|
||||||
|
match &step.parameters {
|
||||||
|
StepParameters::Positional(args) => {
|
||||||
|
assert_eq!(args.len(), 2);
|
||||||
|
assert_eq!(args[0], "https://example.com");
|
||||||
|
assert_eq!(args[1], "main");
|
||||||
|
},
|
||||||
|
StepParameters::Keyword(_kwargs) => {
|
||||||
|
assert!(false, "Not expecting keyword arguments for this step");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ step = { IDENT ~ (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
args = _{ (STR ~ COMMA?)+ }
|
args = { (STR ~ COMMA?)+ }
|
||||||
kwargs = _{ (kwarg ~ COMMA?)+ }
|
kwargs = _{ (kwarg ~ COMMA?)+ }
|
||||||
kwarg = _{ IDENT~ ":" ~ STR }
|
kwarg = { IDENT~ ":" ~ STR }
|
||||||
property = { IDENT ~ "=" ~ STR }
|
property = { IDENT ~ "=" ~ STR }
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue