Skip to content

Commit

Permalink
Added support for fail-if-unchanged (#395)
Browse files Browse the repository at this point in the history
Co-authored-by: Tonye Jack <[email protected]>
  • Loading branch information
Larspolo and jackton1 authored May 4, 2024
1 parent 64d825d commit 6a0d0b6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ jobs:
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Test fail if changed
uses: ./
id: unchanged_files_expected_fail
continue-on-error: true
with:
fail-if-unchanged: true
files: |
test/*.txt
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Make changes
run: |
printf '%s\n' "323442" "424" >> test/new.txt
Expand Down Expand Up @@ -99,6 +110,16 @@ jobs:
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Test dont fail if changed and fail-if-unchanged is true
uses: ./
id: unchanged_files_not_expected_fail
with:
fail-if-unchanged: true
files: |
test/*.txt
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Generate an unstaged file
run: |
echo "New changes" > unstaged.txt
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
12 changes: 9 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ inputs:
description: 'Indicates whether to fail if files have changed.'
default: "false"
required: false
fail-if-unchanged:
description: 'Indicates whether to fail if no files have changed.'
default: "false"
required: false
fail-message:
description: 'Message to display when files have changed and the `fail-if-changed` input is set to `true`.'
default: "Files have changed."
description: 'Message to display when `fail-if-changed` or `fail-if-unchanged` is set to `true`.'
default: ""
required: false
safe_output:
description: "Apply sanitization to output filenames before being set as output."
Expand Down Expand Up @@ -65,6 +69,7 @@ runs:
read-gitignore: ${{ inputs.read-gitignore }}
match-gitignore-files: ${{ inputs.match-gitignore-files }}
safe-output: ${{ inputs.safe_output }}

- run: |
bash $GITHUB_ACTION_PATH/entrypoint.sh
id: verify-changed-files
Expand All @@ -78,7 +83,8 @@ runs:
INPUT_SEPARATOR: ${{ inputs.separator }}
INPUT_MATCH_GITIGNORE_FILES: ${{ inputs.match-gitignore-files }}
INPUT_FAIL_IF_CHANGED: ${{ inputs.fail-if-changed }}
INPUT_FAIL_MSG: ${{ inputs.fail-message }}
INPUT_FAIL_IF_UNCHANGED: ${{ inputs.fail-if-unchanged }}
INPUT_FAIL_MSG: ${{ inputs.fail-message || (inputs.fail-if-changed == 'true' && 'Files have changed.' || 'Files have not changed.') }}
INPUT_SAFE_OUTPUT: ${{ inputs.safe_output }}
INPUT_PATH: ${{ inputs.path }}
INPUT_QUOTEPATH: ${{ inputs.quotepath }}
Expand Down
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ if [[ -n "$CHANGED_FILES" ]]; then
else
echo "No changes found."
echo "files_changed=false" >> "$GITHUB_OUTPUT"

if [[ "$INPUT_FAIL_IF_UNCHANGED" == "true" ]]; then
if [[ -n "$INPUT_FAIL_MSG" ]]; then
echo "$INPUT_FAIL_MSG"
fi
exit 1
fi
fi

echo "::endgroup::"

0 comments on commit 6a0d0b6

Please sign in to comment.