Skip to content

Commit 306b4d3

Browse files
authored
[ci] Forbid CRLF and trailing whitespace in tracked files. (#937)
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.
1 parent 45437f8 commit 306b4d3

6 files changed

Lines changed: 298 additions & 236 deletions

File tree

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
name: 'Install Dependencies'
2-
description: 'This PR installs the dependencies needed'
3-
4-
runs:
5-
using: composite
6-
steps:
7-
8-
- name: Install dependencies on MacOS
9-
if: runner.os == 'macOS'
10-
shell: bash
11-
run: |
12-
brew update --force
13-
if [[ "$(uname -m)" == "x86_64" ]]; then
14-
brew remove swiftlint
15-
else
16-
brew remove unxip
17-
fi
18-
# workaround for https://github.com/actions/setup-python/issues/577
19-
for pkg in $(brew list | grep '^python@'); do
20-
brew unlink "$pkg"
21-
brew link --overwrite "$pkg"
22-
done
23-
brew install ninja
24-
brew install eigen
25-
brew install boost
26-
brew install gnu-sed
27-
pip install distro pytest
28-
29-
- name: Install dependencies on Linux
30-
if: runner.os == 'Linux' && runner.environment != 'self-hosted'
31-
shell: bash
32-
run: |
33-
# Install deps
34-
sudo apt-get update
35-
sudo apt-get install valgrind ninja-build
36-
sudo apt-get install git g++ debhelper devscripts gnupg python3 doxygen graphviz python3-sphinx
37-
sudo apt-get install -y libc6-dbg
38-
sudo apt autoremove
39-
sudo apt clean
40-
# Install libraries used by the cppyy test suite
41-
sudo apt install libeigen3-dev
42-
sudo apt install libboost-all-dev
43-
44-
45-
- name: Install dependencies on Windows
46-
if: runner.os == 'Windows'
47-
shell: powershell
48-
run: |
49-
choco install findutils
50-
$env:PATH="C:\Program Files (x86)\GnuWin32\bin;$env:PATH"
51-
1+
name: 'Install Dependencies'
2+
description: 'This PR installs the dependencies needed'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
8+
- name: Install dependencies on MacOS
9+
if: runner.os == 'macOS'
10+
shell: bash
11+
run: |
12+
brew update --force
13+
if [[ "$(uname -m)" == "x86_64" ]]; then
14+
brew remove swiftlint
15+
else
16+
brew remove unxip
17+
fi
18+
# workaround for https://github.com/actions/setup-python/issues/577
19+
for pkg in $(brew list | grep '^python@'); do
20+
brew unlink "$pkg"
21+
brew link --overwrite "$pkg"
22+
done
23+
brew install ninja
24+
brew install eigen
25+
brew install boost
26+
brew install gnu-sed
27+
pip install distro pytest
28+
29+
- name: Install dependencies on Linux
30+
if: runner.os == 'Linux' && runner.environment != 'self-hosted'
31+
shell: bash
32+
run: |
33+
# Install deps
34+
sudo apt-get update
35+
sudo apt-get install valgrind ninja-build
36+
sudo apt-get install git g++ debhelper devscripts gnupg python3 doxygen graphviz python3-sphinx
37+
sudo apt-get install -y libc6-dbg
38+
sudo apt autoremove
39+
sudo apt clean
40+
# Install libraries used by the cppyy test suite
41+
sudo apt install libeigen3-dev
42+
sudo apt install libboost-all-dev
43+
44+
45+
- name: Install dependencies on Windows
46+
if: runner.os == 'Windows'
47+
shell: powershell
48+
run: |
49+
choco install findutils
50+
$env:PATH="C:\Program Files (x86)\GnuWin32\bin;$env:PATH"
51+
Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
name: 'Save PR Info'
2-
description: 'This PR saves the PR Info for the job'
3-
4-
runs:
5-
using: composite
6-
steps:
7-
8-
- name: Save PR Info on Unix Systems
9-
if: ${{ runner.os != 'Windows' }}
10-
shell: bash
11-
run: |
12-
mkdir -p ./pr
13-
echo ${{ github.event.number }} > ./pr/NR
14-
echo ${{ github.repository }} > ./pr/REPO
15-
16-
cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]')
17-
if [[ "$cling_on" == "ON" ]]; then
18-
export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version || env.CLING_VERSION }} | tr '\t' '-')
19-
export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm${{ matrix.clang-runtime}} | tr '\t' '-')
20-
else
21-
export CLING_HASH="Repl"
22-
# May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x
23-
# which could be quite often for new releases
24-
export LLVM_HASH=$(git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x | tr '\t' '-')
25-
fi
26-
27-
echo "CLING_HASH=$CLING_HASH" >> $GITHUB_ENV
28-
echo "LLVM_HASH=$LLVM_HASH" >> $GITHUB_ENV
29-
30-
- name: Save PR Info on Windows systems
31-
if: runner.os == 'Windows'
32-
shell: powershell
33-
run: |
34-
#can be found
35-
mkdir ./pr
36-
echo "${{ github.event.number }}" > ./pr/NR
37-
echo ${{ github.repository }} > ./pr/REPO
38-
39-
if ( "${{ matrix.cling }}" -imatch "On" )
40-
{
41-
$env:CLING_HASH_TEMP = ( git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version || env.CLING_VERSION }} )
42-
$env:CLING_HASH = $env:CLING_HASH_TEMP -replace "\t","-"
43-
}
44-
else
45-
{
46-
$env:CLING_HASH="Repl"
47-
# May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x
48-
# which could be quite often for new releases
49-
$env:LLVM_HASH_TEMP = (git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x )
50-
$env:LLVM_HASH = $env:LLVM_HASH_TEMP -replace "\t","-"
51-
}
52-
53-
echo "CLING_HASH=$env:CLING_HASH"
54-
echo "LLVM_HASH=$env:LLVM_HASH"
55-
56-
echo "CLING_HASH=$env:CLING_HASH" >> $GITHUB_ENV
57-
echo "LLVM_HASH=$env:LLVM_HASH" >> $GITHUB_ENV
58-
1+
name: 'Save PR Info'
2+
description: 'This PR saves the PR Info for the job'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
8+
- name: Save PR Info on Unix Systems
9+
if: ${{ runner.os != 'Windows' }}
10+
shell: bash
11+
run: |
12+
mkdir -p ./pr
13+
echo ${{ github.event.number }} > ./pr/NR
14+
echo ${{ github.repository }} > ./pr/REPO
15+
16+
cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]')
17+
if [[ "$cling_on" == "ON" ]]; then
18+
export CLING_HASH=$(git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version || env.CLING_VERSION }} | tr '\t' '-')
19+
export LLVM_HASH=$(git ls-remote https://github.com/root-project/llvm-project.git cling-llvm${{ matrix.clang-runtime}} | tr '\t' '-')
20+
else
21+
export CLING_HASH="Repl"
22+
# May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x
23+
# which could be quite often for new releases
24+
export LLVM_HASH=$(git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x | tr '\t' '-')
25+
fi
26+
27+
echo "CLING_HASH=$CLING_HASH" >> $GITHUB_ENV
28+
echo "LLVM_HASH=$LLVM_HASH" >> $GITHUB_ENV
29+
30+
- name: Save PR Info on Windows systems
31+
if: runner.os == 'Windows'
32+
shell: powershell
33+
run: |
34+
#can be found
35+
mkdir ./pr
36+
echo "${{ github.event.number }}" > ./pr/NR
37+
echo ${{ github.repository }} > ./pr/REPO
38+
39+
if ( "${{ matrix.cling }}" -imatch "On" )
40+
{
41+
$env:CLING_HASH_TEMP = ( git ls-remote https://github.com/root-project/cling.git refs/tags/v${{ matrix.cling-version || env.CLING_VERSION }} )
42+
$env:CLING_HASH = $env:CLING_HASH_TEMP -replace "\t","-"
43+
}
44+
else
45+
{
46+
$env:CLING_HASH="Repl"
47+
# May need to revert back to both having same llvm_hash, as below cause llvm to be rebuilt everytime commit is made to llvm/llvm-project for release a.x
48+
# which could be quite often for new releases
49+
$env:LLVM_HASH_TEMP = (git ls-remote https://github.com/llvm/llvm-project.git refs/heads/release/${{ matrix.clang-runtime}}.x )
50+
$env:LLVM_HASH = $env:LLVM_HASH_TEMP -replace "\t","-"
51+
}
52+
53+
echo "CLING_HASH=$env:CLING_HASH"
54+
echo "LLVM_HASH=$env:LLVM_HASH"
55+
56+
echo "CLING_HASH=$env:CLING_HASH" >> $GITHUB_ENV
57+
echo "LLVM_HASH=$env:LLVM_HASH" >> $GITHUB_ENV
58+
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
name: 'Select Default Build Type'
2-
description: 'This action selects the default build typose'
3-
4-
runs:
5-
using: composite
6-
steps:
7-
- name: Select default build type of Unix Systems
8-
if: runner.os != 'Windows'
9-
shell: bash
10-
run: |
11-
echo "BUILD_TYPE=Release" >> $GITHUB_ENV
12-
echo "CODE_COVERAGE=0" >> $GITHUB_ENV
13-
if [[ "${{ matrix.os }}" != "macos"* ]]; then
14-
echo "ncpus=$(nproc --all)" >> $GITHUB_ENV
15-
else
16-
echo "ncpus=$(sysctl -n hw.ncpu)" >> $GITHUB_ENV
17-
fi
18-
19-
- name: Select default build type on Windows
20-
if: runner.os == 'Windows'
21-
shell: powershell
22-
run: |
23-
echo "BUILD_TYPE=Release" >> $env:GITHUB_ENV
24-
echo "CODE_COVERAGE=0" >> $env:GITHUB_ENV
25-
$env:ncpus=$([Environment]::ProcessorCount)
26-
echo "ncpus=$env:ncpus" >> $env:GITHUB_ENV
27-
1+
name: 'Select Default Build Type'
2+
description: 'This action selects the default build typose'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Select default build type of Unix Systems
8+
if: runner.os != 'Windows'
9+
shell: bash
10+
run: |
11+
echo "BUILD_TYPE=Release" >> $GITHUB_ENV
12+
echo "CODE_COVERAGE=0" >> $GITHUB_ENV
13+
if [[ "${{ matrix.os }}" != "macos"* ]]; then
14+
echo "ncpus=$(nproc --all)" >> $GITHUB_ENV
15+
else
16+
echo "ncpus=$(sysctl -n hw.ncpu)" >> $GITHUB_ENV
17+
fi
18+
19+
- name: Select default build type on Windows
20+
if: runner.os == 'Windows'
21+
shell: powershell
22+
run: |
23+
echo "BUILD_TYPE=Release" >> $env:GITHUB_ENV
24+
echo "CODE_COVERAGE=0" >> $env:GITHUB_ENV
25+
$env:ncpus=$([Environment]::ProcessorCount)
26+
echo "ncpus=$env:ncpus" >> $env:GITHUB_ENV
27+

0 commit comments

Comments
 (0)