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 1 commit
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
27 changes: 24 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,27 @@ jobs:
run: |
echo "Changed files (Not expected): ${{ steps.changed_files_not_expected.outputs.changed_files }}"
exit 1
- name: Test dont fail if not changed
- name: Test dont fail if not changed and fail-if-changed is true
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
uses: ./
id: changed_files_not_expected_fail
id: unchanged_files_not_expected_fail
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
with:
fail-if-changed: true
files: |
test/*.txt
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Test fail if changed and fail-if-unchanged is true
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 @@ -88,7 +99,7 @@ jobs:
run: |
echo "No Changes found or missing changed files: (Not expected)"
exit 1
- name: Test fail if changed
- name: Test fail if changed and fail-if-changed is true
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
uses: ./
id: changed_files_expected_fail
continue-on-error: true
Expand All @@ -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: changed_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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ Support this project with a :star:
# Default: "false"
fail-if-changed: ''

# Message to display when files have changed and the
# `fail-if-changed` input is set to `true`.
# Indicates whether to fail if no files have changed.
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
# Type: boolean
# Default: "false"
fail-if-unchanged: ''

# Message to display when `fail-if-changed` or
# `fail-if-unchanged` is set to `true` and triggered.
# Type: string
# Default: "Files have changed."
fail-message: ''
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ 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`.'
description: 'Message to display when `fail-if-changed` or `fail-if-unchanged` is set to `true` and triggered.'
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
default: "Files have changed."
required: false
safe_output:
Expand Down Expand Up @@ -73,6 +77,7 @@ runs:
INPUT_SEPARATOR: ${{ inputs.separator }}
INPUT_MATCH_GITIGNORE_FILES: ${{ inputs.match-gitignore-files }}
INPUT_FAIL_IF_CHANGED: ${{ inputs.fail-if-changed }}
INPUT_FAIL_IF_UNCHANGED: ${{ inputs.fail-if-unchanged }}
INPUT_FAIL_MSG: ${{ inputs.fail-message }}
INPUT_SAFE_OUTPUT: ${{ inputs.safe_output }}
INPUT_PATH: ${{ inputs.path }}
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::"