Skip to content

Commit

Permalink
Add fail-if-changed option (#321)
Browse files Browse the repository at this point in the history
* Add `fail-if-changed` option

* Update entrypoint.sh

* Update test.yml

---------

Co-authored-by: Tonye Jack <jtonye@ymail.com>
  • Loading branch information
Minecraftschurli and jackton1 authored Aug 29, 2023
1 parent 6693935 commit 167811b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
21 changes: 21 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 All @@ -67,6 +77,17 @@ jobs:
run: |
echo "No Changes found: (Not expected)"
exit 1
- name: Test fail if changed
uses: ./
id: changed_files_expected_fail
continue-on-error: true
with:
fail-if-changed: true
files: |
test/*.txt
test/*.sql
test/**/*.txt
test/**/*.sql
- name: Generate an unstaged file
run: |
echo "New changes" > unstaged.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

0 comments on commit 167811b

Please sign in to comment.