Skip to content

Commit faadb20

Browse files
marc-hbxiulipan
authored andcommitted
CI: travis: new shellcheck-gitrange.bash
Travis passes $TRAVIS_COMMIT_RANGE to new shellcheck-gitrange.bash Runs shellcheck only on files changed by the PR. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 9136776 commit faadb20

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# bionic = 2018
2+
dist: bionic
3+
4+
language: minimal
5+
6+
git:
7+
depth: false
8+
quiet: true
9+
10+
before_install:
11+
- sudo apt-get -y install shellcheck
12+
13+
jobs:
14+
include:
15+
16+
- name: "shellcheck"
17+
script: ./tools/shellcheck-gitrange.bash "${TRAVIS_COMMIT_RANGE}"

tools/shellcheck-gitrange.bash

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright(c) 2018 Intel Corporation. All rights reserved.
4+
5+
set -e
6+
7+
# Sample usage:
8+
#
9+
# $ shellcheck-gitrange.bash HEAD~5.. [ -f gcc ]
10+
11+
main()
12+
{
13+
# The rest of args is passed as is to shellcheck
14+
local gitrange="$1"; shift
15+
16+
printf '%s checking range %s\n\n' "$0" "$gitrange"
17+
# also a sanity check
18+
git log --oneline "$gitrange" -- | cat # no pager
19+
20+
local fname ftype failed_files=0
21+
22+
# https://mywiki.wooledge.org/BashFAQ/001
23+
while IFS= read -r fname; do
24+
25+
ftype=$(file --brief --mime-type "$fname")
26+
if [ x'text/x-shellscript' = x"$ftype" ]; then
27+
printf '\n\n ----- shellcheck %s ----\n\n' "$fname"
28+
shellcheck "$@" "$fname" || : $((failed_files++))
29+
fi
30+
31+
done < <(git diff --name-only --diff-filter=d "$gitrange" -- )
32+
33+
return $failed_files
34+
}
35+
36+
main "$@"

0 commit comments

Comments
 (0)