CTX-5783: Mypy Linter Action #3
Workflow file for this run
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
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 |