diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9fdd201..695881b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/action.yml b/action.yml index ded1993..1577e01 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh index a59fb84..66b67cf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,7 +47,7 @@ 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" @@ -55,10 +55,10 @@ if [[ -n "$CHANGED_FILES" ]]; then 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 @@ -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