leave merge

Demo a comlex merge with leave elements

In most of caes, it is enough to just use simple plain string as a var. However we offten need to use object in our project. The configuration of the object evolves in scope and also during the runtime

This demo shows that the vars could be merged in leave level of an object tree. For example, the elements for the object in group vars can override the leave level elements from global scope, then individual scope, eg dev vars override/merge with the nonprod grouop vars, then local vars in func will overrides all above

Expected merge result

overall final exec vars:

(*core.Cache)({
  "a": "dev-a",
  "b": "non-prod-b",
  "c": {
    "c6": "dev-c6",
    "c7": "dev-c7",
    "c1": "dev-c1",
    "c2": "dev-c2",
    "c3": {
      "c31": "global-c31",
      "c32": "nonprod-c32",
      "c33": "dev-c33"
    },
    "c4": "nonprod-c4",
    "c5": "nonprod-c5"
  },
  "d": "global-d"
})

Demo

source

Main task yaml file
    scopes:
    - name: global
      vars:
        a: global-a
        b: global-b
        c:
          c1: global-c1
          c2: global-c2
          c3:
            c31: global-c31
            c32: global-c32
            c33: global-c33
          c4: global-c4
        d: global-d
    - name: prod
      members: [dr, prod]
      vars:
        a: prod-a
        c: prod-c
    - name: nonprod
      members:
      - dev
      - st
      - staging
      vars:
        a: non-prod-a
        b: non-prod-b
        c:
          c1: nonprod-c1
          c2: nonprod-c2
          c3:
            c32: nonprod-c32
            c33: nonprod-c33
          c4: nonprod-c4
          c5: nonprod-c5
    - name: staging
      vars:
        a: staging-a
        b: staging-b
    - name: dev
      vars:
        a: dev-a
        c:
          c1: dev-c1
          c2: dev-c2
          c3:
            c33: dev-c33
          c6: dev-c6
          c7: dev-c7
    tasks:
    - name: task
      task:
      - func: shell
        do:
        - echo "test out the var scopes only"
    
Main log file
    loading [Config]:  ./tests/functests/upconfig.yml
    Main config:
                 Version -> 1.0.0
                  RefDir -> ./tests/functests
                 WorkDir -> cwd
              AbsWorkDir -> /up_project/up
                TaskFile -> c0010
                 Verbose -> vvv
              ModuleName -> self
               ShellType -> /bin/sh
           MaxCallLayers -> 8
                 Timeout -> 3600000
     MaxModuelCallLayers -> 256
               EntryTask -> task
      ModRepoUsernameRef -> 
      ModRepoPasswordRef -> 
    work dir: /up_project/up
    -exec task: task
    loading [Task]:  ./tests/functests/c0010
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "d": "global-d",
      "up_runtime_task_layer_number": 0,
      "a": "dev-a",
      "b": "non-prod-b",
      "c": {
        "c7": "dev-c7",
        "c1": "dev-c1",
        "c2": "dev-c2",
        "c3": {
          "c32": "nonprod-c32",
          "c33": "dev-c33",
          "c31": "global-c31"
        },
        "c4": "nonprod-c4",
        "c5": "nonprod-c5",
        "c6": "dev-c6"
      }
    })
    
    cmd( 1):
    echo "test out the var scopes only"
    
    -
    test out the var scopes only
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level