fix: lint and update workflow related items

This commit is contained in:
realstealthninja
2026-09-30 14:55:09 +05:30
parent 3cb38986de
commit 2aa6797d1c
3 changed files with 79 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ jobs:
name: Code Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v4

61
filename_formatter.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/bin/bash
echo -e "Arguments:
[0] - Used by Bash (script filename)
[1] - Base directory
[2] - Filename type (maximum two values)
[3] - Ignored files or folders (optional; use "\""./<directory_name>"\"")
"
# Separate $2 value (filename types) if it has a comma
if [[ "$2" == *","* ]];
then
string="$2"
str_value=${string#*,}
str_value2=${string%%,*}
else
str_value="$2"
str_value2="$2"
fi
# Do not run script if there are no given arguments.
if [[ "$1" == "" ]] || [[ "$2" == "" ]];
then
echo "No arguments given. Please specify minimum two arguments."
exit 1
fi
echo "Changed files:"
IFS=$'\n'; set -f
for fname in $(find $1 -type f -name "*$str_value2" -or -name "*$str_value")
do
ignored_files="$(echo "$3" | tr "," "\n")"
str="${fname}"
value=${str%/*} # If the base directory is `.`, check in all directories for the ignored filenames
for files in $ignored_files
do
echo ${fname}
if [ "${fname}" == "$value/$files" ] || [ "$value" == "$files" ];
then
continue 2
fi
done
#echo ${fname}
new_fname=$(echo "${fname}" | tr ' ' '_')
#echo " ${new_fname}"
new_fname=$(echo "${new_fname}" | tr '[:upper:]' '[:lower:]')
#echo " ${new_fname}"
new_fname=$(echo "${new_fname}" | tr '-' '_')
#echo " ${new_fname}"
if [ "${fname}" != "${new_fname}" ]
then
echo " ${fname} --> ${new_fname}"
git "mv" "${fname}" "${new_fname}" # Requires you to be in version control
fi
done
unset IFS; set +f

View File

@@ -5,15 +5,28 @@ import sys
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
with open("git_diff.txt") as in_file:
modified_files = sorted(in_file.read().splitlines())
print("{} files were modified.".format(len(modified_files)))
print(f"{len(modified_files)} files were modified.")
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
cpp_exts = (
".c",
".c++",
".cc",
".cpp",
".cu",
".cuh",
".cxx",
".h",
".h++",
".hh",
".hpp",
".hxx",
)
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
print(f"{len(cpp_files)} C++ files were modified.")
if not cpp_files:
sys.exit(0)
subprocess.run(
_ = subprocess.run(
[
"clang-tidy",
"--fix",
@@ -26,7 +39,7 @@ with open("git_diff.txt") as in_file:
text=True,
stderr=subprocess.STDOUT,
)
subprocess.run(
_ = subprocess.run(
["clang-format", "-i", "-style=file", *cpp_files],
check=True,
text=True,