Skip to content

Commit 3e8ce39

Browse files
authored
Merge pull request #92 from basak-qcom/comprehensive-static-checks
CI: scan all Python scripts
2 parents d82008d + 994439b commit 3e8ce39

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

.github/workflows/static-checks.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,32 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- name: Install flake8
26-
run: sudo apt update && sudo apt -y install flake8
26+
run: sudo apt update && sudo apt -y install file flake8
2727

2828
- uses: actions/checkout@v4
2929
with:
3030
fetch-depth: 0
3131

32-
- name: Run Flake8
33-
run: flake8 scripts/*.py
32+
- name: Run Flake8 and dependencies
33+
run: |
34+
. scripts/functions
35+
scan_files text/x-script.python flake8
3436
3537
pylint:
3638
name: Install and run Pylint on Python scripts
3739
runs-on: ubuntu-latest
3840
steps:
39-
- name: Install Pylint
40-
run: sudo apt update && sudo apt -y install pylint
41+
- name: Install Pylint and dependencies
42+
run: sudo apt update && sudo apt -y install file pylint python3-voluptuous
4143

4244
- uses: actions/checkout@v4
4345
with:
4446
fetch-depth: 0
4547

4648
- name: Run Pylint (error mode)
47-
run: pylint --errors-only scripts/*.py
49+
run: |
50+
. scripts/functions
51+
scan_files text/x-script.python pylint --errors-only
4852
4953
shellcheck:
5054
name: Install and run ShellCheck on shell scripts
@@ -59,12 +63,12 @@ jobs:
5963

6064
- name: Run ShellCheck
6165
run: |
62-
# Run shellcheck against all files outside .git/ that `file` reports
63-
# as text/x-shellscript
64-
#
66+
. scripts/functions
67+
6568
# Ignore the double quoting warning, script authors have better
66-
# knowledge of variable contents.
67-
export SHELLCHECK_OPTS="-e SC2086"
68-
find . -path ./.git -prune -o -print0 | \
69-
xargs -0n1 sh -c 'test "$(file --brief --mime-type "$1")" = "text/x-shellscript" && printf "%s\000" "$1"' -- | \
70-
xargs -0t shellcheck
69+
# knowledge of variable contents, and we accept that in practice
70+
# "local" is implemented everywhere so it's OK to use even though
71+
# it's not strictly POSIX.
72+
export SHELLCHECK_OPTS="-e SC2086,SC3043"
73+
74+
scan_files text/x-shellscript shellcheck

ci/schemacheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import os
55
import sys
66
import yaml
7-
import voluptuous
8-
from lava_common.schemas import validate
7+
import voluptuous # pylint: disable=import-error
8+
from lava_common.schemas import validate # pylint: disable=import-error
99

1010
exitcode = 0
1111

scripts/functions

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# shellcheck shell=sh
5+
6+
scan_files() {
7+
# For all files under $PWD except under .git that match $mime_type, run the
8+
# scanner with the remaining parameters. Return zero if all $cmd succeeded,
9+
# non-zero otherwise.
10+
11+
local mime_type="$1"
12+
shift
13+
14+
# shellcheck disable=SC2016
15+
find . -path ./.git -prune -o -print0 | \
16+
xargs -0n1 sh -c 'test "$(file --brief --mime-type "$1")" = "'"$mime_type"'" && printf "%s\000" "$1"' -- | \
17+
xargs -0t -- "$@"
18+
}

0 commit comments

Comments
 (0)