Skip to content

Commit b3188c9

Browse files
authored
Merge pull request #21 from netgroup/linter-github-action
Add linter github action
2 parents 4f2e86f + b9d0e14 commit b3188c9

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

.github/workflows/python_linter.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
###########################
3+
###########################
4+
## Linter GitHub Actions ##
5+
###########################
6+
###########################
7+
name: Python Linter
8+
9+
#
10+
# Documentation:
11+
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
12+
#
13+
14+
#############################
15+
# Start the job on all push #
16+
#############################
17+
on:
18+
push:
19+
branches: [ master ]
20+
pull_request:
21+
branches: [ master ]
22+
23+
###############
24+
# Set the Job #
25+
###############
26+
jobs:
27+
python-lint:
28+
# Name the Job
29+
name: Python Linter
30+
# Set the agent to run on
31+
runs-on: ubuntu-latest
32+
33+
###################
34+
# Python versions #
35+
###################
36+
strategy:
37+
matrix:
38+
python-version: [3.6, 3.7, 3.8]
39+
40+
##################
41+
# Load all steps #
42+
##################
43+
steps:
44+
45+
##########################
46+
# Checkout the code base #
47+
##########################
48+
- name: Checkout Code
49+
uses: actions/checkout@v2
50+
51+
#########################
52+
# Pick a Python version #
53+
#########################
54+
- name: Set up Python ${{ matrix.python-version }}
55+
uses: actions/setup-python@v2
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
59+
##############################
60+
# Set up a Python virtualenv #
61+
##############################
62+
- name: Set up Python virtual environment
63+
run: |
64+
# Create a virtualenv
65+
python -m venv python${{ matrix.python-version }}-venv
66+
# Activate virtualenv
67+
source python${{ matrix.python-version }}-venv/bin/activate
68+
69+
########################
70+
# Install dependencies #
71+
########################
72+
- name: Install dependencies
73+
run: |
74+
# Activate virtualenv
75+
source python${{ matrix.python-version }}-venv/bin/activate
76+
# Upgrade pip
77+
python -m pip install --upgrade pip
78+
# Install linters and other python modules
79+
pip install pylint pycodestyle flake8 black mypy isort setuptools wheel pytest
80+
81+
########################
82+
# Install requirements #
83+
########################
84+
- name: Install requirements
85+
run: |
86+
# Activate virtualenv
87+
source python${{ matrix.python-version }}-venv/bin/activate
88+
# Install requirements
89+
pip install -r requirements.txt
90+
91+
################################
92+
# Run Linter against code base #
93+
################################
94+
- name: Python Code Quality and Lint
95+
run: |
96+
# Activate virtualenv
97+
source python${{ matrix.python-version }}-venv/bin/activate
98+
# Module to be tested
99+
module=nets
100+
# pylint
101+
for file in $(find $module -type f); do
102+
if [ ${file: -3} == ".py" ]; then
103+
echo Running: pylint $file
104+
pylint $file
105+
if [ "$?" = "0" ]; then echo "Pylint ok"; else echo "Pylint error"; exit $exit_code; fi
106+
fi
107+
done;
108+
# pycodestyle
109+
for file in $(find $module -type f); do
110+
if [ ${file: -3} == ".py" ]; then
111+
echo Running: pycodestyle $file
112+
pycodestyle $file
113+
if [ "$?" = "0" ]; then echo "pycodestyle ok"; else echo "pycodestyle error"; exit $exit_code; fi
114+
fi
115+
done;
116+
# flake8
117+
for file in $(find $module -type f); do
118+
if [ ${file: -3} == ".py" ]; then
119+
echo Running: flake8 $file
120+
flake8 $file
121+
if [ "$?" = "0" ]; then echo "Flake8 ok"; else echo "Flake8 error"; exit $exit_code; fi
122+
fi
123+
done;
124+
# black
125+
#for file in $(find $module -type f); do
126+
# if [ ${file: -3} == ".py" ]; then
127+
# echo Running: black --check $file
128+
# black --check $file
129+
# if [ "$?" = "0" ]; then echo "Black ok"; else echo "Black error"; exit $exit_code; fi
130+
# fi
131+
#done;
132+
# mypy
133+
#for file in $(find $module -type f); do
134+
# if [ ${file: -3} == ".py" ]; then
135+
# echo Running: mypy $file
136+
# mypy $file
137+
# if [ "$?" = "0" ]; then echo "mypy ok"; else echo "mypy error"; exit $exit_code; fi
138+
# fi
139+
#done;
140+
# isort
141+
for file in $(find $module -type f); do
142+
if [ ${file: -3} == ".py" ]; then
143+
echo Running: isort -rc $file -c --diff
144+
isort -rc $file -c --diff --project $file
145+
if [ "$?" = "0" ]; then echo "isort ok"; else echo "isort error"; exit $exit_code; fi
146+
fi
147+
done;

0 commit comments

Comments
 (0)