From 9cd99b376ea4287e734b7bb415a63b591c71049a Mon Sep 17 00:00:00 2001 From: Vuk Manojlovic Date: Fri, 5 Jul 2024 13:29:03 +0200 Subject: [PATCH] CTX-5783: Added github action --- .github/workflows/linter-code-check.yml | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/linter-code-check.yml diff --git a/.github/workflows/linter-code-check.yml b/.github/workflows/linter-code-check.yml new file mode 100644 index 00000000..466a8db7 --- /dev/null +++ b/.github/workflows/linter-code-check.yml @@ -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