Run job on every file a bash script outputs

Hi all,

in one step of my Action I execute a shell script, which gives me a list of certain files as output.
I now want to run another step for each of those files, so that I can access certain contents of the file.
Example:

My script outputs the following:

some-file.txt, some-information, other-information
some-file-2.txt, some-information-2, other-information-2

Now I want to create a step like this:

- name: blah
  uses: ...
  with:
    username: ${{ some-information }}
    password: ${{ other-information }}
    filename: ${{ some-file.txt }}

Hi @LorenzBung,

Which action do you use for the step? If it cannot read the whole filelist, the action cannot run for each of those files.
I’d prefer to pipe the filelist to a json file which has below format:

[
	{
	 "filename": "some-file.txt", 
	 "username": "some-information", 
	 "password": "other-information"
	},
	{
	 "filename": "some-file-2.txt", 
	 "username": "some-information-2", 
	 "password": "other-information-2"
	}
]

And in the action, read the json file and parse the values, use a loop to deal with the related stuff.

- name: blah
  uses: ...
  with: 
     file: filelist.json

Thanks.

Hi, thank you for your answer.

When I push certain files in my repo (in a certain directory, filename, certain content etc.) I want to send an email using dawidd6/action-send-mail@v2.
That’s the reason I can’t put a filelist in the call of the action.

Hi @LorenzBung,

Thanks for your reply. Steps are executed in sequence in Github Action, so if you’d like to specify different values for the action dawidd6/action-send-mail@v2, you need to use matrix.
Code sample:

        uses: dawidd6/action-send-mail@v2
        with:
          server_address: smtp.gmail.com
          server_port: 465
          username: ${{ matrix.username }}
          password: ${{ matrix.password }}
          attachments: ${{ matrix.filename }}
          .....

Use two jobs:
The 1st jobs to get the file list and set the matrix value, transfer to the next job.
The 2nd jobs get the matrix and use the matrix value for the action, it will be dynamic according to your output in job1.
I tried below code:

name: matrix jobs
on: [push]
jobs:
  job1:
    outputs: 
      matrix: ${{ steps.files.outputs.matrix }}
    runs-on: [ubuntu-latest]
    steps:
      - name: set the file list
        id: files
        run: |
          echo "::set-output name=matrix::{\"include\":[{\"filename\":\"some-file.txt\",\"username\":\"some-information\",\"password\":\"other-information\"},{\"filename\":\"some-file-2.txt\",\"username\":\"some-information-2\",\"password\":\"other-information-2\"}]}"
  job2:
    needs: [job1]    
    runs-on: [ubuntu-latest]
    strategy:
      matrix: ${{fromJson(needs.job1.outputs.matrix)}}
      
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: execute
        run: |
          echo ${{ matrix.filename }}
          echo ${{ matrix.username }}
          echo ${{ matrix.password }}

The value has been successfully got in each jobs. Please refer to my workflow for your reference.

Thanks