defenseunicorns / maru-runner

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

Allow a cmd to set the default value of a variable #81

Open corang opened 8 months ago

corang commented 8 months ago

Is your feature request related to a problem? Please describe

There are some variables that change depending on os/hardware that need to referenced in multiple places. The current solution is to have each task that needs this info reference a task that sets those variables. It would be really nice to be able to set default values for those vars in the variables field at the top of the tasks.yaml file

Current:

tasks:
  - name: build-zarf
    actions:
      - task: set-os-arch
      - cmd: |
          if [ -f ./zarf ] && [ "$(./zarf version)" = "${ZARF_VERSION}" ] ; then exit 0; fi
          echo "Downloading zarf"
          curl -sL https://github.com/defenseunicorns/zarf/releases/download/${ZARF_VERSION}/zarf_${ZARF_VERSION}_${PLATFORM}_${ARCH} -o ./zarf
          chmod +x ./zarf
        dir: build
  - name: set-os-arch
    actions:
      - cmd: |
          ARCH=$(uname -m)
          [ "$ARCH" = "x86_64" ] && ARCH="amd64"
          echo $ARCH
        setVariables:
          - name: ARCH
            sensitive: false
      - cmd: uname -s
        setVariables:
          - name: PLATFORM
            sensitive: false

Wanted:

variables:
  - name: PLATFORM
    defaultCmd:  uname -s
  - name: ARCH
    defaultCmd: |
          ARCH=$(uname -m)
          [ "$ARCH" = "x86_64" ] && ARCH="amd64"
          echo $ARCH
tasks:
  - name: build-zarf
    actions:
      - task: set-os-arch
      - cmd: |
          if [ -f ./zarf ] && [ "$(./zarf version)" = "${ZARF_VERSION}" ] ; then exit 0; fi
          echo "Downloading zarf"
          curl -sL https://github.com/defenseunicorns/zarf/releases/download/${ZARF_VERSION}/zarf_${ZARF_VERSION}_${PLATFORM}_${ARCH} -o ./zarf
          chmod +x ./zarf
        dir: build

Describe the solution you'd like

UncleGedd commented 8 months ago

Do you think this would be resolved by defenseunicorns/maru-runner#82 ? If we implemented the matrix functionality it sounds like it would solve the use case of referencing os/arch. cc @zachariahmiller

zachariahmiller commented 8 months ago

It seems like in a scenario where things would always be static that at least for things like platform/arch the matrix functionality would resolve the issue given in the example and also has a bunch of other helpful uses. That being said, I do like the idea of a variable defined in a uds run task file having the ability to have its default set with command in one line.

I think these things could coexist nicely in the task files.

UncleGedd commented 8 months ago

Outside of platform/arch, do you have an example of needing a reusable value that requires a bash script to set? I'm not opposed to the idea, I think the runner lends itself to more freedom/flexibility, just want to understand the use case (again outside of platform/arch)

zachariahmiller commented 8 months ago

off the top of my head, possibly generating a cert, a random string (say for node token or unique naming) or something like that.

UncleGedd commented 8 months ago

👍 feel free to implement @corang, thanks for the inputs @zachariahmiller

oates commented 1 month ago

@corang doing some backlog grooming this morning. Is this issue still something you need/want?

corang commented 1 month ago

I'd say yes, I dont necessarily have a use case for it right now but i think it's a valuable feature