loop through list of files

how would i loop through a list of files and run a workflow on each file?
say i have a list of files in yaml:

<font face="courier new,courier"> files:
    scss: [fileone.scss,file2.sass]
    prettify: [codeone.js,code2.json]</font>

on the scss files i must run one workflow that compiles them into css, and the one that prettifies them. and on the prettify files i just have to run the prettifier workflow. How would i loop through an array and pass it to a workflow so i can reference it with something like:

${{ vars.FILE }}

You could set them as environment variables and use shell commands to loop over them, e.g. (Linux shell syntax, might be different on other platforms):

  - name: run loop
      FILES: a.scss b.scss
    run: for f in $FILES; do [YOUR COMMAND HERE]; done

Though I think it might be better to use a build tool (e.g. make or whatever else suits your project) for this, or to add a script to your repository that does the processing based on parameters or even automatically discovered input.

I’m not sure how you compile the scss files into css, but ‘jobs.<job_id>.strategy.matrix’ could be an option for you.


im using:

- name: Sass Build
        uses: gha-utilities/sass-build@v0.1.6

to build it

using this, how would i call a github action using a consle command?

Hi @vortetty ,

action ‘gha-utilities/sass-build’ has defined inputs ‘source’ and ‘destination’, you can use matrix value for them.

Code sample as below:

        scssfiles: [fileone,file2]
    runs-on: [ubuntu-latest]
      - name: test
        run: |
          echo ${{ matrix.scssfiles }}.scss
      - uses: actions/checkout@v1
      - name: Compile .css from .scss
        uses: gha-utilities/sass-build@v0.1.6
          source: scss/${{ matrix.scssfiles }}.scss
          destination: css/${{ matrix.scssfiles }}.css

It will complie the two scss files seperately into css folder. Hope it helps.

Perfect, thank you!

what language it is for “for” loop?

I guess you mean this? That’s sh (Unix/Linux shell). By default run: commands run in such a shell on Linux runners.