[ci] Forbid CRLF and trailing whitespace in tracked files. - #937
Merged
Conversation
Add a small workflow that runs on `pull_request` and rejects two
classes of text-hygiene problems before they land:
- Any committed file with CRLF or mixed line endings, detected
via `git ls-files --eol`'s index column. Binary files get
`i/-text` and are skipped automatically. The check looks at
the index column rather than the working tree so a
contributor's local CRLF on a Windows checkout (without
`core.autocrlf` configured) doesn't trip CI -- only what
actually gets committed counts.
- Any trailing whitespace, conflict marker, or whitespace-style
error on a line the PR adds or changes, detected via
`git diff --check $base...HEAD`. This is the same logic git
uses to render whitespace warnings in `git diff` output, so
the message a contributor sees in CI matches what they would
see locally. Diff-scoped on purpose: ~30 files in the tree
have pre-existing trailing whitespace that we don't want to
touch in this PR; the rule applies to new additions only,
mirroring how `clang-format.yml` checks the diff rather than
the whole tree.
Checkout uses `fetch-depth: 0` and `ref: head.sha` so the diff
base (`pull_request.base.sha`) is in local history and HEAD points
at the PR tip rather than the synthetic merge ref.
Five files in the action set committed historically with CRLF
(`Install_Dependencies`, `Save_PR_Info`, `Select_Default_Build_Type`,
`Setup_Compiler` action.yml, plus `.github/pull_request_template.md`)
are normalized to LF in the same commit -- without the conversion
the new CRLF check would fail on its first run. The LF rewrite
makes every line of each file appear "added" in the diff, which
also surfaces two pre-existing trailing-whitespace lines
(`Install_Dependencies/action.yml:51`,
`Select_Default_Build_Type/action.yml:14`); strip those too so the
diff-scoped trailing-ws check passes as well.
A `.gitattributes` with `* text=auto eol=lf` would catch CRLF at
commit time on contributor machines and is a reasonable follow-up;
this CI check stays as the backstop regardless.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a small workflow that runs on
pull_requestand rejects two classes of text-hygiene problems before they land:git ls-files --eol's index column. Binary files geti/-textand are skipped automatically. The check looks at the index column rather than the working tree so a contributor's local CRLF on a Windows checkout (withoutcore.autocrlfconfigured) doesn't trip CI -- only what actually gets committed counts.git diff --check $base...HEAD. This is the same logic git uses to render whitespace warnings ingit diffoutput, so the message a contributor sees in CI matches what they would see locally. Diff-scoped on purpose: ~30 files in the tree have pre-existing trailing whitespace that we don't want to touch in this PR; the rule applies to new additions only, mirroring howclang-format.ymlchecks the diff rather than the whole tree.Checkout uses
fetch-depth: 0andref: head.shaso the diff base (pull_request.base.sha) is in local history and HEAD points at the PR tip rather than the synthetic merge ref.Five files in the action set committed historically with CRLF (
Install_Dependencies,Save_PR_Info,Select_Default_Build_Type,Setup_Compileraction.yml, plus.github/pull_request_template.md) are normalized to LF in the same commit -- without the conversion the new CRLF check would fail on its first run. The LF rewrite makes every line of each file appear "added" in the diff, which also surfaces two pre-existing trailing-whitespace lines (Install_Dependencies/action.yml:51,Select_Default_Build_Type/action.yml:14); strip those too so the diff-scoped trailing-ws check passes as well.A
.gitattributeswith* text=auto eol=lfwould catch CRLF at commit time on contributor machines and is a reasonable follow-up; this CI check stays as the backstop regardless.