tests: add shellcheck

This commit is contained in:
Otto Sabart 2022-08-16 21:00:00 +02:00 committed by Erik Arvstedt
parent b625325487
commit 9a92d29111
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
3 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -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
View 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