dorny / paths-filter

Conditionally run actions based on files modified by PR, feature branch or pushed commits
MIT License
2.14k stars 239 forks source link

Passing changed file list to a python script #102

Closed arielelkin closed 3 years ago

arielelkin commented 3 years ago

I have a Python script which should process each file that has been changed in a PR. Here's my yml file:

jobs: 
  process-files:
    name: Process files
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - uses: dorny/paths-filter@v2
      id: filter
      with:
        list-files: json
        filters: |
          changed:
            - '**'
    - name: Process changed files
      run: |
        echo "${{ steps.filter.outputs.changed_files }}"
        python process.py

In the run step, the first echo correctly prints all the changed files. However, when I try to print them from within process.py:

import os
os.system("echo \" ${{ steps.filter.outputs.changed_files }} \" ")

I get a sh: 1: Bad substitution error

Any ideas?

arielelkin commented 3 years ago
jobs: 
  process-files:
    name: Process files
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - uses: dorny/paths-filter@v2
      id: filter
      with:
        list-files: json
        filters: |
          changed:
            - '**'
    - name: Process changed files
      run: |
        python process.py '${{ steps.filter.outputs.changed_files }}'

And then in process.py:

new_files = list(json.loads(sys.argv[1]))