Skip to content

Commit

Permalink
Add fail-if-changed option
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli committed Aug 21, 2023
1 parent 427c15b commit 2568af0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
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,18 @@ 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

else
echo "No changes found."

if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=files_changed::false"
else
Expand All @@ -67,3 +67,10 @@ else
fi

echo "::endgroup::"

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

0 comments on commit 2568af0

Please sign in to comment.