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

Add fail-if-changed option #321

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ jobs:
run: |
echo "Changed files (Not expected): ${{ steps.changed_files_not_expected.outputs.changed_files }}"
exit 1
- name: Test dont fail if not changed
uses: ./
id: changed_files_not_expected_fail
with:
fail-if-changed: true
files: |
test/*.txt
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Make changes
run: |
printf '%s\n' "323442" "424" >> test/new.txt
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ inputs:
description: 'Indicates whether to match files in `.gitignore`'
default: "false"
required: true
fail-if-changed:
description: 'Indicates whether to fail if 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."
required: false

outputs:
files_changed:
Expand Down Expand Up @@ -50,6 +58,8 @@ runs:
INPUT_FILES_PATTERN_FILE: ${{ steps.glob.outputs.paths-output-file }}
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 }}

branding:
icon: file-text
Expand Down
13 changes: 10 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,25 @@ if [[ -n "$CHANGED_FILES" ]]; then
echo "Found uncommited changes"

CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')

if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=files_changed::true"
echo "::set-output name=changed_files::$CHANGED_FILES"
else
echo "files_changed=true" >> "$GITHUB_OUTPUT"
echo "changed_files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
fi


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

else
echo "No changes found."

if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=files_changed::false"
else
Expand Down
Loading