0

I am using Github Action to run pylint, I have a list of modified files and need to check if they are blank or not, if they are blank then skip them, how do I do this?

Part of Action:

   - name: Get modified files
      id: files
      uses: umani/changed-files@v3.3.0
      with:
        repo-token: ${{ github.token }}
        pattern: '^src.*\.(py)$'
        result-encoding: 'string'
    - name: Check files size
      id: file_check
      run: |
        echo "file_size="$(printf "%s" "${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}" | wc -m) >> $GITHUB_ENV
        echo 'MESSAGE=No valid file found, skipped' >> $GITHUB_ENV
    - name: Lint with pylint
      if: env.file_size > 1
      working-directory: ./
      run: |
        pip install pylint
        OUTPUT=$(pylint ${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}  --exit-zero --jobs=0 --rcfile=.pylintrc)
        LAST_LINE=$(tail -1 <<< "$OUTPUT")
        SCORE=$(sed -n '$s/[^0-9-]*\([-0-9.]*\).*/\1/p' <<< "$OUTPUT")
        OUTPUT=$(echo "$OUTPUT" | sed -e '20{$!N;s/\n.*/\n\n\n... results too long, run pylint locally to get full result/' -e 'q}')
        OUTPUT+=".  Pylint finished with score: $SCORE"
        echo  "SCORE=$SCORE"  >> $GITHUB_ENV
        echo 'MESSAGE<<EOF' >> $GITHUB_ENV
        echo  "$OUTPUT"  >> $GITHUB_ENV
        echo 'EOF' >> $GITHUB_ENV

So what I need to do is loop the variables ${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}" which are currently encoded as comma separated strings. And check if that file is blank or not, then create a new list with non-blank files, how do I do this?

Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174

1 Answers1

0

You can try something like this

IFS=, read -a fa <<<"${{ steps.files.outputs.files_updated }}"

declare -a fe fne

for f in "${fa[@]}"
do
    if [[ -s "$f" ]]
    then
        fne+=( "$f" )
    else
        fe+=( "$f" )
    fi
done

# fne: non-empty files
# fe: empty files

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134