I am trying to take output from dorny/paths-filter@v2 which is actually a list of files that got changed, and use it as a multiple input for Strategy matrix in Github Actions.
Although i see relevant file path that got changed, which looks something like "aws/dev/something/yo.yaml" for eg. in the plugins output, but the strategy matrix just dont like it and throws errors like
Error when evaluating 'strategy' for job 'deploy'. .github/workflows/main.yaml (Line: 59, Col: 15): Error parsing fromJson,.github/workflows/main.yaml (Line: 59, Col: 15): Unexpected character encountered while parsing value: a. Path '', line 0, position 0.,.github/workflows/main.yaml (Line: 59, Col: 15): Unexpected value ''
My Github Action file
name: Yo
on:
push:
branch:
- main
jobs:
changes:
runs-on: ubuntu-latest
outputs:
files: ${{ steps.filter.outputs.aws_files }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
base: ${{ github.ref }}
list-files: 'escape'
filters: |
aws:
- added|modified: 'aws/**'
deploy:
runs-on: ubuntu-latest
needs: changes
strategy:
matrix:
file: ${{fromJson(needs.changes.outputs.files)}}
fail-fast: false
steps:
- name: Lets See
env:
file: ${{matrix.file}}
run: |
echo ${{env.file}}
Tried multiple option of the plugin like shell, csv but no luck
The issue is that strategy matrix expects the response from fromJSON
to be an array. That's not happening here, and hence the error.
So you need to make sure dorny/paths-filter@v2
send back the list of files formatted as a JSON array.
- uses: dorny/paths-filter@v2
id: filter
with:
base: ${{ github.ref }}
list-files: 'json'
filters: |
aws:
- added|modified: 'aws/**'
Notice that list-files: 'json'
instead of list-files: 'escape'
.