Skip to content

Commit 2b82e91

Browse files
committed
wip
1 parent 4e28a41 commit 2b82e91

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

.github/workflows/static-checks.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ jobs:
3131

3232
- name: Run Flake8 and dependencies
3333
run: |
34-
# Run flake8 against all files outside .git/ that `file` reports
35-
# as text/x-script.python
36-
find . -path ./.git -prune -o -print0 | \
37-
xargs -0n1 sh -c 'test "$(file --brief --mime-type "$1")" = "text/x-script.python" && printf "%s\000" "$1"' -- | \
38-
xargs -0t flake8
34+
. scripts/functions
35+
scan_files text/x-script.python flake8
3936
4037
pylint:
4138
name: Install and run Pylint on Python scripts
@@ -50,11 +47,8 @@ jobs:
5047

5148
- name: Run Pylint (error mode)
5249
run: |
53-
# Run pylint against all files outside .git/ that `file` reports
54-
# as text/x-script.python
55-
find . -path ./.git -prune -o -print0 | \
56-
xargs -0n1 sh -c 'test "$(file --brief --mime-type "$1")" = "text/x-script.python" && printf "%s\000" "$1"' -- | \
57-
xargs -0t pylint --errors-only
50+
. scripts/functions
51+
scan_files text/x-script.python pylint --errors-only
5852
5953
shellcheck:
6054
name: Install and run ShellCheck on shell scripts
@@ -69,12 +63,12 @@ jobs:
6963

7064
- name: Run ShellCheck
7165
run: |
72-
# Run shellcheck against all files outside .git/ that `file` reports
73-
# as text/x-shellscript
74-
#
66+
. scripts/functions
67+
7568
# Ignore the double quoting warning, script authors have better
76-
# knowledge of variable contents.
77-
export SHELLCHECK_OPTS="-e SC2086"
78-
find . -path ./.git -prune -o -print0 | \
79-
xargs -0n1 sh -c 'test "$(file --brief --mime-type "$1")" = "text/x-shellscript" && printf "%s\000" "$1"' -- | \
80-
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

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 $cmd (expanded by shell word splitting). Return zero if all $cmd
9+
# succeeded, non-zero otherwise.
10+
11+
local mime_type="$1"
12+
local cmd="$2"
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 -- $cmd
18+
}

0 commit comments

Comments
 (0)