Skip to content

Commit 6f7cbd6

Browse files
feat(lint): check whitespace
1 parent 61d1ced commit 6f7cbd6

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/__call-common-lint.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v5
28+
with:
29+
fetch-depth: 2 # need to fetch 2 to get list of changed files
30+
31+
- name: Get changed files
32+
id: changed_files
33+
shell: bash
34+
run: |
35+
firstCommit='${{ github.event.pull_request.base.sha }}'
36+
lastCommit='${{ github.event.pull_request.head.sha }}'
37+
changedFiles=$(git diff --name-only --diff-filter=d "${firstCommit}" "${lastCommit}" | tr '\n' ' ')
38+
39+
echo "Changed files: ${changedFiles}"
40+
echo "CHANGED_FILES=${changedFiles}" >> "${GITHUB_OUTPUT}"
2841
2942
- name: Download problem matchers
3043
shell: bash
@@ -73,6 +86,7 @@ jobs:
7386
python-version: '3.12'
7487

7588
- name: Install Python dependencies
89+
shell: bash
7690
run: |
7791
# shellcheck disable=SC2102 # this is triggered by the [toolchain] extra
7892
python -m pip install --upgrade \
@@ -102,6 +116,7 @@ jobs:
102116
fi
103117
104118
- name: Replace shell
119+
# for actionlint
105120
shell: bash
106121
run: |
107122
# Replace in workflow files
@@ -127,9 +142,39 @@ jobs:
127142
echo "::remove-matcher owner=actionlint::"
128143
exit ${error}
129144
145+
- name: check-eol
146+
if: always()
147+
shell: bash
148+
run: |
149+
error=0
150+
for file in ${{ steps.changed_files.outputs.CHANGED_FILES }}; do
151+
152+
# Skip empty files
153+
if [[ ! -s "$file" ]]; then
154+
continue
155+
fi
156+
157+
# Check if file ends with newline using tail -c 1
158+
if [[ -n "$(tail -c 1 "$file")" ]]; then
159+
error=1
160+
title="EOL linting error"
161+
message="File '$file' does not end with a newline character."
162+
line=$(($(wc -l < "$file") + 1))
163+
164+
echo "::error file=$file,line=$line,title=$title::$message"
165+
fi
166+
done
167+
168+
exit ${error}
169+
170+
- name: check-trailing-spaces
171+
if: always()
172+
uses: marcopaganini/check-trailing-spaces@v2.0.0
173+
130174
- name: C++ - find files
131175
id: cpp_files
132176
if: always()
177+
shell: bash
133178
run: |
134179
# find files
135180
found_files=$(find . -type f \
@@ -176,6 +221,7 @@ jobs:
176221

177222
- name: C++ - Clang format (simple)
178223
if: always() && steps.clang_format_diff.outcome == 'failure'
224+
shell: bash
179225
run: |
180226
echo "::add-matcher::.github/matchers/clang-format.json"
181227
set +e
@@ -193,6 +239,7 @@ jobs:
193239
- name: CMake - find files
194240
id: cmake_files
195241
if: always()
242+
shell: bash
196243
run: |
197244
# find files
198245
found_files=$(find . -type f -iname "CMakeLists.txt" -o -iname "*.cmake")
@@ -221,6 +268,7 @@ jobs:
221268
222269
- name: CMake - cmake-lint
223270
if: always() && steps.cmake_files.outputs.found_files
271+
shell: bash
224272
run: |
225273
echo "::add-matcher::.github/matchers/cmake-lint.json"
226274
set +e
@@ -234,6 +282,7 @@ jobs:
234282
- name: Docker - find files
235283
id: docker_files
236284
if: always()
285+
shell: bash
237286
run: |
238287
found_files=$(find . -type f -iname "Dockerfile" -o -iname "*.dockerfile")
239288
@@ -244,6 +293,7 @@ jobs:
244293
245294
- name: Docker - hadolint
246295
if: always() && steps.docker_files.outputs.found_files
296+
shell: bash
247297
run: |
248298
docker pull hadolint/hadolint
249299
@@ -339,6 +389,7 @@ jobs:
339389
340390
- name: Python - flake8
341391
if: always()
392+
shell: bash
342393
run: |
343394
echo "::group::problem matcher"
344395
set +e
@@ -359,6 +410,7 @@ jobs:
359410
360411
- name: Python - nbqa flake8
361412
if: always()
413+
shell: bash
362414
run: |
363415
echo "::group::problem matcher"
364416
set +e
@@ -381,6 +433,7 @@ jobs:
381433
382434
- name: Python - nb-clean
383435
if: always()
436+
shell: bash
384437
run: |
385438
output=$(find . -name '*.ipynb' -exec nb-clean check {} \;)
386439
@@ -393,6 +446,7 @@ jobs:
393446
- name: Rust - find Cargo.toml
394447
id: run_cargo
395448
if: always()
449+
shell: bash
396450
run: |
397451
# check if Cargo.toml exists
398452
if [ -f "Cargo.toml" ]; then
@@ -412,6 +466,7 @@ jobs:
412466

413467
- name: Rust - cargo fmt
414468
if: always() && steps.run_cargo.outputs.found_cargo == 'true'
469+
shell: bash
415470
run: |
416471
set +e
417472
error=0
@@ -449,6 +504,7 @@ jobs:
449504
- name: shellcheck - find files
450505
id: shellcheck_files
451506
if: always()
507+
shell: bash
452508
run: |
453509
found_files=$(find . -type f -iname "*.bash" -o -iname "*.sh")
454510
@@ -459,6 +515,7 @@ jobs:
459515
460516
- name: shellcheck
461517
if: always() && steps.shellcheck_files.outputs.found_files
518+
shell: bash
462519
run: |
463520
echo "::add-matcher::.github/matchers/shellcheck-gcc.json"
464521
set +e
@@ -472,6 +529,7 @@ jobs:
472529
- name: YAML - find files
473530
id: yaml_files
474531
if: always()
532+
shell: bash
475533
run: |
476534
# space separated list of files
477535
FILES=.clang-format
@@ -491,6 +549,7 @@ jobs:
491549
- name: YAML - yamllint
492550
id: yamllint
493551
if: always()
552+
shell: bash
494553
run: |
495554
if [ ! -f .yamllint.yml ]; then
496555
curl -sSL https://raw.githubusercontent.com/LizardByte/.github/master/.yamllint.yml -o .yamllint.yml

0 commit comments

Comments
 (0)