diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b155556..de8a1e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,6 +53,17 @@ jobs: test/*.sql test/**/*.txt test/**/*.sql + - name: Test fail if changed + 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 @@ -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: unchanged_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 diff --git a/README.md b/README.md index 9d57cf2..89e6c61 100644 --- a/README.md +++ b/README.md @@ -243,4 +243,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d -This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! \ No newline at end of file diff --git a/action.yml b/action.yml index ce0d099..604e0cf 100644 --- a/action.yml +++ b/action.yml @@ -25,9 +25,13 @@ 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`.' - default: "Files have changed." + description: 'Message to display when `fail-if-changed` or `fail-if-unchanged` is set to `true`.' + default: "" required: false safe_output: description: "Apply sanitization to output filenames before being set as output." @@ -65,6 +69,7 @@ runs: read-gitignore: ${{ inputs.read-gitignore }} match-gitignore-files: ${{ inputs.match-gitignore-files }} safe-output: ${{ inputs.safe_output }} + - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh id: verify-changed-files @@ -78,7 +83,8 @@ runs: 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 }} + INPUT_FAIL_IF_UNCHANGED: ${{ inputs.fail-if-unchanged }} + INPUT_FAIL_MSG: ${{ inputs.fail-message || (inputs.fail-if-changed == 'true' && 'Files have changed.' || 'Files have not changed.') }} INPUT_SAFE_OUTPUT: ${{ inputs.safe_output }} INPUT_PATH: ${{ inputs.path }} INPUT_QUOTEPATH: ${{ inputs.quotepath }} diff --git a/entrypoint.sh b/entrypoint.sh index 3172a0a..2c66d12 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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::"