How to overcome a failing command that is doing what is intended

I have a workflow that is getting a SLOC count for our repo. One fot he first steps in the workflow is

 - name: Count and List all files
        # wc creates very many errors for all directories
        # This leaves the workflow in an error state
        run: |
          find . -name '*.*' | xargs wc -l > allFiles.txt

This executes correctly creating a file in the format

   13 somefile.txt
   72 other.file

This is EXACTLY what I want, but it also creates error messages related to the directories and some odd file names.

wc: .: Is a directory
wc: ./.github: Is a directory
wc: ./.git: Is a directory
wc: ./examples/cpp/.github: Is a directory
wc: ./html/imgs/Delete: No such file or directory
wc: Branch.png: No such file or directory

I have put if: ${{always}} tags on each of the subsequent steps and the whole workflow is doing what I want, but it still shows as a red x in our actions. I’d like to find some way to ensure it reports a pass instead of a fail. I don’t know how to force that. Help please

The best way would be to change the find command to ignore directories and the broken files. I’m a little confused why find would report files that then don’t exist, are those broken symlinks? You could do something like

find . -name '*.*' -type f

to get only regular files. Also you could remove the name filter: It matches any name including a dot, and you’re searching “.”, so it will match everything.

Technically you could also add || true at the end of the command to completely ignore errors, but I’d caution against that because it ignores ALL errors, not just the ones you decided don’t matter.

1 Like

I will try that. One of our devs uploaded text files with windows style names. The spaces are throwing things off.

Hi @bsdillon,

You can use find options to exclude some specific directories and files, only filter for files…etc.

Please try below command:

      - name: Count and List all files
        run: |
          find . -type d \( -path ./.git -o -path ./.github -o -path ./examples -o -path ./html \) -prune -false -o -type f ! -name "Branch.png" | xargs wc -l > allFiles.txt

My workflow here for your reference.

You can also add jobs.<job_id>.continue-on-error to ignore the error if you decided it doesn’t matter.