-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vuk Manojlovic
committed
Jul 5, 2024
1 parent
0d76879
commit 9cd99b3
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Linter code check | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- stage | ||
- develop | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
branches: | ||
- main | ||
- stage | ||
- develop | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.9" | ||
- name: Install mypy globally | ||
run: | | ||
pip install mypy | ||
- name: Analysing templates with mypy | ||
run: | | ||
eval "$(conda shell.bash hook)" | ||
for dir in tasks/* ; do | ||
echo "Checking directory: $dir" | ||
# Skip the directory if no .mypy.ini file is found | ||
if [ ! -f "$dir/.mypy.ini" ]; then | ||
echo "No .mypy.ini file found in $dir, skipping..." | ||
continue | ||
fi | ||
if [ -f "$dir/environment.yml" ]; then | ||
echo "Setting up conda environment for $dir" | ||
conda env create -n $(basename "$dir") -f "$dir/environment.yml" | ||
echo "Created conda environment" | ||
conda activate $(basename "$dir") | ||
pip install mypy | ||
elif [ -f "$dir/requirements.txt" ]; then | ||
echo "Setting up venv for $dir" | ||
python -m venv "$dir/venv" | ||
source "$dir/venv/bin/activate" | ||
pip install -r "$dir/requirements.txt" | ||
pip install mypy | ||
fi | ||
echo "Running mypy in $dir" | ||
set +e # Disable exit on error | ||
mypy_output=$(mypy --config-file "$dir/.mypy.ini" "$dir" 2>&1) | ||
set -e # Re-enable exit on error | ||
echo "$mypy_output" | ||
if echo "$mypy_output" | grep -q 'error:'; then | ||
echo "Running install-types in $dir" | ||
mypy --install-types --non-interactive --config-file "$dir/.mypy.ini" "$dir" | ||
fi | ||
if [ -f "$dir/environment.yml" ]; then | ||
conda deactivate | ||
conda remove -y -n $(basename "$dir") --all | ||
elif [ -f "$dir/requirements.txt" ]; then | ||
deactivate | ||
rm -rf "$dir/venv" | ||
fi | ||
done |