defenseunicorns / maru-runner

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

Magic Imports - able to call tasks from files not included in task file #18

Open decleaver opened 4 months ago

decleaver commented 4 months ago

Environment

-tasks -- magic-import.yaml -- publish.yaml tasks.yaml

#tasks/magic-import.yaml
tasks:
  - name: run-magic-root-task
    description: Build and publish the packages
    actions:
      - task: magical-working-task
  - name: magic-task
    description: run
    actions:
      - cmd: echo "I shouldnt work"
#tasks/publish.yaml
variables:
  - name: TARGET_REPO
    default: "oci://ghcr.io/defenseunicorns/packages/uds"

tasks:
  - name: publish
    description: Build and publish the packages
    actions:
      - description: Create the packages
        cmd: echo ${TARGET_REPO}
  - name: package
    description: Build and publish the packages
    actions:
      - description: Create the packages
        cmd: |
          set -e
          ZARF_ARCHITECTURE=amd64 uds run create-package --set FLAVOR=${FLAVOR}
          if [ ${FLAVOR} != "registry1" ]; then
            ZARF_ARCHITECTURE=arm64 uds run create-package --set FLAVOR=${FLAVOR}
          fi
  - name: package2
    description: Build and publish the packages
    actions:
      - description: Create the packages
        cmd: |
          set -e
          ZARF_ARCHITECTURE=amd64 uds run create-package2 --set FLAVOR=${FLAVOR}
  - name: package3
    description: Build and publish the packages
    actions:
      - description: Create the packages
        cmd: |
          set -e
          ZARF_ARCHITECTURE=amd64 uds run create-package3 --set FLAVOR=${FLAVOR}
  - name: package4
    description: Build and publish the packages
    actions:
      - description: Create the packages
        cmd: |
          set -e
          ZARF_ARCHITECTURE=amd64 uds run create-package4 --set FLAVOR=${FLAVOR}
#tasks.yaml
includes:
  - publish: ./tasks/publish.yaml
  - magic-import: ./tasks/magic-import.yaml
  - package: https://raw.githubusercontent.com/defenseunicorns/uds-common-tasks/v0.2.0/tasks/create.yaml

variables:
  - name: TARGET_REPO
    default: oci://ghcr.io/zachariahmiller/packages/uds

tasks:
  - name: var-no-worky
    actions:
      - task: publish:publish

  - name: magical-working-task
    actions:
      - cmd: echo "I'm working but i really shouldnt be"

  - name: create-package
    description: Create the Gitlab runner package
    actions:
      - cmd: echo "Parent task"
  - name: create-package2
    description: Create the Gitlab runner package
    actions:
      - task: magic-import:magic-task

  - name: create-package3
    description: Create the Gitlab runner package
    actions:
      - task: publish:package3

  - name: create-package4
    description: Create the Gitlab runner package
    actions:
      - task: publish:package2

Steps to reproduce

To test run uds run -f tasks/magic-import.yaml run-magic-root-task

tasks/magic-import.yaml is locally included in the root task

This says ERROR: Failed to run action: task name magical-working-task not found

That is expected behavior. Now run uds run -f tasks/publish.yaml package --set FLAVOR=upstream

Expected Result:

An error about there being no task called create-package as it is not explicitly imported

Actual Result:

package gets created

Then also try uds run -f tasks/publish.yaml package2 --set FLAVOR=upstream

This also shouldnt work but returns:

     I shouldnt work                                                                                                                       
  ✔  Completed "echo "I shouldnt work"" 

Then try uds run -f tasks/publish.yaml package3 --set FLAVOR=upstream

That goes in some circular death loop, which makes sense.

Then try uds run -f tasks/publish.yaml package4 --set FLAVOR=upstream

This works and also shouldnt:

  ⠋  Waiting for "echo "I shouldnt work"" (no timeout)                                                                                                             
     I shouldnt work                                                                                                            
  ✔  Completed "echo "I shouldnt work""                                                                                                    

  ✔  Completed "Create the packages"                                                                                                              
  ✔  Completed "Create the packages"    
decleaver commented 4 months ago

Its expecting and reading in the root Tasks.yaml

zachariahmiller commented 2 months ago

will have to do some follow up testing but im not sure this is still an issue. I had to add create imports into multiple publish tasks that failed recently. 😅

Racer159 commented 1 month ago

Confirmed this is still an issue - tasks should probably be namespaced internally to not conflict with one another.