Run a command if files are different.
# npm
npm i -S run-if-diff
# yarn
yarn add --dev run-if-diff
Exit with an exit code of 128
if matching files have changed, Exit with an exit code of 0
if no matching files have changed.
exit-if-diff [--since <ref>] [--file-path <glob>] [--file-status
<status>] [--exit-code-when-changed <number>] [--exit-code-when-unchanged <number>]
Example:
set +e
exit-if-diff --since v1.3.1 --file-path my-app.yml
set -e
if [ $? -eq 128 ]
aws cfn deploy --stack-name my-app --template-file my-app.yml
fi
List matching files that have changed.
list-if-diff [--since <ref>] [--file-path <glob>] [--file-status <status>]
Example:
list-if-diff --since v1.3.1 --file-path my-app.yml | xargs eslint
Run a command and passthru it's output if matching files have changed.
run-if-diff [--since <ref>] [--file-path <glob>] [--file-status <status>] -- <cmd>
Example:
run-if-diff --since v1.3.1 --file-path my-app.yml -- aws cfn deploy --stack-name my-app --template-file my-app.yml
Check whether files have changed in a pipeline.
steps:
- uses: actions/checkout@v2
- id: run-if-diff
uses: jameslnewell/run-if-diff@master
with:
cwd: .
since: previous-tag
file-path: |
apps/**/*.tsx
packages/**/*.tsx
file-status: |
A
M
- name: Get the ref
run: 'echo "ref: ${{ steps.run-if-diff.outputs.ref }}"'
- name: Get the file count
run: 'echo "count: ${{ steps.run-if-diff.outputs.count }}"'
- name: Get the file paths
run: 'echo -e "paths: \n${{ steps.run-if-diff.outputs.paths }}"'
- name: Conditional command
if: ${{ steps.run-if-diff.outputs.count > 0 }}
run: echo "Expensive command..."
Inspired by lerna
's --since
filter.
Copyright 2018 James Newell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.