Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable github PR python pre-check for KVM #240

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/scripts/cfg-lint-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

import os
import re
import sys


def cfg_lint_check():
print('Running cfg lint check...')
exit_code = 0
for file in sys.argv[1:]:
status_code = 0
blank_line = 0
cfg_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir, file))
with open(cfg_path, 'r') as f:
contents = f.read()
for num, line in enumerate(contents.splitlines(), 1):
# Only strip whitespaces, handle other blank characters below
stripped_line = line.lstrip(' ')
blank_line = (blank_line + 1
if re.search(r'^\s*$', stripped_line) else 0)
if blank_line >= 2:
print(f'{file}:{num}: Too many blank lines')
status_code = 1
if re.search(r'\s$', line):
print(f'{file}:{num}: Trailing whitespaces')
status_code = 1
if re.search(r'^\s', stripped_line):
print(f'{file}:{num}: Wrong indent(Unexpected blank characters')
status_code = 1
if (len(line) - len(stripped_line)) % 4:
print(f'{file}:{num}: Wrong indent(4x spaces mismatch)')
status_code = 1
if not contents.endswith('\n'):
print(f'{file} Missing final newline')
status_code = 1
exit_code = exit_code or status_code
sys.exit(exit_code)


if __name__ == '__main__':
cfg_lint_check()
3 changes: 3 additions & 0 deletions .github/scripts/requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pylint
inspektor==0.5.3
autopep8
71 changes: 71 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,74 @@ jobs:
run: sudo docker build -f BM/Dockerfile.build -t builder BM
- name: Build Project
run: sudo ./.github/scripts/build_check
python-style-check:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.9]
fail-fast: false

steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install sphinx
pip install -r ./.github/scripts/requirements-ci.txt
- name: Run inspekt
run: inspekt checkall ./KVM --disable-style E501,E265,W601,E402,E722,E741 --disable-lint=W,R,C,E0601,E1002,E1101,E1103,E1120,F0401,I0011,I1101 --enable-lint W0611,W1201 --no-license-check
- run: echo "This job's status is ${{ job.status }}."
cfg-lint-check:
name: Cfg lint
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed files
id: cfg-files
uses: tj-actions/changed-files@v35
with:
files: |
./KVM/qemu/*.cfg
- name: Set matrix
id: set-matrix
run: echo matrix=$(python3 -c 'print("${{ steps.cfg-files.outputs.all_changed_files }}".split())') >> $GITHUB_OUTPUT
- name: Check cfg files lint
if: steps.cfg-files.outputs.any_changed == 'true'
run: |
./.github/scripts/cfg-lint-check.py ${{ steps.cfg-files.outputs.all_changed_files }}
cartesian-syntax-check:
name: Cartesian syntax
runs-on: ubuntu-latest
needs: cfg-lint-check
if: ${{ needs.cfg-lint-check.outputs.matrix != '[]' }}
strategy:
matrix:
file: ${{ fromJson(needs.cfg-lint-check.outputs.matrix) }}
fail-fast: false

steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Parse ${{ matrix.file }} into Cartesian configuration
env:
CFG_FILE: ${{ matrix.file }}
run: |
echo "Parse ${CFG_FILE} into Cartesian configuration"
sed -i '1s/^/variants:\n/' ${CFG_FILE}
curl -fsSL https://raw.githubusercontent.com/avocado-framework/avocado-vt/master/virttest/cartesian_config.py | python3 - -f ${CFG_FILE}
Loading