[go: up one dir, main page]

Skip to content

Parse Expressions & Rules for inputs

Context

Part 2/3: Dynamic Input Selection in GitLab Pipelines (&18546) - this will parse and evaluate expressions.

spec:
  inputs:
    deployment_type:
      options: ["rolling", "blue_green", "canary"]
      default: "rolling"

    target_environment:
      options: ["development", "staging", "production"]
      default: "development"

    resource_tier:
      rules:
        - if: $[[ inputs.target_environment ]] == "development"
          options: ["small", "medium"]
          default: "small"
        - if: $[[ inputs.target_environment ]] == "staging"
          options: ["medium", "large"]
          default: "medium"
        - if: $[[ inputs.target_environment ]] == "production" && $[[ inputs.deployment_type ]] == "canary"
          options: ["large", "xlarge", "xxlarge"]
          default: "large"
        - if: $[[ inputs.target_environment ]] == "production"
          options: ["large", "xlarge"]
          default: "xlarge"
        - options: ["small"]

---
deploy:
  script: |
    echo "Deploying using $[[ inputs.deployment_type ]] strategy"
    echo "Target: $[[ inputs.target_environment ]]"
    echo "Resources: $[[ inputs.resource_tier ]]"

Detect circular dependencies:

  spec:
    inputs:
      a:
        rules:
          - if: '$[[ inputs.b ]] == "x"'
            options: ['y']
      b:
        rules:
          - if: '$[[ inputs.a ]] == "y"'  
            options: ['x']

This will be split up into four MRs:

MR Status Description
Input lexeme !206891 (merged) Parse $[[ inputs.X ]] syntax in expressions
Rules converter !209135 needs: lexeme Convert expression AST to JSON
Semantic validation needs: input lexme Validate input references and circular dependencies, error handlin
GraphQL API needs: input lexme, rules converter Expose rules

Error Handling - (will be done during MR 3 or 4):

  • Invalid syntax: clear parse error messages
  • Missing inputs: graceful handling with boolean result
  • Unsupported operators: helpful error messages

How this works together

When the user writes:

rules:  
 - if: '$[[ inputs.env ]] == "prod"'
  1. We extracc: $inputs.env == "prod" (in the entry classes)
  2. The lexer then scans 🖨️ and creates tokens, so:
    • $[[ inputs.env ]] becomes an Input token
    • == becomes an Equals token
    • "prod" becomes String token
  3. Then the tokens get parsed into a tree. During this step, the value tokens become leafs and the operator tokens (== && ||) become parent nodes with children
Edited by Laura Montemayor