Skip to content

[ci] Forbid CRLF and trailing whitespace in tracked files. - #937

Merged
vgvassilev merged 1 commit into
compiler-research:mainfrom
vgvassilev:ci-no-crlf
Apr 26, 2026
Merged

[ci] Forbid CRLF and trailing whitespace in tracked files.#937
vgvassilev merged 1 commit into
compiler-research:mainfrom
vgvassilev:ci-no-crlf

Conversation

@vgvassilev

Copy link
Copy Markdown
Contributor

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.

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.
@vgvassilev
vgvassilev merged commit 306b4d3 into compiler-research:main Apr 26, 2026
5 of 25 checks passed
@vgvassilev
vgvassilev deleted the ci-no-crlf branch April 26, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant