Improve dev tools in the Nix environment (#1666)

* Improve dev tools in the nix environment

Added postgrest-build, postgrest-run, postgrest-clean, postgrest-check
and postgrest-watch tools. Changed order of postgrest-test-spec-all to
run backwards from pg13 to pg9.5. Added shellcheck to lint shell scripts
in nix environment.

Co-authored-by: monacoremo <monacoremo>
This commit is contained in:
Remo Rechkemmer
2020-11-30 22:21:19 +01:00
committed by GitHub
co-authored by monacoremo <monacoremo>
parent 9adec12a67
commit 07cb47e6ac
13 changed files with 255 additions and 129 deletions
+22 -29
View File
@@ -2,7 +2,9 @@
{ buildEnv
, cabal-install
, checkedShellScript
, curl
, devCabalOptions
, git
, haskell
, lib
@@ -13,17 +15,13 @@
, postgrestStatic
, postgrestProfiled
, runtimeShell
, writeShellScript
, writeShellScriptBin
}:
let
# Wrap the `test/with_tmp_db` script with the required dependencies from Nix.
withTmpDb =
postgresql:
writeShellScript "postgrest-test-${postgresql.name}"
checkedShellScript "postgrest-test-${postgresql.name}"
''
set -euo pipefail
export PATH=${postgresql}/bin:${git}/bin:${runtimeShell}/bin:"$PATH"
exec ${../test/with_tmp_db} "$@"
@@ -33,12 +31,11 @@ let
# PostgreSQL.
testSpec =
name: postgresql:
writeShellScriptBin
checkedShellScript
name
''
set -euo pipefail
export PATH="$(cat ${postgrest.env})"/bin:"$PATH"
env="$(cat ${postgrest.env})"
export PATH="$env/bin:$PATH"
cat << EOF
@@ -46,8 +43,11 @@ let
EOF
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test -f FailOnWarn \
--test-show-detail=direct
trap 'echo "Failed on ${postgresql.name}"' exit
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
trap "" exit
cat << EOF
@@ -59,8 +59,9 @@ let
# Create a `testSpec` for each PostgreSQL version that we want to test
# against.
testSpecVersions =
lib.mapAttrsToList
(name: postgresql: testSpec "postgrest-test-spec-${name}" postgresql)
builtins.map
({ name, postgresql }:
(testSpec "postgrest-test-spec-${name}" postgresql).bin)
postgresqlVersions;
# Helper script for running the tests against all PostgreSQL versions.
@@ -69,20 +70,14 @@ let
testRunners =
map (test: "${test}/bin/${test.name}") testSpecVersions;
in
writeShellScriptBin "postgrest-test-spec-all"
''
set -euo pipefail
${lib.concatStringsSep "\n" testRunners}
'';
checkedShellScript "postgrest-test-spec-all"
(lib.concatStringsSep "\n" testRunners);
testIO =
name: postgresql:
writeShellScriptBin
checkedShellScript
name
''
set -euo pipefail
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
cd "$rootdir"
@@ -93,11 +88,9 @@ let
testMemory =
name: postgresql:
writeShellScriptBin
checkedShellScript
name
''
set -euo pipefail
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
cd "$rootdir"
@@ -115,8 +108,8 @@ buildEnv
paths =
[
(testSpec "postgrest-test-spec" postgresql)
testSpecAllVersions
(testSpec "postgrest-test-spec" postgresql).bin
testSpecAllVersions.bin
] ++ testSpecVersions;
}
# The IO an memory tests have large dependencies (a static and a profiled
@@ -125,8 +118,8 @@ buildEnv
# them available through separate attributes:
// {
ioTests =
(testIO "postgrest-test-io" postgresql);
(testIO "postgrest-test-io" postgresql).bin;
memoryTests =
(testMemory "postgrest-test-memory" postgresql);
(testMemory "postgrest-test-memory" postgresql).bin;
}