mirror of
https://gitlab.com/TECHNOFAB/soonix.git
synced 2026-02-02 07:15:06 +01:00
feat: add package to exclude gitignored hooks
tools like renovate can run soonix:update after updating stuff, but the gitignored hooks cannot be committed anyways, so why bother building them
This commit is contained in:
parent
56f281eea4
commit
87399d28fe
2 changed files with 116 additions and 78 deletions
|
|
@ -153,9 +153,17 @@ in {
|
|||
|
||||
config = let
|
||||
hooks = config.hooks;
|
||||
hookNames = builtins.attrNames hooks;
|
||||
# allow excluding gitignore since stuff like renovate can't use/commit it anyways
|
||||
getHookNames = {includeGitignored ? true}:
|
||||
if includeGitignored
|
||||
then (builtins.attrNames hooks)
|
||||
else
|
||||
map
|
||||
(hook: hook.name)
|
||||
(builtins.filter (hook: !hook.hook.gitignore) (builtins.attrValues hooks));
|
||||
|
||||
runHooks = concatMapStringsSep "\n" (hookName: let
|
||||
runHooks = args:
|
||||
concatMapStringsSep "\n" (hookName: let
|
||||
hook = hooks.${hookName};
|
||||
modes = {
|
||||
link =
|
||||
|
|
@ -193,6 +201,7 @@ in {
|
|||
''
|
||||
else "";
|
||||
in
|
||||
builtins.addErrorContext "[soonix] while generating script for ${hookName}"
|
||||
# sh
|
||||
''
|
||||
# Process hook: ${hookName}
|
||||
|
|
@ -227,9 +236,10 @@ in {
|
|||
_soonix_failed+=("${hookName}")
|
||||
}
|
||||
'')
|
||||
hookNames;
|
||||
(getHookNames args);
|
||||
|
||||
generatedShellHook =
|
||||
generateShellHook = args:
|
||||
builtins.addErrorContext "[soonix] while generating shell hook"
|
||||
# sh
|
||||
''
|
||||
_soonix_log() {
|
||||
|
|
@ -265,7 +275,7 @@ in {
|
|||
_soonix_failed=()
|
||||
_soonix_uptodate=()
|
||||
|
||||
${runHooks}
|
||||
${runHooks args}
|
||||
|
||||
local output=$'\E[msoonix:\E[38;5;8m'
|
||||
local status=0
|
||||
|
|
@ -297,8 +307,8 @@ in {
|
|||
in rec {
|
||||
# nothing to do if no hooks exist
|
||||
shellHook =
|
||||
if (builtins.length hookNames > 0)
|
||||
then generatedShellHook
|
||||
if (builtins.length (builtins.attrNames config.hooks) > 0)
|
||||
then generateShellHook {}
|
||||
else "";
|
||||
shellHookFile = pkgs.writeShellScript "shellHook" shellHook;
|
||||
devshellModule = {
|
||||
|
|
@ -307,11 +317,17 @@ in {
|
|||
};
|
||||
finalFiles = buildAllFiles allFiles;
|
||||
# make it simpler to update the hooks without any devshell
|
||||
packages."soonix:update" = pkgs.writeShellScriptBin "soonix:update" ''
|
||||
packages = let
|
||||
mkPackage = args:
|
||||
pkgs.writeShellScriptBin "soonix:update" ''
|
||||
function _soonix() {
|
||||
${shellHook}
|
||||
${generateShellHook args}
|
||||
}
|
||||
_soonix
|
||||
'';
|
||||
in {
|
||||
"soonix:update" = mkPackage {};
|
||||
"soonix:update:excludegitignore" = mkPackage {includeGitignored = false;};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,28 @@ in {
|
|||
assert_file_contains ${shellHook} "gomplate"
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "packages";
|
||||
type = "script";
|
||||
script = let
|
||||
conf = (soonix.make {inherit hooks;}).config;
|
||||
baseBin = conf.packages."soonix:update" + "/bin/soonix:update";
|
||||
exclBin = conf.packages."soonix:update:excludegitignore" + "/bin/soonix:update";
|
||||
in
|
||||
# sh
|
||||
''
|
||||
${ntlib.helpers.path [pkgs.gnugrep]}
|
||||
${ntlib.helpers.scriptHelpers}
|
||||
|
||||
assert -f "${baseBin}" "should exist"
|
||||
assert -f "${exclBin}" "should exist"
|
||||
|
||||
assert_file_contains "${baseBin}" "gotmpl"
|
||||
assert_file_contains "${baseBin}" "test.json"
|
||||
assert_file_not_contains "${exclBin}" "gotmpl"
|
||||
assert_file_contains "${exclBin}" "test.json"
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue