-
Notifications
You must be signed in to change notification settings - Fork 5
139 lines (117 loc) · 4.97 KB
/
pr-checks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Pull Request Checks
on:
pull_request:
branches:
- main
jobs:
build:
name: Pull Request Checks
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/[email protected]
with:
separator: ","
- name: Get markdown files
id: changed_md_files
uses: tj-actions/[email protected]
with:
files: |
**.md
separator: ","
- name: Print the changed and markdown files
run: |
echo Changed files: ${{ steps.changed_files.outputs.all_changed_files }}
echo Markdown files: ${{ steps.changed_md_files.outputs.all_changed_files }}
- name: Create log files
run: |
touch error_log.txt
touch pass_log.txt
touch flake8_log.txt
touch pylint_log.txt
- name: Check for naming conventions
run: |
all_files=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" | tr "," "\n")
while IFS= read -r file; do
if echo "$file" | grep -q " "; then
echo "The file or path $file contains spaces, please rename the path or file without spaces, using underscore ('_') instead." >> error_log.txt
fi
IFS='/' read -r -a fname_array <<< "$file";
path="${fname_array[@]::${#fname_array[@]}-1}";
if echo "${path}" | grep -qE '[A-Z]'; then
echo "The path '$file' contains capital letters. Please write file paths in lower case." >> error_log.txt
fi
done <<< "$all_files"
echo "Folders and files are correctly named!" >> pass_log.txt
- name: Check for markdown file naming conventions
run: |
md_files=$(echo "${{ steps.changed_md_files.outputs.all_changed_files }}" | tr "," "\n")
if [ -n "$md_files" ]; then
while IFS= read -r file; do
md_fname=$(echo "$file" | tr "/" "\n" | grep "md" || true) # Ensure grep doesn't exit
if echo $md_fname | grep -qE "^[^A-Z]+.md"; then
echo "The markdown file $md_fname at path $file is not in all caps. Please write markdown file names using all caps." >> error_log.txt
fi
done <<< "$md_files"
echo "All markdown files are correctly named!" >> pass_log.txt
else
echo "There are no markdown files to check." >> pass_log.txt
fi
- name: Check for PDF and Word files
run: |
echo "${{ steps.changed_files.outputs.all_changed_files }}" | tr "," "\n" | if grep -q -e ".docx" -e ".pdf"; then
echo "This PR contains PDF or word (.docx) files, please remove them and try again." >> error_log.txt
else
echo "This PR does not contain PDF or word (.docx) files." >> pass_log.txt
fi
- name: Setup Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install check dependencies
run: |
python -m pip install --upgrade pip
pip install nbqa flake8 pylint bandit nbformat
- name: Execute linting check on Python files
run: |
py_files=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" | tr "," "\n" | grep ".py$" || true)
if [ -n "$py_files" ]; then
for file in $py_files; do
flake8 --config=ci_build/flake8 "$file" >> flake8_log.txt || true
pylint "$file" --rcfile=ci_build/pylintrc >> pylint_log.txt || true
done
else
echo "No Python files to lint and check."
fi
- name: Execute linting check on Jupyter Notebooks
run: |
nb_files=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" | tr "," "\n" | grep ".ipynb$" || true)
if [ -n "$nb_files" ]; then
for file in $nb_files; do
nbqa flake8 --config=ci_build/flake8 "$file" >> flake8_log.txt || true
nbqa pylint "$file" --rcfile=ci_build/pylintrc >> pylint_log.txt || true
done
else
echo "No Jupyter Notebooks to lint."
fi
- name: Display name check logs and handle errors
run: |
echo -e "\n-----------------------------------------\nNaming Conventions Check File:"
cat error_log.txt
echo -e "\n-----------------------------------------\nFlake8 Linting Check File:"
cat flake8_log.txt
echo -e "\n-----------------------------------------\nPylint Linting Check File:"
cat pylint_log.txt
if [ -s error_log.txt ]; then
exit 1
elif [ -s flake8_log.txt ]; then
exit 1
elif [ -s pylint_log.txt ]; then
exit 1
else
cat pass_log.txt
echo "No naming errors found!"
fi