tests: add shellcheck
This commit is contained in:
parent
b625325487
commit
9a92d29111
|
@ -36,3 +36,7 @@ task:
|
|||
build_script:
|
||||
- nix flake check
|
||||
- ./test/nixos-search/ci-test.sh
|
||||
|
||||
- name: shellcheck
|
||||
build_script:
|
||||
- nix shell --inputs-from . nixpkgs#{shellcheck,findutils,gnugrep} -c ./test/shellcheck.sh
|
||||
|
|
|
@ -312,8 +312,14 @@ examples() {
|
|||
(cd "$scriptDir/../examples" && nix-shell --run "$script")
|
||||
}
|
||||
|
||||
shellcheck() {
|
||||
if ! checkFlakeSupport "shellcheck"; then return; fi
|
||||
nix shell --inputs-from "$scriptDir/.." nixpkgs#shellcheck -c "$scriptDir/shellcheck.sh"
|
||||
}
|
||||
|
||||
all() {
|
||||
buildable
|
||||
buildable "$@"
|
||||
shellcheck
|
||||
examples
|
||||
flake
|
||||
nixosSearch
|
||||
|
|
19
test/shellcheck.sh
Executable file
19
test/shellcheck.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "${BASH_SOURCE[0]%/*}/.."
|
||||
{
|
||||
# Skip .git dir in all find commands
|
||||
find . -type f ! -path './.git/*' -name '*.sh'
|
||||
# Find files without extensions that have a shell shebang
|
||||
find . -type f ! -path './.git/*' ! -name "*.*" -exec grep -lP '\A^#! */usr/bin/env (?:nix-shell|bash)' {} \;
|
||||
} | while IFS= read -r path; do
|
||||
echo "$path"
|
||||
file=${path##*/}
|
||||
dir=${path%/*}
|
||||
# Switch working directory so that shellcheck can access external sources
|
||||
# (via arg `--external-sources`)
|
||||
pushd "$dir" > /dev/null
|
||||
shellcheck --external-sources --shell bash "$file"
|
||||
popd > /dev/null
|
||||
done
|
Loading…
Reference in New Issue
Block a user