defenseunicorns / maru-runner

The Unicorn Task Runner
Apache License 2.0
8 stars 0 forks source link

UDS Runner: `INPUT_` vars fall off when chaining tasks with inputs #86

Open zack-is-cool opened 5 months ago

zack-is-cool commented 5 months ago

Environment

App version: v0.9.2

Steps to reproduce

Given this complete example:

#!/usr/bin/env bash

# make temp dir
DEMO_DIR=$(mktemp -d)
pushd $DEMO_DIR

# create some dir
mkdir -p tasks
mkdir -p foo
echo "hello" > foo/hello.txt

# Generate the taskfiles with some heredocs
cat <<'EOF' > tasks.yaml
includes:
  - test: ./tasks/test-inputs.yaml

tasks:
  - name: test-inputs
    actions: 
      - task: test:input-checker
        with:
          file_name: "hello.txt"
          file_path: ./foo
EOF

cat <<'EOF' > tasks/test-inputs.yaml
tasks:
  - name: input-checker
    inputs:
      file_name:
        description: "Name of the file"
        required: true
      file_path:
        description: "Path of the file"
        required: true
    actions:
      - description: "cat file directly"
        cmd: |
          set -x
          cat ${INPUT_FILE_PATH}/${INPUT_FILE_NAME}
      - description: "use dir to enter dir using go template and cat file"
        dir: ${{ .inputs.file_path }}
        cmd: |
          set -x
          # get basename of cwd
          echo "cwd: $(basename $(pwd))"
          cat ${{ .inputs.file_name }}
      - description: "chaining inputs does not work within tasks with '$INPUT_' vars"
        task: chaining
        with:
          file_name: ${INPUT_FILE_NAME}
          file_path: ${INPUT_FILE_PATH}
      - description: "chaining inputs works within tasks with gotemplate"
        task: chaining
        with:
          file_name: ${{ .inputs.file_name }}
          file_path: ${{ .inputs.file_path }}

  - name: chaining
    inputs:
      file_name:
        description: "Name of the file"
        required: true
      file_path:
        description: "Path of the file"
        required: true
    actions:
      - description: "chaining inputs"
        cmd: |
          set -x
          echo "file_name: ${INPUT_FILE_NAME}"
          echo "file_path: ${INPUT_FILE_PATH}"
EOF

# Run the task
uds run test-inputs

while (( $? == 0 )); do popd  > /dev/null 2>&1; done
rm -rf "$DEMO_DIR"
unset DEMO_DIR

Expected result

Actual Result

$INPUT_ vars fall off after the first task, chaining inputs from included tasks that include other tasks doesn't seem to work without using gotemplating syntax. Not sure if intentional.

Visual Proof (screenshots, videos, text, etc)

/var/folders/bf/tkdyvkq57lq56fck6q_rnlv80000gn/T/tmp.y2Bf3xNc1C ~/uds-run-scratch

 NOTE  Saving log file to
       /var/folders/bf/tkdyvkq57lq56fck6q_rnlv80000gn/T/uds-2024-02-27-15-16-27-255546366.log
     + cat ./foo/hello.txt                                                                                                                                                                                                                                                                   
     hello                                                                                                                                                                                                                                                                                   
  ✔  Completed "cat file directly"                                                                                                                                                                                                                                                           
     +++ pwd                                                                                                                                                                                                                                                                                 
     ++ basename /private/var/folders/bf/tkdyvkq57lq56fck6q_rnlv80000gn/T/tmp.y2Bf3xNc1C/foo                                                                                                                                                                                                 
     cwd: foo                                                                                                                                                                                                                                                                                
     + echo 'cwd: foo'                                                                                                                                                                                                                                                                       
     + cat hello.txt                                                                                                                                                                                                                                                                         
     hello                                                                                                                                                                                                                                                                                   
  ✔  Completed "use dir to enter dir using go template and cat file"                                                                                                                                                                                                                         
     file_name: ${INPUT_FILE_NAME}                                                                                                                                                                                                                                                           
     file_path: ${INPUT_FILE_PATH}                                                                                                                                                                                                                                                           
     + echo 'file_name: ${INPUT_FILE_NAME}'                                                                                                                                                                                                                                                  
     + echo 'file_path: ${INPUT_FILE_PATH}'                                                                                                                                                                                                                                                  
  ✔  Completed "chaining inputs"                                                                                                                                                                                                                                                             
     + echo 'file_name: hello.txt'                                                                                                                                                                                                                                                           
     file_name: hello.txt                                                                                                                                                                                                                                                                    
     + echo 'file_path: ./foo'                                                                                                                                                                                                                                                               
     file_path: ./foo                                                                                                                                                                                                                                                                        
  ✔  Completed "chaining inputs"