Purpose of this library is to evaluate conditional expressions written in
domain specific language defined in Conditions DSL section bellow for given
set of parameters.
Each condition will be evaluated either as true or false for given set of parameters
if it is valid expression in Conditions DSL, otherwise error is returned.
Just add it to your mix.exs file:
{:when, github: "renderedtext/when"}
and then you can evaluate string condition written in Conditions DSL with:
When.evaluate(condition, parameters)
where parameters is map containing {keyword, value} pairs for each keyword that appears in condition string.
Formal language definition in extended Backus-Naur Form (EBNF) notation:
expression = expression bool_operator term
           | term
term = "(" expression ")"      
     | keyword operator string
     | string operator keyword
     | string                  
     | boolean
bool_operator = "and" | "AND" | "or" | "OR"
keyword = "branch" | "BRANCH" | "tag" | "TAG" | "pull_request" | "PULL_REQUEST" |
 "result" | "RESULT" | "result_reason" | "RESULT_REASON"
operator = "=" | "!=" | "=~" | "!~"
boolean = "true" | "TRUE" | "false" | "FALSE"
string = ? all characters between two single quotes, e.g. 'master' ?
Each keyword in passed expression is replaced with passed value from parameters map when expression is evaluated, and then operations identified with one of the operators from above are executed with those values.
| KEYWORD | MEANING | 
|---|---|
| branch | Name of the GitHub branch from which originated the pipeline that is being executed. | 
| tag | Name of the GitHub tag from which originated the pipeline that is being executed. | 
| pull_request | Number (as string) of GitHub pull request from which originated the pipeline that is being executed. | 
| result | Execution result of pipeline, block, or job. Possible values are: passed, stopped, canceled and failed. | 
| result_reason | The reason for given result of execution. Possible values are: test, malformed, stuck, deleted, internal and user. | 
| OPERATOR | OPERATION RESULT | 
|---|---|
| = | True if keyword value and given string are equal | 
| != | True if keyword value and given string are not equal | 
| =~ | True if keyword value and given PCRE* string match | 
| !~ | True if keyword value and given PCRE* string do not match | 
| and | True if expressions on both sides are true | 
| or | True if at least one of two expressions is true | 
* PCRE = Perl Compatible Regular Expression
promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "true"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch =~ '.*' AND result =~ '.*'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch =~ '.*' AND result = 'passed'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch = 'master' AND result = 'passed'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch = 'master'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch =~ '^df\/'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch = 'staging' OR branch = 'master'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "tag =~ '.*'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "tag =~ '^v1\.'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "tag =~ '^v1\.' AND result = 'passed'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "branch = 'master' OR tag =~ '.*'"promotions:
  - name: Deploy to production
    pipeline_file: prod.yml
    auto:
      when: "(branch = 'master' OR tag =~ '.*') AND result = 'passed'"blocks:
  - name: Unit tests
    skip:
      when: "true"blocks:
  - name: Unit tests
    skip:
      when: "branch = '.*'"blocks:
  - name: Unit tests
    skip:
      when: "branch = 'master'"blocks:
  - name: Unit tests
    skip:
      when: "branch =~ '^df\/'"blocks:
  - name: Unit tests
    skip:
      when: "branch = 'staging' OR branch = 'master'"blocks:
  - name: Unit tests
    skip:
      when: "tag =~ '.*'"blocks:
  - name: Unit tests
    skip:
      when: "tag =~ '^v1\.'"blocks:
  - name: Unit tests
    skip:
      when: "branch = 'master' OR tag =~ '.*'"blocks:
  - name: Unit tests
    skip:
      when: "branch !~ '^dev\/'"fail_fast:
  cancel:
    when: "true"fail_fast:
  cancel:
    when: "branch = 'master'"fail_fast:
  cancel:
    when: "branch =~ '^df\/'"fail_fast:
  cancel:
    when: "branch = 'staging' OR branch = 'master'"fail_fast:
  cancel:
    when: "tag =~ '.*'"fail_fast:
  cancel:
    when: "tag =~ '^v1\.'"fail_fast:
  cancel:
    when: "branch = 'master' OR tag =~ '.*'"fail_fast:
  cancel:
    when: "tag !~ '^dev\/'"queue:
  mode:
    stop:
      when: "branch = 'master' OR tag =~ '.*'"
    cancel:
      when: "tag =~ '.*'"This software is licensed under the Apache 2.0 license.