Pass list of variables to shell script in GitHub Actions

See here for the original answer.

Today I was able to do this with the following YAML (truncated):

...
with:
  targets: |
    FolderA/SubfolderA
    FolderB/SubfolderB

The actual GitHub Action passes this as an argument like the following:

runs:
  using: docker
  image: Dockerfile
  args:
    - "${{ inputs.targets }}"

What this does is simply sends the parameters as a string with the newline characters embedded, which can then be iterated over similar to an array in a POSIX-compliant manner via the following shell code:

#!/bin/sh -l

targets="${1}"

for target in $targets
do
  echo "Proof that this code works: $target"
done

Which should be capable of accomplishing your desired task, if I understand the question correctly. You can always run something like sh ./script.sh $target in the loop if your use case requires it.


Tags

  1. github-actions (Private)
  2. shell (Private)
  3. yaml (Private)
  4. stack-overflow (Private)
  5. answer (Private)