nix: Refactor checkedShellScript's inRootDir to workingDir

This allows more flexible control over the working directory. Values for workingDir must always start
with a / and will then be relative to the repo root.
This commit is contained in:
Wolfgang Walther
2024-02-18 13:10:00 +01:00
committed by Wolfgang Walther
parent 75a86ba873
commit e110fdbd2c
10 changed files with 37 additions and 34 deletions
@@ -15,12 +15,13 @@
, docs
, args ? [ ]
, positionalCompletion ? ""
, inRootDir ? false
, redirectTixFiles ? true
, withEnv ? null
, withPath ? [ ]
, withTmpDir ? false
, workingDir ? null
}: text:
assert workingDir == null || lib.hasPrefix "/" workingDir;
let
# square brackets are a pain to escape - if even possible. just don't use them...
escape = builtins.replaceStrings [ "\n" ] [ " \\n" ];
@@ -89,7 +90,7 @@ let
trap 'rm -rf $hpctixdir' EXIT
''
+ lib.optionalString inRootDir ''
+ lib.optionalString (workingDir != null) ''
cd "$(${git}/bin/git rev-parse --show-toplevel)"
if test ! -f postgrest.cabal; then
@@ -97,6 +98,8 @@ let
"run this command somewhere in the PostgREST repo."
exit 1
fi
cd "''${PWD}${workingDir}"
''
+ lib.optionalString withTmpDir ''
+4 -4
View File
@@ -11,7 +11,7 @@ let
name = "postgrest-build";
docs = "Build PostgREST interactively using cabal-install.";
args = [ "ARG_LEFTOVERS([Cabal arguments])" ];
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
@@ -23,7 +23,7 @@ let
{
name = "postgrest-clean";
docs = "Clean the PostgREST project, including all cabal-install artifacts.";
inRootDir = true;
workingDir = "/";
}
''
# clean old coverage data, too
@@ -45,7 +45,7 @@ let
"ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool size])"
"ARG_LEFTOVERS([PostgREST arguments])"
];
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
@@ -63,7 +63,7 @@ let
name = "postgrest-repl";
docs = "Interact with PostgREST modules using the cabal repl";
args = [ "ARG_LEFTOVERS([cabal v2-repl arguments])" ];
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
+5 -5
View File
@@ -34,7 +34,7 @@ let
];
positionalCompletion = "_command";
redirectTixFiles = false; # will be done by sub-command
inRootDir = true;
workingDir = "/";
}
''
while true; do
@@ -51,7 +51,7 @@ let
Requires authentication with `cachix authtoken ...`.
'';
inRootDir = true;
workingDir = "/";
}
''
${nix}/bin/nix-instantiate \
@@ -71,7 +71,7 @@ let
This currently excludes the memory and spec-idempotence tests,
as those are particularly expensive.
'';
inRootDir = true;
workingDir = "/";
}
''
${tests}/bin/postgrest-test-spec
@@ -126,7 +126,7 @@ let
COMPREPLY=( $(compgen -W "basic full" -- "$cur") )
fi
'';
inRootDir = true;
workingDir = "/";
}
''
if [ run != "$_arg_operation" ]; then
@@ -237,7 +237,7 @@ let
name = "postgrest-dump-minimal-imports";
docs = "Dump minimal imports into given directory.";
args = [ "ARG_POSITIONAL_SINGLE([dumpdir], [Output directory])" ];
inRootDir = true;
workingDir = "/";
withTmpDir = true;
}
''
+4 -4
View File
@@ -43,7 +43,7 @@ let
"ARG_OPTIONAL_SINGLE([testdir], [t], [Directory to load tests and fixtures from], [./test/load])"
"ARG_LEFTOVERS([additional vegeta arguments])"
];
inRootDir = true;
workingDir = "/";
}
''
# previously required settings to make this work with older branches
@@ -90,7 +90,7 @@ let
__gitcomp_nl "$(__git_refs)"
fi
'';
inRootDir = true;
workingDir = "/";
}
''
for tgt in "''${_arg_target[@]}"; do
@@ -140,7 +140,7 @@ let
"ARG_POSITIONAL_SINGLE([file], [Filename of result to create report for])"
"ARG_LEFTOVERS([additional vegeta arguments])"
];
inRootDir = true;
workingDir = "/";
}
''
${vegeta}/bin/vegeta report -type=json "$_arg_file" \
@@ -169,7 +169,7 @@ let
{
name = "postgrest-loadtest-report";
docs = "Create a report of all loadtest reports as markdown.";
inRootDir = true;
workingDir = "/";
}
''
find loadtest -type f -iname '*.bin' -exec ${reporter} {} \; \
+1 -1
View File
@@ -13,7 +13,7 @@ let
{
name = "postgrest-test-memory";
docs = "Run the memory tests.";
inRootDir = true;
workingDir = "/";
withPath = [ postgrestProfiled curl ];
}
''
+1 -1
View File
@@ -28,7 +28,7 @@ let
{
inherit name;
docs = "Pin the newest stable version of Nixpkgs.";
inRootDir = true;
workingDir = "/";
}
''
# The list of refs is sorted. The first result will be nixpkgs-unstable, the second the latest stable branch.
+1 -1
View File
@@ -53,7 +53,7 @@ let
name = "postgrest-release";
docs = "Patch postgrest.cabal, CHANGELOG.md, tag and push all in one go.";
args = [ "ARG_POSITIONAL_SINGLE([version], [Version to release], [pre])" ];
inRootDir = true;
workingDir = "/";
}
''
trap "echo You need to be on the main branch or a release branch to proceed. Exiting ..." ERR
+3 -3
View File
@@ -17,7 +17,7 @@ let
{
name = "postgrest-style";
docs = "Automatically format Haskell, Nix and Python files.";
inRootDir = true;
workingDir = "/";
}
''
# Format Nix files
@@ -39,7 +39,7 @@ let
{
name = "postgrest-style-check";
docs = "Check whether postgrest-style results in any uncommited changes.";
inRootDir = true;
workingDir = "/";
}
''
${style}
@@ -54,7 +54,7 @@ let
{
name = "postgrest-lint";
docs = "Lint all Haskell files, bash scripts and github workflows.";
inRootDir = true;
workingDir = "/";
}
''
echo "Checking consistency of import aliases in Haskell code..."
+7 -7
View File
@@ -24,7 +24,7 @@ let
name = "postgrest-test-spec";
docs = "Run the Haskell test suite. Use --match PATTERN for running individual specs";
args = [ "ARG_LEFTOVERS([hspec arguments])" ];
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
@@ -37,7 +37,7 @@ let
{
name = "postgrest-test-doctests";
docs = "Run the Haskell doctest test suite";
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
@@ -49,7 +49,7 @@ let
{
name = "postgrest-test-spec-idempotence";
docs = "Check that the Haskell tests can be run multiple times against the same db.";
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
@@ -75,7 +75,7 @@ let
name = "postgrest-test-io";
docs = "Run the pytest-based IO tests. Add -k to run tests that match a given expression.";
args = [ "ARG_LEFTOVERS([pytest arguments])" ];
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
}
''
@@ -89,7 +89,7 @@ let
{
name = "postgrest-dump-schema";
docs = "Dump the loaded schema's SchemaCache as a yaml file.";
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
withPath = [ jq ];
}
@@ -106,7 +106,7 @@ let
name = "postgrest-coverage";
docs = "Run spec and io tests while collecting hpc coverage data. First runs weeder to detect dead code.";
args = [ "ARG_LEFTOVERS([hpc report arguments])" ];
inRootDir = true;
workingDir = "/";
redirectTixFiles = false;
withEnv = postgrest.env;
withTmpDir = true;
@@ -181,7 +181,7 @@ let
{
name = "postgrest-coverage-draft-overlay";
docs = "Create a draft overlay from current coverage report.";
inRootDir = true;
workingDir = "/";
}
''
${ghc}/bin/hpc draft --output=test/coverage.overlay coverage/postgrest.tix
+6 -6
View File
@@ -34,7 +34,7 @@ let
"ARG_USE_ENV([PGOPTIONS], [-c search_path=public,test], [PG options to use])"
];
positionalCompletion = "_command";
inRootDir = true;
workingDir = "/";
redirectTixFiles = false;
withPath = [ postgresql ];
withTmpDir = true;
@@ -139,7 +139,7 @@ let
"ARG_LEFTOVERS([command arguments])"
];
positionalCompletion = "_command";
inRootDir = true;
workingDir = "/";
}
(lib.concatStringsSep "\n\n" runners);
@@ -161,7 +161,7 @@ let
"ARG_USE_ENV([PGDELAY], [0ms], [extra PG latency (duration)])"
];
positionalCompletion = "_command";
inRootDir = true;
workingDir = "/";
redirectTixFiles = false;
withTmpDir = true;
}
@@ -199,7 +199,7 @@ let
"ARG_USE_ENV([PGRST_DELAY], [0ms], [extra PostgREST latency (duration)])"
];
positionalCompletion = "_command";
inRootDir = true;
workingDir = "/";
redirectTixFiles = false;
withTmpDir = true;
}
@@ -249,7 +249,7 @@ let
_command_offset 2
fi
'';
inRootDir = true;
workingDir = "/";
}
''
# not using withTmpDir here, because we don't want to keep the directory on error
@@ -360,7 +360,7 @@ let
"ARG_LEFTOVERS([command arguments])"
];
positionalCompletion = "_command";
inRootDir = true;
workingDir = "/";
withEnv = postgrest.env;
withTmpDir = true;
}