Skip to content

Commit

Permalink
github: Fix CI tests sanity
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Castello <[email protected]>
  • Loading branch information
microhobby committed Jan 12, 2025
1 parent dcc84ee commit e887537
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
check-eof-new-line:
runs-on: ubuntu-latest
container:
image: torizonextras/torizon-dev:next
image: torizonextras/torizon-dev:dev
options: --user root
name: Check EOF New Line
steps:
- uses: actions/checkout@v3
Expand All @@ -38,4 +39,4 @@ jobs:
shell: bash

run: |
xonsh ./scripts/valid-new-line.xsh
/home/torizon/.local/bin/xonsh ./scripts/valid-new-line.xsh
61 changes: 61 additions & 0 deletions scripts/valid-new-line.xsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env xonsh

# Copyright (c) 2025 Toradex
# SPDX-License-Identifier: MIT

##
# This script is used to check if all the files have a new line at the end.
# WARNING:
# This script is not meant to be run manually. It's make part of the internal
# validation process from CI/CD.
##

# use the xonsh environment to update the OS environment
$UPDATE_OS_ENVIRON = True
# always return if a cmd fails
$RAISE_SUBPROC_ERROR = True

import os
import sys


def check_new_line(file_path):
with open(file_path, 'rb') as f:
f.seek(-1, os.SEEK_END)
last_char = f.read(1)
return last_char == b'\n'


ignore_folders = [
".git",
"node_modules",
"id_rsa",
"css",
"obj",
"target",
".mypy",
"egg-info"
]

error_reach = False

for root, dirs, files in os.walk('.'):
dirs[:] = [d for d in dirs if d not in ignore_folders]
for file in files:
file_path = os.path.join(root, file)

if any(ig in file_path for ig in ignore_folders):
continue

mime_type = $(file --mime-type -b @(file_path)).strip()
if mime_type.startswith('text/') or mime_type in {'application/javascript', 'application/json'}:
if not check_new_line(file_path):
print(f"❌ :: {file_path}", file=sys.stderr)
error_reach = True

if error_reach:
print("\n❌ :: Files are missing new line at the end\n", file=sys.stderr)
sys.exit(404)
else:
print("\n✅ :: All files have new line at the end\n")
sys.exit(0)

0 comments on commit e887537

Please sign in to comment.