Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for fail-if-unchanged #395

Merged
merged 8 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -243,4 +243,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::"
Loading