Skip to content

Commit

Permalink
feat: include flake8 linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebits committed Jun 28, 2024
1 parent 48e94be commit dffbd1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions .github/workflows/scripts/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit dffbd1b

Please sign in to comment.