Skip to content

Convert Actions Expression Array into a bash array

ChristopherHX edited this page Dec 5, 2022 · 1 revision

This snippet uses the join function to initialize a bash array with matrix.args as long no line contains EOF as the only word

on: push
jobs:
  _:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
        - args:
          - test with space
          - another test
          - |
              my multiline input
              Help Me
              True tragic              
    steps:
    - run: |
        args=(${{ matrix.args[0] && format('"$(cat << "EOF"
        {0}
        EOF
        )"', join(matrix.args, '
        EOF
        )" "$(cat << "EOF"
        ')) || ''}})
        # You have your bash array args from the matrix key
        echo "${args[@]}"