diff --git a/.github/workflows/check-eol.yml b/.github/workflows/check-eol.yml index fa53184..8725785 100644 --- a/.github/workflows/check-eol.yml +++ b/.github/workflows/check-eol.yml @@ -30,19 +30,16 @@ jobs: ref: ${{ inputs.checkout-ref }} - name: Check End-of-Line Sequence + env: + DEFAULT_EOL: ${{ inputs.default-eol }} run: | exit_code=0 while IFS= read line; do - if [[ $line =~ ^i/([^ ]*)\ +w/([^ ]*)\ +attr/([^[:space:]]+( eol=([[:alpha:]]+))?)?\ +$'\t'(.+)$ ]] ; then + if [[ $line =~ ^i/([^ ]*)\ +w/[^\ ]*\ +attr/[^$'\t']+$'\t'(.+)$ ]] ; then index_eol=${BASH_REMATCH[1]} - working_tree_eol=${BASH_REMATCH[2]} - expected_eol=${BASH_REMATCH[5]:-${{ inputs.default-eol }}} - if { [ "$index_eol" == "lf" ] || [ "$index_eol" == "crlf" ] || [ "$index_eol" == "mixed" ] ; } && [ "$index_eol" != "$expected_eol" ] ; then - echo "${BASH_REMATCH[6]}:"$'\t'"End-of-line sequence in index($index_eol) does not match expected end-of-line sequence $expected_eol." - exit_code=1 - elif { [ "$working_tree_eol" == "lf" ] || [ "$working_tree_eol" == "crlf" ] || [ "$working_tree_eol" == "mixed" ] ; } && [ "$working_tree_eol" != "$expected_eol" ] ; then - echo "${BASH_REMATCH[6]}:"$'\t'"End-of-line sequence in working tree($working_tree_eol) does not match expected end-of-line sequence $expected_eol." + if [ "$index_eol" != $DEFAULT_EOL ] ; then + echo "${BASH_REMATCH[2]}:"$'\t'"End-of-line sequence in index($index_eol) must be LF." exit_code=1 fi else diff --git a/README.md b/README.md index 860f230..119b051 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ jobs: ## Usage ### Default End-of-Line Sequence -The workflow uses `LF` as the fallback end-of-line sequence. The default end-of-line sequence can be configured either through [`.gitattributes`](https://www.git-scm.com/docs/gitattributes) or through the parameter `default-eol`. The following example sets the fallback end-of-line sequence to `CRLF`. +The workflow enforces `LF` for all files in the index. `autocrlf=true` modifies files in the working tree rather than the index and thus does not affect the workflow. The following example configures the workflow to enforce `CRLF` instead. ```yml jobs: check-eol: diff --git a/docs/Test_List.md b/docs/Test_List.md index f9c01ec..b87d203 100644 --- a/docs/Test_List.md +++ b/docs/Test_List.md @@ -5,61 +5,28 @@ A list of steps for testing the workflow's features. ### Steps 1. Create the following files, - - `lf-lf.txt` - A file containing one LF. - - `lf-crlf.txt` - A file containing one CRLF. - - `lf-mixed.txt` - A file containing one LF and one CRLF. - - `crlf-lf.txt` - A file containing one LF. - - `crlf-crlf.txt` - A file containing one CRLF. - - `crlf-mixed.txt` - A file containing one LF and one CRLF. + - `lf.txt` - A file containing one LF. + - `crlf.txt` - A file containing one CRLF. + - `mixed.txt` - A file containing one LF and one CRLF. 1. Create or copy a binary file, such as an image or an archive. 1. Run the command `git config core.autocrlf false` -1. Create a file named `.gitattributes` with the following contents, - ```ini - lf-*.txt text eol=lf - crlf-*.txt text eol=crlf - ``` -1. All other files created such as `.gitattributes` and workflow files must be using the LF end-of-line sequence. +1. All other files created such as workflow files must be using the LF end-of-line sequence. 1. Commit and push to GitHub. ### Outputs 1. Workflow triggers. 1. Workflow fails. 1. The workflow should flag the following files, - - `lf-crlf.txt`. - - `lf-mixed.txt`. - - `crlf-lf.txt`. - - `crlf-mixed.txt`. + - `crlf.txt`. + - `mixed.txt`. 1. The workflow should not flag the following files, - - `lf-lf.txt`. - - `crlf-crlf.txt`. + - `lf.txt`. - The binary file. -## Action respects `.gitattributes` - -### Steps -1. Replace the contents of the file named `.gitattributes` with the following, - ```ini - *-lf.txt text eol=lf - *-crlf.txt text eol=crlf - ``` -1. Remove the files ending in `mixed`. -1. Commit and push to GitHub. - -### Outputs -1. Workflow triggers. -1. Workflow succeeds. - ## Action succeeds when non-compliant files are fixed ### Steps -1. Replace the contents of the file named `.gitattributes` with the following, - ```ini - lf-*.txt text eol=lf - crlf-*.txt text eol=crlf - ``` -1. Restore the files ending in `mixed`. -1. Replace all non-LF end-of-line sequences with LF in files starting with `lf-*`. -1. Replace all non-CRLF end-of-line sequences with CRLF in files starting with `crlf-*`. +1. Replace all non-LF end-of-line sequences with LF in flagged files. ### Outputs 1. Workflow triggers. diff --git a/test/respects_gitattributes/.gitattributes b/test/respects_gitattributes/.gitattributes deleted file mode 100644 index d36e4fc..0000000 --- a/test/respects_gitattributes/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -lf.txt text eol=lf -crlf.txt text eol=crlf diff --git a/test/respects_gitattributes/crlf.txt b/test/respects_gitattributes/crlf.txt deleted file mode 100644 index d3f5a12..0000000 --- a/test/respects_gitattributes/crlf.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/respects_gitattributes/lf.txt b/test/respects_gitattributes/lf.txt deleted file mode 100644 index 8b13789..0000000 --- a/test/respects_gitattributes/lf.txt +++ /dev/null @@ -1 +0,0 @@ -