tests: add shellcheck
This commit is contained in:
parent
b625325487
commit
9a92d29111
@ -36,3 +36,7 @@ task:
|
|||||||
build_script:
|
build_script:
|
||||||
- nix flake check
|
- nix flake check
|
||||||
- ./test/nixos-search/ci-test.sh
|
- ./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")
|
(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() {
|
all() {
|
||||||
buildable
|
buildable "$@"
|
||||||
|
shellcheck
|
||||||
examples
|
examples
|
||||||
flake
|
flake
|
||||||
nixosSearch
|
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