I have a CircleCI step that takes up a list of changed files on a git PR, checks for specific extensions, and then runs a command on each of those files, it looks something like this:
command: |
git diff main..$(git branch --show-current) --name-only --diff-filter=d | grep '(.rb|.rake)$' | xargs --no-run-if-empty bundle exec rubocop -a
Basically, the first portion of the command (git diff -> grep) will give xargs a list of file names. However, if this list is empty xargs --no-run-if-empty
will not run the command at all. When this scenario happens, it returns a code 1 on CircleCI which fails the step. How can I make it so it returns 0 on that case?
Cold Penguin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.