From dffbd1ba0ee32adb1830992fa7fefe257f9d0b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 14:50:52 +0100 Subject: [PATCH] feat: include flake8 linting --- .github/workflows/code_analysis.yaml | 2 +- .github/workflows/scripts/linter.py | 29 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index b2838026b5..425dda3595 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v3 - name: Install pycodestyle and yamllint linter - run: python -m pip install pycodestyle==2.8.0 yamllint==1.26.3 + run: python -m pip install pycodestyle==2.8.0 yamllint==1.26.3 flake8==6.0.0 - name: Get the updated files id: updated_files diff --git a/.github/workflows/scripts/linter.py b/.github/workflows/scripts/linter.py index 694c899131..59b07344ec 100644 --- a/.github/workflows/scripts/linter.py +++ b/.github/workflows/scripts/linter.py @@ -93,11 +93,29 @@ def run_python_linter(python_files): print('No python files were found. Skipping python linter analysis') return 0 + + linters_data = { + 'pycodestyle': { + 'command': 'pycodestyle', + 'parameters': ['--max-line-length=120'] + }, + 'flake8': { + 'command': 'flake8', + 'parameters': ['--max-line-length=120'] + } + } + + linters_result = {} + # Set the linter parameters - parameters = ['pycodestyle', '--max-line-length=120'] - parameters.extend(python_files) + for linter, linter_data in linters_data.items(): + full_command = [linter_data['command']] + full_command.extend(linter_data['parameters']) + full_command.extend(python_files) + + linters_result[linter] = subprocess.run(full_command).returncode - return subprocess.run(parameters).returncode + return linters_result def run_yaml_linter(yaml_files, config_files_path): @@ -175,13 +193,14 @@ def main(): yaml_files = get_yaml_files(updated_files) # Run the python linter analysis process - python_linter_status = run_python_linter(python_files) + python_linter_results = run_python_linter(python_files) + python_linter_failed = any(status != 0 for linter, status in python_linter_results.items()) # Run the yaml linter analysis process yaml_linter_status = run_yaml_linter(yaml_files, script_parameters.config_path) # Return failure code if some check has not passed - if python_linter_status != 0 or yaml_linter_status != 0: + if python_linter_failed or yaml_linter_status != 0: sys.exit(1)