Compare commits
3 Commits
69c582b87e
...
57747e0fbc
Author | SHA1 | Date |
---|---|---|
R Tyler Croy | 57747e0fbc | |
R Tyler Croy | c256dffa50 | |
R Tyler Croy | 6eca8bfd7d |
|
@ -300,9 +300,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.53"
|
||||
version = "1.0.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68"
|
||||
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
76
src/lib.rs
76
src/lib.rs
|
@ -238,17 +238,65 @@ pipeline {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn parse_script_step() {
|
||||
fn parse_steps_with_triple_singles() {
|
||||
let _s = PipelineParser::parse(
|
||||
Rule::stepsDecl,
|
||||
r#"steps {
|
||||
script {
|
||||
def taskOutput = readJSON file: 'task-output.dev.json'
|
||||
def revision = taskOutput.taskDefinition.revision
|
||||
sh "aws ecs update-service --cluster ${CLUSTER} --service ${SERVICE} --task-definition ${FAMILY}:${revision}"
|
||||
sh '''
|
||||
env
|
||||
'''
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_steps_with_triple_doubles() {
|
||||
let _s = PipelineParser::parse(
|
||||
Rule::stepsDecl,
|
||||
r#"steps {
|
||||
sh """
|
||||
env
|
||||
"""
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/*
|
||||
* I kind of cannot believe that this is legitimate Declarative but it
|
||||
* apparently is!
|
||||
*/
|
||||
#[test]
|
||||
fn parse_string_with_concatenation() {
|
||||
let _s = PipelineParser::parse(
|
||||
Rule::stepsDecl,
|
||||
r#"steps {
|
||||
echo 'Hello world: ' + WORKSPACE
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_step_with_symbol_concatenation() {
|
||||
let _s = PipelineParser::parse(
|
||||
Rule::stepsDecl,
|
||||
r#"steps {
|
||||
ws(dir: WORKSPACE + '/foo') {
|
||||
sh 'pwd'
|
||||
}
|
||||
}"#)
|
||||
.unwrap().next().unwrap();
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -264,6 +312,20 @@ pipeline {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_script_step() {
|
||||
let _s = PipelineParser::parse(
|
||||
Rule::stepsDecl,
|
||||
r#"steps {
|
||||
script {
|
||||
def taskOutput = readJSON file: 'task-output.dev.json'
|
||||
def revision = taskOutput.taskDefinition.revision
|
||||
sh "aws ecs update-service --cluster ${CLUSTER} --service ${SERVICE} --task-definition ${FAMILY}:${revision}"
|
||||
}
|
||||
}"#)
|
||||
.unwrap().next().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_script_step_nesting() {
|
||||
let _s = PipelineParser::parse(
|
||||
|
|
|
@ -203,10 +203,12 @@ block_step = _{ IDENT ~
|
|||
checkout_step = { "checkout" ~ "scm" }
|
||||
step = { checkout_step | block_step | simple_step }
|
||||
|
||||
arg = _{ string | bool | number | magic_vars | array_args | map_args | step }
|
||||
args = { (arg ~ COMMA?)+ }
|
||||
kwargs = _{ (kwarg ~ COMMA?)+ }
|
||||
kwarg = { IDENT~ ":" ~ arg }
|
||||
value = _{ string | bool | number | magic_vars }
|
||||
arg = _{ value | array_args | map_args | step }
|
||||
args = { (arg ~ comma?)+ }
|
||||
|
||||
kwarg = { IDENT ~ ":" ~ arg }
|
||||
kwargs = _{ (kwarg ~ comma?)+ }
|
||||
|
||||
map_args = _{ opening_brack ~ kwargs ~ closing_brack }
|
||||
// This syntax is some Groovy invocation magic that I'm not sure I fully
|
||||
|
@ -215,8 +217,8 @@ array_args = _{ opening_brack ~ args ~ closing_brack }
|
|||
property = { IDENT ~ "=" ~ string }
|
||||
|
||||
// These are magic variables that are legitimate to use in "declarative"
|
||||
// pipeline
|
||||
magic_vars = _{ envRef | scmRef | paramsRef }
|
||||
// pipeline. Supports concatenation
|
||||
magic_vars = _{ (envRef | scmRef | paramsRef | "WORKSPACE") ~ (plus ~ (string | magic_vars))? }
|
||||
envRef = { "env." ~ nestedRef }
|
||||
scmRef = { "scm." ~ nestedRef }
|
||||
paramsRef = { "params." ~ nestedRef }
|
||||
|
@ -260,7 +262,7 @@ whenTriggered = { "triggeredBy" ~ string }
|
|||
|
||||
IDENT = @{ (ASCII_ALPHA | "$") ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
|
||||
string = ${ (single_quoted | double_quoted) }
|
||||
string = { (single_quoted | double_quoted) ~ (plus ~ (magic_vars | string))* }
|
||||
single_quoted = ${ single_quote ~ inner_single_str ~ single_quote }
|
||||
double_quoted = ${ quote ~ inner_double_str ~ quote }
|
||||
|
||||
|
@ -282,11 +284,12 @@ opening_paren = { "(" }
|
|||
closing_paren = { ")" }
|
||||
opening_brack = { "[" }
|
||||
closing_brack = { "]" }
|
||||
plus = @{ "+" }
|
||||
|
||||
number = @{ '0'..'9'+ }
|
||||
integer = @{ number | "-" ~ "0"* ~ '1'..'9' ~ number? }
|
||||
|
||||
COMMA = @{ "," }
|
||||
comma = @{ "," }
|
||||
bool = @{ (TRUE | FALSE) }
|
||||
TRUE = { "true" }
|
||||
FALSE = { "false" }
|
||||
|
|
Loading…
Reference in New Issue